Skip to content

Instantly share code, notes, and snippets.

@bdnf
Created March 12, 2020 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdnf/ff052002a571374ee41e5c85749e9202 to your computer and use it in GitHub Desktop.
Save bdnf/ff052002a571374ee41e5c85749e9202 to your computer and use it in GitHub Desktop.
Steps on how to organize a library in Rust
[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]
// 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);
}
}
// 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