Both bin and lib in the one crate

On some of the online tutorials, folks says that you cannot have bin and lib together, but actually it is possible. Here is the example crate which allows for that (Of course you specify bin and lib):

Cargo.toml configuration

Here is a specification in the Cargo.toml file.

// Cargo.toml
[lib] 
name = "nexssp_os_lib"
path = "src/lib.rs"

[[bin]]
name = "nexssp-os"
path = "src/main.rs"

Library file

// src/lib.rs
pub fn example_function() {
    println!("Function from lib!");
}

Usage of the library

// src.main.rs
use nexssp_os_lib::example_function; // here is an import of the library
fn main() {
    println!("Hello, world!");
    example_function();
}
If you found it valuable, please join to the nexss.com supporters at: Support Nexss.com