When considering Rust, thoughts of performance, safety, and concurrency often come to mind. But what about productivity? Traditionally seen as a systems programming language, Rust has made its mark in infrastructure and is used extensively by companies like Google, Amazon, and Microsoft. However, its adoption for higher-level applications, such as database-backed backend systems, has been slower.
At QCon San Francisco 204, Carl Lerche, Principal Engineer at AWS and creator of the Tokio Rust library, challenged the perception that Rust is not suited for high-level productivity. By delving into Rust's ecosystem for database applications, Lerche showcased how Rust can rival dynamic languages in productivity while maintaining its hallmark performance and safety.
The highlights of the talk were:
- Rust’s Promise: Beyond Performance
- A Systems Programming Legacy: Rust’s low-level runtime performance makes it comparable to C++ but with the added benefit of a modern, memory-safe design without a garbage collector.
- Expanding to High-Level Applications: Despite its strong infrastructure presence, Lerche argued Rust is equally capable of backend development, delivering high-quality, defect-free code.
- Challenges:
- Steeper learning curve compared to dynamic languages.
- Less mature ecosystem for web and database development.
- Advantages for Long-lived Code: While not ideal for rapid prototyping, Rust excels in building robust, maintainable systems.
- Database Development in Rust: A Growing Ecosystem
- Lerche introduced Toasty, a new Object-Relational Mapping (ORM) library designed to simplify Rust database interactions. Built for both SQL and NoSQL, Toasty emphasizes ease of use over pure performance.
- Traits and Lifetimes: Common hurdles for new Rust users.
- Simplified schema handling and code generation.
- Reduction of boilerplate code via procedural macros.
- Intuitive APIs tailored for both newcomers and experienced Rust developers.
- Challenges for Developers:
- Second-order trait Bounds: Addressing complexity by minimizing overuse.
- Generated Code Reading: Lerche stressed the importance of ensuring that generated code is understandable for maintainability.
- Tips for Maximizing Productivity in Rust
- Practical Code Simplification:
- Prefer enums over traits for easier-to-read code.
- Use procedural macros to streamline repetitive tasks.
- Error Handling in Rust:
- Leveraging Rust’s unique approach to errors minimizes runtime bugs through safe patterns.
- Practical Code Simplification:
- Optimizing for Database Relationships:
- Use indices for managing complex relationships effectively.
Regarding the Future of Rust in Web and Application Development, Lerche envisioned Rust as a productive general-purpose language for backend systems. However, its adoption challenges are due to its complexity and younger ecosystem; tools like Toasty signal progress. He encouraged developers to experiment with Rust for backend systems and contribute feedback to improve its ecosystem further.