init
This commit is contained in:
commit
921497ab45
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
5
Cargo.lock
generated
Normal file
5
Cargo.lock
generated
Normal file
@ -0,0 +1,5 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "tuto"
|
||||
version = "0.1.0"
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "tuto"
|
||||
version = "0.1.0"
|
||||
authors = ["alban <git@albancrommer.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
39
src/main.rs
Normal file
39
src/main.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use std::env;
|
||||
|
||||
#[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")
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn ip_to_int(ip_str: &str) -> u32 {
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue
Block a user