Our Pullpiri is developed using the Rust Programming language for the language semantics and rust usage the developers shall refer and use the standard rust documentation publicly available
Folder names should be written in lowercase with hyphens (-).
src: Source code foldertests: Test code folderexamples: Example code folderdocs: Documentation folder
File names should be written in lowercase with underscores (_).
main.rs: Main filelib.rs: Library filemod_name.rs: Module file
Variable names should be written in lowercase with underscores (_).
user_nametotal_countis_valid
Function names should be written in lowercase with underscores (_).
calculate_sumfetch_datais_valid_user
-
Consistency: Maintain a consistent code style.
-
Clear Names: Use clear names for variables, functions, and modules that reflect their roles.
-
Comments: The code can be self-annotated, and the documentation should be concise.
a. Write comments where necessary to explain the intent of the code.
b. File header comments to include a copyright notice
c. Use FIXME and TODO in comments to help with task collaboration
d. normal comments use // or /* ... */, and
e. document comments use ///, //! or /** ... **/
-
Modularization: Modularize functionality to improve readability and reusability.
-
Error Handling: Handle errors thoroughly to enhance stability.
a. recoverable - use Result<T, E>
b. unrecoverable errors - use panic!
-
Write Tests: Write test code to ensure the reliability of the code.
-
Use Standard Library: Use the Rust standard library whenever possible to improve efficiency.
-
Add License information and dependencies to Cargo.toml conventions: This helps in build and performing static check
The license field must contain a valid SPDX expression, using valid SPDX license names. (As an exception, by widespread convention, the license field may use / in place of OR; for example, MIT/Apache-2.0.)
// src/main.rs
fn main() {
let user_name = "Alice";
let total_count = calculate_sum(5, 10);
println!("Hello, {}! The total count is {}.", user_name, total_count);
}
fn calculate_sum(a: i32, b: i32) -> i32 {
a + b
}
// src/lib.rs
pub fn fetch_data() -> String {
String::from("Sample data")
}
// src/tests/mod_name.rs
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_calculate_sum() {
assert_eq!(calculate_sum(2, 3), 5);
}
#[test]
fn test_fetch_data() {
assert_eq!(fetch_data(), "Sample data");
}
}