Created
March 12, 2020 17:46
-
-
Save bdnf/ff052002a571374ee41e5c85749e9202 to your computer and use it in GitHub Desktop.
Steps on how to organize a library in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "graph" | |
version = "0.1.0" | |
authors = ["me"] | |
edition = "2020" | |
[lib] | |
name = "service" | |
path = "src/lib.rs" | |
[[bin]] | |
name = "graph" | |
path = "src/main.rs" | |
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/lib.rs | |
// Any useful functions | |
pub fn printer_service(s: &str){ | |
let s = format!("Some useful lib function on {} called", s); | |
println!("{}", s) | |
} | |
// Any useful tests | |
#[cfg(test)] | |
mod tests { | |
#[test] | |
fn it_works() { | |
assert_eq!(2 + 2, 4); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/main.rs | |
// Main function | |
use service::printer_service; | |
pub fn main(){ | |
printer_service("my test func"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment