just a little cleanup
This commit is contained in:
parent
921497ab45
commit
af2a5eff0a
37
src/main.rs
37
src/main.rs
@ -1,39 +1,36 @@
|
||||
use std::env;
|
||||
|
||||
/* Not used, example of an enum
|
||||
#[derive(Debug)]
|
||||
enum Maybe<T> {
|
||||
Just(T),
|
||||
Nothing
|
||||
}
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
let arg = env::args().nth(1);
|
||||
|
||||
println!("{:?}", Maybe::Just(42));
|
||||
|
||||
match arg {
|
||||
Some(result) => {
|
||||
let ip = ip_to_int(&result);
|
||||
println!("{:b}", ip);
|
||||
},
|
||||
None => println!("need one arg")
|
||||
}
|
||||
|
||||
let arg = env::args().nth(1);
|
||||
|
||||
// println!("{:?}", Maybe::Just(42));
|
||||
|
||||
match arg {
|
||||
Some(result) => {
|
||||
let ip = ip_to_int(&result);
|
||||
println!("{:b}", ip);
|
||||
}
|
||||
None => println!("need one arg"),
|
||||
}
|
||||
}
|
||||
|
||||
fn ip_to_int(ip_str: &str) -> u32 {
|
||||
let mut tbl : Vec<&str> = ip_str.split(".")
|
||||
.collect();
|
||||
let mut tbl: Vec<&str> = ip_str.split('.').collect();
|
||||
tbl.reverse();
|
||||
|
||||
let mut ip = 0_u32;
|
||||
|
||||
for (idx, s) in tbl.iter().enumerate() {
|
||||
let nbr : u8 = s.parse()
|
||||
.expect("parse fail");
|
||||
ip += (nbr as u32) << 8*idx;
|
||||
}
|
||||
ip
|
||||
for (idx, s) in tbl.iter().enumerate() {
|
||||
let nbr: u8 = s.parse().expect("parse fail");
|
||||
ip += (nbr as u32) << (8 * idx);
|
||||
}
|
||||
ip
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user