You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: rust/rust.rst
+17-8Lines changed: 17 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,18 @@ LSST Rust Development Guide
6
6
7
7
This guide details the standards and best practices for writing Rust code within the LSST DM Stack and includes basic knowledge of the package.
8
8
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.
9
15
This document assumes a basic understanding of Rust and the LSST DM Stack.
10
16
11
17
The de-facto location, and reference implementation, of rust within the lsst science pipelines is in a package called ``rubinoxide``.
12
18
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``.
13
19
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.
15
21
16
22
2. Rust Version
17
23
---------------
@@ -21,6 +27,8 @@ All LSST Rust code must be compatible with the standard Rust toolchain provided
21
27
3. Resources
22
28
------------
23
29
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
+
24
32
* The `Rust Book <https://doc.rust-lang.org/book/>`_ is a good resource to find out information on the rust language.
25
33
* `crates.io <https://crates.io/>`_ is where third party crates (libraries) are stored and distributed.
26
34
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
30
38
4. Code Organization
31
39
--------------------
32
40
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.
34
42
35
43
* Top-Level Module: All Rust code will be bound to a single top-level module.
36
44
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
66
74
These tests should be placed in the **tests** top level directory.
67
75
* pytest: Use pytest as the python testing framework.
68
76
* 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.
70
78
* Import Rust Modules: Python tests should import the Rust modules (exposed via `pyO3`_) and exercise their functionality.
71
79
* Comprehensive Coverage: Strive for high test coverage to ensure that all critical code paths are tested.
72
80
* 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
76
84
77
85
Consistent code style improves readability and maintainability.
78
86
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.
81
89
* Documentation Comments: Write clear and concise documentation comments for all public functions and data structures.
82
90
* To the extent possible, make apis that will be public to python feel exactly as if they are written in python.
83
91
84
92
9. Logging
85
93
-----------
86
94
87
95
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.
89
97
90
98
10. Don'ts
91
99
----------
92
100
93
101
* Do not use implicit multithreading in rust
94
102
* 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.
96
104
97
105
11. Build and management system integration
98
106
-------------------------------------------
99
107
100
108
* Rust packages should be built using maturin, which manages the complexities of compiling and bundling cargo products.
101
109
* 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
103
111
* pytest is used to run python level unit tests
104
112
* 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.
0 commit comments