Skip to content

0005 Rust

Author:
Steven Johnson
Created:
2024-01-09
Status:
Draft
Tags:
Base for:
0006 Rust Cargo Lock 0007 Rust Version configuration in `cargo.toml`

Context

Languages used in the project need to be chosen based on:

  • their strengths
  • suitability to the tasks they are used for
  • familiarity with the team.

Assumptions

  • That the language chosen will continue to be a mainstream language.
  • That it will be reasonably easy to find developers proficient in it.

Decision

Backend and System level services can be coded in:

  • Rust

Other languages can be also be used for these services as described by their own ADR.

Risks

  1. Learning Curve: Rust has a steep learning curve, especially for developers who are new to systems programming or low-level languages. The language enforces strict memory safety rules and introduces concepts like ownership, borrowing, and lifetimes, which can be challenging to grasp initially. This learning curve may require additional time and effort for developers to become proficient in Rust.
  2. Ecosystem Immaturity: While Rust has a growing ecosystem, it may not have the same level of maturity and breadth as more established languages. This can result in a smaller selection of libraries and tools compared to languages like Python or Java. However, the Rust community actively develops and maintains high-quality libraries, and many common use cases are well-supported.
  3. Development Speed: Rust's focus on safety and strict compile-time checks can sometimes slow down development speed, especially for rapid prototyping or small-scale projects. The compile times in Rust can be longer compared to other languages, which may impact the iterative development process. However, the benefits of safety and performance often outweigh this trade-off in larger-scale projects.

Despite these risks, Rust's benefits in terms of memory safety, performance, and concurrency make it a compelling choice for backend systems programming.

Consequences

  1. Memory Safety: Rust's ownership system and borrow checker ensure memory safety at compile time, preventing common bugs like null pointer dereferences, buffer overflows, and data races.
  2. Performance: Rust enables low-level control over resources, developers can write efficient code with minimal runtime overhead. It offers zero-cost abstractions and fine-grained control over memory allocation.
  3. Concurrency: Rust's ownership model and built-in concurrency primitives, such as threads and channels, make it easy to write safe and concurrent code. The async/await syntax and the tokio library provide powerful asynchronous programming capabilities.
  4. Safety Guarantees: Rust's strict compile-time checks enforce safe programming practices, eliminating undefined behavior and making code more reliable. The language prevents common programming mistakes by catching them at compile time.
  5. Developer Experience: Rust has a growing ecosystem of libraries and tools, making it easier to build robust applications. The language promotes clear and explicit code, with helpful error messages and a strong type system that aids in code maintainability.
  6. Cross-platform Support: Rust is designed to be portable and can target a wide range of platforms, including desktop, mobile, and embedded systems. It supports various architectures and operating systems, making it versatile for different use cases.
  7. Interoperability: Rust can seamlessly interface with other languages, allowing developers to leverage existing code-bases or libraries. It provides C-compatible FFI (Foreign Function Interface) and supports integration with languages like C, C++, and Python.
  8. Community: Rust has a vibrant and supportive community that actively contributes to the language's development and provides valuable resources, documentation, and libraries. The community fosters a culture of knowledge sharing and collaboration.
  9. Tooling: Rust has a powerful package manager called Cargo, which simplifies dependency management and project build processes. It also offers excellent IDE support, code formatting, and extensive testing frameworks.
  10. Future-proofing: Rust is designed for long-term stability and compatibility. The language emphasizes backward compatibility and provides a strong commitment to avoiding breaking changes. This ensures that code written in Rust today will continue to work in the future.

Scope

This ADR applies to all projects which consume Catalyst-CI unless they define an ADR specific to that project.

More Information

  • Rust
  • Rust: A Language for the Next 40 Years - This video presentation by Carol Nichols highlights Rust's strengths and discusses its unique features, including memory safety, zero-cost abstractions, and concurrency.