Skip to content

Commit f5ee1bc

Browse files
committed
Address new Rust review comments
1 parent 2037adc commit f5ee1bc

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

rust/rust.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ LSST Rust Development Guide
66

77
This guide details the standards and best practices for writing Rust code within the LSST DM Stack and includes basic knowledge of the package.
88
Rust is being adopted to provide performance-critical components and leverage its memory safety features.
9+
Of note, we are making use of Rust's memory safety in the sense of the design of the language.
10+
This does not mean one can not use unsafe blocks where appropriate, but they should be used with due consideration and held to the same standards as where they are used elsewhere in rust.
11+
For sexample, unsafe blocks should be liminted in scope to the smallest size needed to accomplish a unit of work.
12+
13+
There should be careful consideration when writing new code in rust.
14+
The line between when something is simple enough and should be done in python with a small performance hit, vs written in rust and bound to python is a hard line to define and is left up to our 'empowering developers' directive for them to make the most informed decision.
915
This document assumes a basic understanding of Rust and the LSST DM Stack.
1016

1117
The de-facto location, and reference implementation, of rust within the lsst science pipelines is in a package called ``rubinoxide``.
1218
This does not mean developers are not allowed to use rust in another dedicated package, but unless there is a compelling reason to do so rust code should be placed in ``rubinoxide``.
1319
This guide assumes the package layout of ``rubinoxide``.
14-
Any other Rust based packages that are written should adhear to this as best as possible.
20+
Any other Rust based packages that are written should adhere to this as best as possible.
1521

1622
2. Rust Version
1723
---------------
@@ -21,6 +27,8 @@ All LSST Rust code must be compatible with the standard Rust toolchain provided
2127
3. Resources
2228
------------
2329

30+
Unlike the c++ section of the guide, where the language has no clear community consensus or resources, we defer to standard published rust resources guidance on how to work with rust.
31+
2432
* The `Rust Book <https://doc.rust-lang.org/book/>`_ is a good resource to find out information on the rust language.
2533
* `crates.io <https://crates.io/>`_ is where third party crates (libraries) are stored and distributed.
2634
This contains links to the documentation on each crate.
@@ -30,7 +38,7 @@ All LSST Rust code must be compatible with the standard Rust toolchain provided
3038
4. Code Organization
3139
--------------------
3240

33-
Unlike the package-centric organization often seen in Python, packages containing rust code should me monolithic and not depend on other lsst packages.
41+
Unlike the package-centric organization often seen in Python, packages containing rust code should be monolithic and not depend on other lsst packages.
3442

3543
* Top-Level Module: All Rust code will be bound to a single top-level module.
3644
This module will serve as the entry point for Python interaction.
@@ -66,7 +74,7 @@ Managing dependencies is crucial for maintaining a stable and reproducible build
6674
These tests should be placed in the **tests** top level directory.
6775
* pytest: Use pytest as the python testing framework.
6876
* For functionality that does not have a public python api, or is not well covered by a python api, or is difficult to appropriately test with a python unit test rust unit tests may be written using the standard rust unit test infrastructure.
69-
Genreally avoid a rust until test on any code that is wrapped with pyo3.
77+
Generally avoid a rust unit tests on any code that is wrapped with pyo3.
7078
* Import Rust Modules: Python tests should import the Rust modules (exposed via `pyO3`_) and exercise their functionality.
7179
* Comprehensive Coverage: Strive for high test coverage to ensure that all critical code paths are tested.
7280
* Integration Tests: In addition to unit tests, consider integration tests to verify the interaction between Rust components and other parts of the LSST DM Stack.
@@ -76,32 +84,33 @@ Managing dependencies is crucial for maintaining a stable and reproducible build
7684

7785
Consistent code style improves readability and maintainability.
7886

79-
* `rustfmt`_: Use rustfmt to automatically format your Rust code.
80-
* `Clippy`_: Use Clippy to lint your Rust code and identify potential issues.
87+
* `rustfmt`_: One must use rustfmt to automatically format your Rust code, or otherwise produce output that is the same as would have been produced with `rustfmt`_.
88+
* `Clippy`_: Use Clippy to lint your Rust code and identify potential issues. Not every suggestion from clippy must be adopted, but all should be carefully considered. Suggestions which make code conform to community standards should only be skipped with good justification.
8189
* Documentation Comments: Write clear and concise documentation comments for all public functions and data structures.
8290
* To the extent possible, make apis that will be public to python feel exactly as if they are written in python.
8391

8492
9. Logging
8593
-----------
8694

8795
Logging should be done using the `log`_ crate, and accompanying macros.
88-
The standard rubinoxide package initializes the pyo3_log crate to forward all logs through to the python log handler to the approprate log level.
96+
The standard rubinoxide package initializes the pyo3_log crate to forward all logs through to the python log handler to the appropriate log level.
8997

9098
10. Don'ts
9199
----------
92100

93101
* Do not use implicit multithreading in rust
94102
* Do not introduce any cross package rust bindings that transit through python aka how we use c++ now.
95-
* As mentioned above, do not arange module structure according to lsst packages. Write modules by related functionality.
103+
* As mentioned above, do not arrange module structure according to lsst packages. Write modules by related functionality.
96104

97105
11. Build and management system integration
98106
-------------------------------------------
99107

100108
* Rust packages should be built using maturin, which manages the complexities of compiling and bundling cargo products.
101109
* Cargo additionally is to be used manage dependencies and run rust level tests.
102-
* pip is used as the mechanism to locally depoly the wheels created by maturin
110+
* pip is used as the mechanism to locally deploy the wheels created by maturin
103111
* pytest is used to run python level unit tests
104112
* coordinating these scripts for the developer is a Makefile
113+
* The Makefile supports build and test modes independently (as well as an all mode) so authors can more quickly iterate in development.
105114

106115
.. _rustfmt: https://github.com/rust-lang/rustfmt
107116
.. _Clippy: https://github.com/rust-lang/rust-clippy

0 commit comments

Comments
 (0)