this is a demo rust library published on crates.io
to use this library you have to add following line in dependency section of cargo.toml
even_odd = "0.1.1"
your cargo.toml file should look like this: ``` [package] name = "even_odd" version = "0.1.0" authors = ["farjadali farjadmohal@gmail.com"] edition = "2018"
[dependencies] evenoddcrate = "0.1.1" ```
In src/lib.rs
you can use like this:
This function will check the Input:
To use in main.rs
use evenodd;
fn main(){
evenodd::evenodd();
}
This function will check the Input:
pub fn evenodd(){
println!("*Welcome to Even Odd Rust Program*");
println!("Please Enter A Number To Check: " );
let mut num = String::new();
io::stdin().read_line(&mut num).expect("Error");
let check_num = num.trim();
match check_num.parse::<u32>() {
Ok(i) => {
println!("Your integer input: {}", i);
let num_to_int:u32 = check_num.parse().unwrap();
if num_to_int %2 ==0 {
println!("Number is Even");
}
else {
println!("Number is Odd");
}
}
,
Err(..) => println!("This was not an integer: {}", check_num),
};
}
```
now cargo run
for results