diff --git a/Cargo.lock b/Cargo.lock index 8295e51..0f5c5ba 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,4 +1,23 @@ [root] name = "hello_world" version = "0.0.1" +dependencies = [ + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", +] +[[package]] +name = "libc" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "88ee81885f9f04bff991e306fea7c1c60a5f0f9e409e99f6b40e3311a3363135" +"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" diff --git a/Cargo.toml b/Cargo.toml index 09819c8..abd9f0f 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,12 @@ name = "hello_world" version = "0.0.1" authors = [ "Clara Benedicta Maria Mueller " ] + [[bin]] -name = "test" -path = "/media/win_e/Clara_Daten/etc/Programmierung/Rust/src/test.rs" +name = "main" +path = "/media/win_e/Clara_Daten/etc/Programmierung/Rust/src/main.rs" + + +[dependencies] + +rand="0.3.0" diff --git a/Cargo.toml_backup b/Cargo.toml_backup new file mode 100755 index 0000000..5b9e98a --- /dev/null +++ b/Cargo.toml_backup @@ -0,0 +1,15 @@ +[package] + +name = "hello_world" +version = "0.0.1" +authors = [ "Clara Benedicta Maria Mueller " ] + + +[[bin]] +name = "test" +path = "/media/win_e/Clara_Daten/etc/Programmierung/Rust/src/test.rs" + + +[dependencies] + +rand="0.3.0" diff --git a/main.rs b/main.rs new file mode 100755 index 0000000..c8c0ba2 --- /dev/null +++ b/main.rs @@ -0,0 +1,56 @@ +// another rust programm +// let's get started ^.^ + +extern crate rand; // actually using rand (declared in dependencies of 'Cargo.toml') + +// rust only uses few things by default ('prelude') -> add your needs! +use std::io; // use io library from the standard library +use std::cmp::Ordering; // use ordering type +use rand::Rng; // using rands function rand::thread_rng() + + +// main function +fn main() { + println!("guess a number!"); // macro, prints string + + let secret_number = rand::thread_rng() // get copy of random number generator + .gen_range(1, 101); // methods takes 2 arguments -> generate random number between (inclusive on the lower bound, but exclusive on the upper bound -> 1 - 100) + + // println!("The secret number is: {}", secret_number); // print out secret number // just for testing -> runs the game! + + + loop { // building infinity loop + + println!("please input your guess!."); // macro, prints string + + let mut guess = String::new(); // let -> create 'variable bindings'; String -> string type (UTF-8 encoded bit of text); '::' -> associate function; 'new()' -> created empty + let foo = 5; // 'foo' is immutable + let mut bar = 5; //'bar' is mutable + + io::stdin().read_line(&mut guess) // calling associated function // without std::io -> written 'std::io::stdin()' //returns handle to standard input + // read_line() -> calling method (like associate function, only on parcticular instant of type) an handle + // read_line():&mut guess -> passing argument to mutable reference of guess + .expect("failed to read line"); // io::Result encodes error handling information // not successful -> panic! with message "failed to read line" + // alternative written: 'io::stdin().read_line(&mut guess).expect("failed to read line");' + + // let guess: u32 = guess.trim().parse() // 'shadow' guess with new one -> convert string into u32 // 'trim()' eliminates whitespace // 'prase()' -> parses string into number + // .expect("Please type a number!"); // stop programm if not a number + + let guess: u32 = match guess.trim().parse() { // 'handling error' -> 'match' instead 'expect()' // result returned by prase() + Ok(num) => num, // success -> set name num on unwrapped Ok value (integer) + Err(_) => continue, // failure -> don't care of kind of error -> catch all _(everything not ok) // 'continue' -> move to next iteration of loop (aka ignore all errors) + }; + + println!("you guessed: {}", guess); // print out saved string from STDIN + println!("FOO: {} & BAR: {}", foo, bar); // print out string variables + + match guess.cmp(&secret_number) { // cmp can called on anything comparable, takes references to thing to compare // returns odering type // match -> determine exactly what typ of ordering (ordering = enum (enumeration)) // guess + secret_number have to be same type for comparision! + Ordering::Less => println!("To small!"), // ordering enum -> 3 possible variants (less/greater/equal) + Ordering::Greater => println!("To big!"), + Ordering::Equal => { + println!("You win!"); + break; + } + } + } +} diff --git a/target/debug/.fingerprint/hello_world-0c8f4da7f93c9c5c/bin-main-0c8f4da7f93c9c5c b/target/debug/.fingerprint/hello_world-0c8f4da7f93c9c5c/bin-main-0c8f4da7f93c9c5c new file mode 100755 index 0000000..6b1cf37 --- /dev/null +++ b/target/debug/.fingerprint/hello_world-0c8f4da7f93c9c5c/bin-main-0c8f4da7f93c9c5c @@ -0,0 +1 @@ +17a9309d5cd6c961 \ No newline at end of file diff --git a/target/debug/.fingerprint/hello_world-0c8f4da7f93c9c5c/bin-main-0c8f4da7f93c9c5c.json b/target/debug/.fingerprint/hello_world-0c8f4da7f93c9c5c/bin-main-0c8f4da7f93c9c5c.json new file mode 100755 index 0000000..ec1d3f2 --- /dev/null +++ b/target/debug/.fingerprint/hello_world-0c8f4da7f93c9c5c/bin-main-0c8f4da7f93c9c5c.json @@ -0,0 +1 @@ +{"rustc":9749998217168482212,"target":17950575461743581120,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1492077381,811763100],[47,109,101,100,105,97,47,119,105,110,95,101,47,67,108,97,114,97,95,68,97,116,101,110,47,101,116,99,47,80,114,111,103,114,97,109,109,105,101,114,117,110,103,47,82,117,115,116,47,115,114,99,47,116,97,114,103,101,116,47,100,101,98,117,103,47,46,102,105,110,103,101,114,112,114,105,110,116,47,104,101,108,108,111,95,119,111,114,108,100,45,48,99,56,102,52,100,97,55,102,57,51,99,57,99,53,99,47,100,101,112,45,98,105,110,45,109,97,105,110,45,48,99,56,102,52,100,97,55,102,57,51,99,57,99,53,99]]},"features":"None","deps":[["rand v0.3.15",127043405904794477]],"rustflags":[]} \ No newline at end of file diff --git a/target/debug/.fingerprint/hello_world-0c8f4da7f93c9c5c/dep-bin-main-0c8f4da7f93c9c5c b/target/debug/.fingerprint/hello_world-0c8f4da7f93c9c5c/dep-bin-main-0c8f4da7f93c9c5c new file mode 100755 index 0000000..f98c291 Binary files /dev/null and b/target/debug/.fingerprint/hello_world-0c8f4da7f93c9c5c/dep-bin-main-0c8f4da7f93c9c5c differ diff --git a/target/debug/.fingerprint/hello_world-943817d46c044558/bin-test-943817d46c044558 b/target/debug/.fingerprint/hello_world-943817d46c044558/bin-test-943817d46c044558 index a88d065..2e93f5b 100755 --- a/target/debug/.fingerprint/hello_world-943817d46c044558/bin-test-943817d46c044558 +++ b/target/debug/.fingerprint/hello_world-943817d46c044558/bin-test-943817d46c044558 @@ -1 +1 @@ -6d8524286a203399 \ No newline at end of file +430c19affbf6a977 \ No newline at end of file diff --git a/target/debug/.fingerprint/hello_world-943817d46c044558/bin-test-943817d46c044558.json b/target/debug/.fingerprint/hello_world-943817d46c044558/bin-test-943817d46c044558.json index 859500c..f9a940e 100755 --- a/target/debug/.fingerprint/hello_world-943817d46c044558/bin-test-943817d46c044558.json +++ b/target/debug/.fingerprint/hello_world-943817d46c044558/bin-test-943817d46c044558.json @@ -1 +1 @@ -{"rustc":9749998217168482212,"target":10994546209011070589,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1492017954,643537700],[47,109,101,100,105,97,47,119,105,110,95,101,47,67,108,97,114,97,95,68,97,116,101,110,47,101,116,99,47,80,114,111,103,114,97,109,109,105,101,114,117,110,103,47,82,117,115,116,47,115,114,99,47,116,97,114,103,101,116,47,100,101,98,117,103,47,46,102,105,110,103,101,114,112,114,105,110,116,47,104,101,108,108,111,95,119,111,114,108,100,45,57,52,51,56,49,55,100,52,54,99,48,52,52,53,53,56,47,100,101,112,45,98,105,110,45,116,101,115,116,45,57,52,51,56,49,55,100,52,54,99,48,52,52,53,53,56]]},"features":"None","deps":[],"rustflags":[]} \ No newline at end of file +{"rustc":9749998217168482212,"target":10994546209011070589,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1492072499,359251700],[47,109,101,100,105,97,47,119,105,110,95,101,47,67,108,97,114,97,95,68,97,116,101,110,47,101,116,99,47,80,114,111,103,114,97,109,109,105,101,114,117,110,103,47,82,117,115,116,47,115,114,99,47,116,97,114,103,101,116,47,100,101,98,117,103,47,46,102,105,110,103,101,114,112,114,105,110,116,47,104,101,108,108,111,95,119,111,114,108,100,45,57,52,51,56,49,55,100,52,54,99,48,52,52,53,53,56,47,100,101,112,45,98,105,110,45,116,101,115,116,45,57,52,51,56,49,55,100,52,54,99,48,52,52,53,53,56]]},"features":"None","deps":[["rand v0.3.15",127043405904794477]],"rustflags":[]} \ No newline at end of file diff --git a/target/debug/.fingerprint/libc-5dc7b85e748840b4/dep-lib-libc-5dc7b85e748840b4 b/target/debug/.fingerprint/libc-5dc7b85e748840b4/dep-lib-libc-5dc7b85e748840b4 new file mode 100755 index 0000000..ce78b54 Binary files /dev/null and b/target/debug/.fingerprint/libc-5dc7b85e748840b4/dep-lib-libc-5dc7b85e748840b4 differ diff --git a/target/debug/.fingerprint/libc-5dc7b85e748840b4/lib-libc-5dc7b85e748840b4 b/target/debug/.fingerprint/libc-5dc7b85e748840b4/lib-libc-5dc7b85e748840b4 new file mode 100755 index 0000000..03665ea --- /dev/null +++ b/target/debug/.fingerprint/libc-5dc7b85e748840b4/lib-libc-5dc7b85e748840b4 @@ -0,0 +1 @@ +20054fec61dda75a \ No newline at end of file diff --git a/target/debug/.fingerprint/libc-5dc7b85e748840b4/lib-libc-5dc7b85e748840b4.json b/target/debug/.fingerprint/libc-5dc7b85e748840b4/lib-libc-5dc7b85e748840b4.json new file mode 100755 index 0000000..416741c --- /dev/null +++ b/target/debug/.fingerprint/libc-5dc7b85e748840b4/lib-libc-5dc7b85e748840b4.json @@ -0,0 +1 @@ +{"rustc":9749998217168482212,"target":12335968779674043000,"profile":14528549471338536373,"local":{"variant":"Precalculated","fields":["0.2.21"]},"features":"Some([\"default\", \"use_std\"])","deps":[],"rustflags":[]} \ No newline at end of file diff --git a/target/debug/.fingerprint/rand-c9d9fbdab2355ee4/dep-lib-rand-c9d9fbdab2355ee4 b/target/debug/.fingerprint/rand-c9d9fbdab2355ee4/dep-lib-rand-c9d9fbdab2355ee4 new file mode 100755 index 0000000..e8b8b3b Binary files /dev/null and b/target/debug/.fingerprint/rand-c9d9fbdab2355ee4/dep-lib-rand-c9d9fbdab2355ee4 differ diff --git a/target/debug/.fingerprint/rand-c9d9fbdab2355ee4/lib-rand-c9d9fbdab2355ee4 b/target/debug/.fingerprint/rand-c9d9fbdab2355ee4/lib-rand-c9d9fbdab2355ee4 new file mode 100755 index 0000000..e21bdb8 --- /dev/null +++ b/target/debug/.fingerprint/rand-c9d9fbdab2355ee4/lib-rand-c9d9fbdab2355ee4 @@ -0,0 +1 @@ +6dd302f84d59c301 \ No newline at end of file diff --git a/target/debug/.fingerprint/rand-c9d9fbdab2355ee4/lib-rand-c9d9fbdab2355ee4.json b/target/debug/.fingerprint/rand-c9d9fbdab2355ee4/lib-rand-c9d9fbdab2355ee4.json new file mode 100755 index 0000000..8d02bb2 --- /dev/null +++ b/target/debug/.fingerprint/rand-c9d9fbdab2355ee4/lib-rand-c9d9fbdab2355ee4.json @@ -0,0 +1 @@ +{"rustc":9749998217168482212,"target":16630976334449306048,"profile":14528549471338536373,"local":{"variant":"Precalculated","fields":["0.3.15"]},"features":"None","deps":[["libc v0.2.21",6532433197170361632]],"rustflags":[]} \ No newline at end of file diff --git a/target/debug/deps/liblibc-5dc7b85e748840b4.rlib b/target/debug/deps/liblibc-5dc7b85e748840b4.rlib new file mode 100755 index 0000000..132e437 Binary files /dev/null and b/target/debug/deps/liblibc-5dc7b85e748840b4.rlib differ diff --git a/target/debug/deps/librand-c9d9fbdab2355ee4.rlib b/target/debug/deps/librand-c9d9fbdab2355ee4.rlib new file mode 100755 index 0000000..c8c50be Binary files /dev/null and b/target/debug/deps/librand-c9d9fbdab2355ee4.rlib differ diff --git a/target/debug/deps/main-0c8f4da7f93c9c5c b/target/debug/deps/main-0c8f4da7f93c9c5c new file mode 100755 index 0000000..8242c16 Binary files /dev/null and b/target/debug/deps/main-0c8f4da7f93c9c5c differ diff --git a/target/debug/main b/target/debug/main new file mode 100755 index 0000000..8242c16 Binary files /dev/null and b/target/debug/main differ diff --git a/target/debug/main.d b/target/debug/main.d new file mode 100755 index 0000000..9a25e52 --- /dev/null +++ b/target/debug/main.d @@ -0,0 +1 @@ +/media/win_e/Clara_Daten/etc/Programmierung/Rust/src/target/debug/main: /media/win_e/Clara_Daten/etc/Programmierung/Rust/src/main.rs