Skip to content

Commit

Permalink
much more rusties
Browse files Browse the repository at this point in the history
  • Loading branch information
roastercode committed Apr 11, 2017
1 parent 4b99a70 commit 6767713
Show file tree
Hide file tree
Showing 57 changed files with 368 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .tramp_history
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,47 @@ git add .
git commit -m "some more Rusties"
git push
sudo pacman -Syu
cd ../..
cargo new closures --bin
cd closures/
cargo build
cargo run
sudo pacman -Syu
cargo run
cd ..
cargo new closures-capturing --bin
cd closures-capturing/
cargo build
cargo run
cd ..
cargo new closure-as-input-parameters --bin
cd closure-as-input-parameters/
pacman -Ss zeronet
yaourt -ss zeronet
cargo build
cargo run
cd ..
cargo build closures-anonymity
cd closures-anonymity/
cargo build
cargo run
cd ..
cd closure-as-input-parameters/
cargo build
cargo run
cd ..
cd closure-as-input-functions
ls -lart
cd closures-input-functions/
cargo build
cargo run
cd ..
cd closures-as-output-parameters/
cargo build
cargo run
cd ;.
cd git/rust/
git add .
git commit -m "+ much more rusties"
git push
exit
4 changes: 4 additions & 0 deletions higher-order-functions/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions higher-order-functions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "higher-order-functions"
version = "0.1.0"
authors = ["Aurélien DESBRIÈRES <[email protected]>"]

[dependencies]
41 changes: 41 additions & 0 deletions higher-order-functions/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Aurélien DESBRIÈRES
aurelien(at)hackers(dot)camp
License GNU GPL latest */

// Rust experimentations
// HOF - Higher Order Functions in Rust

fn is_odd(n: u32) -> bool {
n % 2 == 1
}

fn main() {
println!("Find the sum of all the squared odd numbers under 1000");
let upper = 1000;

// Imperative approach
// Declare accumulator varialbe
let mut acc = 0;
// Iterate: 0, 1, 2, ... to infinity
for n in 0.. {
// Square the number
let n_squared = n * n;

if n_squared >= upper {
// Break loop if exceeded the upper limit
break;
} else if is_odd(n_squared) {
// Accumulate value, if it's odd
acc += n_squared;
}
}
println!("imperative style: {}", acc);

// Functional approach
let sum_of_squared_odd_numbers: u32 =
(0..).map(|n| n * n) // All natural numbers squared
.take_while(|&n| n < upper) // Below upper limit
.filter(|&n| is_odd(n)) // That are odd
.fold(0, |sum, i| sum + i); // Sum them
println!("functional style: {}", sum_of_squared_odd_numbers);
}
3 changes: 3 additions & 0 deletions higher-order-functions/src/main.rs~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4b92e2d5830d32b1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":7337822701906583572,"target":17663985639602434515,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1491816739,952247649],[47,104,111,109,101,47,97,117,114,101,108,105,101,110,47,103,105,116,47,114,117,115,116,47,104,105,103,104,101,114,45,111,114,100,101,114,45,102,117,110,99,116,105,111,110,115,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,105,103,104,101,114,45,111,114,100,101,114,45,102,117,110,99,116,105,111,110,115,45,49,102,102,100,100,102,55,52,99,54,53,48,54,53,52,56,47,100,101,112,45,98,105,110,45,104,105,103,104,101,114,95,111,114,100,101,114,95,102,117,110,99,116,105,111,110,115,45,49,102,102,100,100,102,55,52,99,54,53,48,54,53,52,56]]},"features":"None","deps":[],"rustflags":[]}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/aurelien/git/rust/higher-order-functions/target/debug/higher-order-functions: /home/aurelien/git/rust/higher-order-functions/src/main.rs
4 changes: 4 additions & 0 deletions iterator-find/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions iterator-find/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "iterator-find"
version = "0.1.0"
authors = ["Aurélien DESBRIÈRES <[email protected]>"]

[dependencies]
30 changes: 30 additions & 0 deletions iterator-find/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Aurélien DESBRIÈRES
aurelien(at)hackers(dot)camp
License GNU GPL latest */

// Rust experimentations
// Iterator find in Rust

fn main() {
let vec1 = vec![1, 2, 3];
let vec2 = vec![4, 5, 6];

// `iter()` for vec yields `&i32`.
let mut iter = vec1.iter();
// `into_iter()` for vec yields `i32`.
let mut into_iter = vec2.into_iter();

// A reference to what is yielded is `&&i32`. Destructure to `i32`.
println!("Find 2 in vec1: {:?}", iter .find(|&&x| x == 2));
// A reference to what is yielded is `&i32`. Destructure to `i32`.
println!("Find 2 in vec2: {:?}", into_iter.find(| &x| x == 2));

let array1 = [1, 2, 3];
let array2 = [4, 5, 6];

// `iter()` for arrays yields `&i32`
println!("Find 2 in array1: {:?}", array1.iter() .find(|&&x| x == 2));
// `into_iter()` for arrays unusually yields `&i32`
println!("Find 2 in array2: {:?}", array2.into_iter().find(|&&x| x == 2));
}

3 changes: 3 additions & 0 deletions iterator-find/src/main.rs~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
67015548b56cb8b2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":7337822701906583572,"target":9291745995434966666,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1491816056,792262795],[47,104,111,109,101,47,97,117,114,101,108,105,101,110,47,103,105,116,47,114,117,115,116,47,105,116,101,114,97,116,111,114,45,102,105,110,100,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,105,116,101,114,97,116,111,114,45,102,105,110,100,45,55,48,49,55,54,97,51,55,99,51,54,99,55,56,97,99,47,100,101,112,45,98,105,110,45,105,116,101,114,97,116,111,114,95,102,105,110,100,45,55,48,49,55,54,97,51,55,99,51,54,99,55,56,97,99]]},"features":"None","deps":[],"rustflags":[]}
Binary file not shown.
Binary file not shown.
Binary file added iterator-find/target/debug/iterator-find
Binary file not shown.
1 change: 1 addition & 0 deletions iterator-find/target/debug/iterator-find.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/aurelien/git/rust/iterator-find/target/debug/iterator-find: /home/aurelien/git/rust/iterator-find/src/main.rs
4 changes: 4 additions & 0 deletions iterator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions iterator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "iterator"
version = "0.1.0"
authors = ["Aurélien DESBRIÈRES <[email protected]>"]

[dependencies]
21 changes: 21 additions & 0 deletions iterator/src/.tramp_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
stty tab0 -inlcr -onlcr -echo kill '^U' erase '^H'
echo foo
PS1=///7ded89db0b4ea90cff909b1ab08f0585\#\$ PS2='' PS3='' PROMPT_COMMAND=''
echo \"`uname -sr`\" 2>/dev/null; echo tramp_exit_status $?
echo foo ; echo bar
set +o vi +o emacs
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin; export PATH
mesg n 2>/dev/null; biff n 2>/dev/null
stty iutf8 2>/dev/null
echo \"`tty`\" 2>/dev/null; echo tramp_exit_status $?
while read var val; do export $var=$val; done <<'123b1d2f7d58a818fa70d25e2eff25fd'
PAGER cat
INSIDE_EMACS '25.1.1,tramp:2.2.13.25.1'
TERM dumb
LC_CTYPE ''
TMOUT 0
LC_ALL en_US.utf8
123b1d2f7d58a818fa70d25e2eff25fd

unset correct autocorrect MAILPATH MAILCHECK MAIL HISTORY CDPATH
cd /home/aurelien/git/rust/iterator/src/ && exec env PS1\=/sshx\:aurelien\@icebreaker\:/home/aurelien/git/rust/iterator/src/\ \#\$\ TERMCAP\= COLUMNS\=118 INSIDE_EMACS\=25.1.1\,comint /bin/bash --noediting -i
24 changes: 24 additions & 0 deletions iterator/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Aurélien DESBRIÈRES
aurelien(at)hackers(dot)camp
License GNU GPL latest */

// Rust experimentations
// Iterator in Rust

fn main() {
let vec1 = vec![1, 2, 3];
let vec2 = vec![4, 5, 6];

// `iter()` for vec yields `&i32, Destructure to `i32`
println!("2 in vec1: {}", vec1.iter() .any(|&x| x == 2));
// `into_iter()` for vecs yields `i32`, No destructuring required,
println!("2 in vec2: {}", vec2.into_iter().any(| x| x == 2));

let array1 = [1, 2, 3];
let array2 = [4, 5, 6];

// `iter()` for arrays yield `&i32`.
println!("2 in array1: {}", array1.iter() .any(|&x| x == 2));
// `into_iter()` for arrays unnusually yields `&i32`
println!("2 in array2; {}", array2.into_iter().any(|&x| x == 2));
}
3 changes: 3 additions & 0 deletions iterator/src/main.rs~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
64863de95bac730e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":7337822701906583572,"target":7291426499645126153,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1491501286,729241359],[47,104,111,109,101,47,97,117,114,101,108,105,101,110,47,103,105,116,47,114,117,115,116,47,105,116,101,114,97,116,111,114,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,105,116,101,114,97,116,111,114,45,50,97,56,53,98,102,102,51,57,55,100,98,100,56,52,51,47,100,101,112,45,98,105,110,45,105,116,101,114,97,116,111,114,45,50,97,56,53,98,102,102,51,57,55,100,98,100,56,52,51]]},"features":"None","deps":[],"rustflags":[]}
Binary file not shown.
Binary file not shown.
Binary file added iterator/target/debug/iterator
Binary file not shown.
1 change: 1 addition & 0 deletions iterator/target/debug/iterator.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/aurelien/git/rust/iterator/target/debug/iterator: /home/aurelien/git/rust/iterator/src/main.rs
4 changes: 4 additions & 0 deletions modules-struct-visibility/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions modules-struct-visibility/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "modules-struct-visibility"
version = "0.1.0"
authors = ["Aurélien DESBRIÈRES <[email protected]>"]

[dependencies]
50 changes: 50 additions & 0 deletions modules-struct-visibility/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Aurélien DESBRIÈRES
aurelien(at)hackers(dot)camp
License GNU GPL latest */

// Rust experimentations
// Modules Struct Visibility in Rust

mod my {
// A public struct with a public field of generic type `T`
pub struct WhiteBox<T> {
pub contents: T,
}

// A public struct with a private field of generic type `T`
#[allow(dead_code)]
pub struct BlackBox<T> {
contents: T,
}

impl<T> BlackBox<T> {
// A public constructor method
pub fn new(contents: T) -> BlackBox<T> {
BlackBox {
contents: contents,
}
}
}
}

fn main() {
// Public structs with public fields can be constructed as usual
let white_box = my::WhiteBox { contents: "public information" };

// and their fields can be normally accessed.
println!("The white box contains: {}", white_box.contents);

// Public structs with private fields cannot be constructed using field names.
// Error! `BlackBox` has private fields
//let black_box = my::BlackBox { contents: "classified information" };
// TODO ^ Try uncommenting this line

// However, structs with private fields can be created using
// public constructors
let _black_box = my::BlackBox::new("classified information");

// and the private fields of a public struct cannot be accessed.
// Error! The `contents` field is private
println!("The black box contains: {}", _black_box.contents);
// TODO ^ Try uncommenting this line
}
3 changes: 3 additions & 0 deletions modules-struct-visibility/src/main.rs~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d1e428418f7bfdea
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":7337822701906583572,"target":17217705447684493301,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1491940292,189508453],[47,104,111,109,101,47,97,117,114,101,108,105,101,110,47,103,105,116,47,114,117,115,116,47,109,111,100,117,108,101,115,45,115,116,114,117,99,116,45,118,105,115,105,98,105,108,105,116,121,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,109,111,100,117,108,101,115,45,115,116,114,117,99,116,45,118,105,115,105,98,105,108,105,116,121,45,97,53,101,54,48,49,50,52,55,55,98,50,101,100,97,50,47,100,101,112,45,98,105,110,45,109,111,100,117,108,101,115,95,115,116,114,117,99,116,95,118,105,115,105,98,105,108,105,116,121,45,97,53,101,54,48,49,50,52,55,55,98,50,101,100,97,50]]},"features":"None","deps":[],"rustflags":[]}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/home/aurelien/git/rust/modules-struct-visibility/target/debug/deps/modules_struct_visibility-a5e6012477b2eda2: src/main.rs

/home/aurelien/git/rust/modules-struct-visibility/target/debug/deps/modules_struct_visibility-a5e6012477b2eda2.d: src/main.rs

src/main.rs:
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/aurelien/git/rust/modules-struct-visibility/target/debug/modules-struct-visibility: /home/aurelien/git/rust/modules-struct-visibility/src/main.rs
4 changes: 4 additions & 0 deletions modules-visibility/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions modules-visibility/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "modules-visibility"
version = "0.1.0"
authors = ["Aurélien DESBRIÈRES <[email protected]>"]

[dependencies]
Loading

0 comments on commit 6767713

Please sign in to comment.