Skip to content

Commit 4b99a70

Browse files
committed
+ much more rusties
1 parent 8676d7b commit 4b99a70

33 files changed

+126
-0
lines changed

closures-anonymity/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

closures-anonymity/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "closures-anonymity"
3+
version = "0.1.0"
4+
authors = ["Aurélien DESBRIÈRES <[email protected]>"]
5+
6+
[dependencies]

closures-anonymity/src/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Aurélien DESBRIÈRES
2+
aurelien(at)hackers(dot)camp
3+
License GNU GPL latest */
4+
5+
// Rust experimentations
6+
// Closures as Type Anonymity in Rust
7+
8+
//`F` must implement `Fn` for a closure which takes no
9+
// inputs and returns nothing - exactly what is required
10+
// for `print`.
11+
fn apply<F>(f: F) where
12+
F: Fn() {
13+
f();
14+
}
15+
16+
fn main() {
17+
let x = 7;
18+
19+
// Capture `x` into an anonymous type and implement
20+
// `Fn` for it. Sotre in `print`.
21+
let print = || println!("{}", x);
22+
23+
apply(print);
24+
}
25+

closures-anonymity/src/main.rs~

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

closures-anonymity/target/debug/.cargo-lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e5523b0cfc4c3222
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"rustc":7337822701906583572,"target":10252773731995063932,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1491495920,659360326],[47,104,111,109,101,47,97,117,114,101,108,105,101,110,47,103,105,116,47,114,117,115,116,47,99,108,111,115,117,114,101,115,45,97,110,111,110,121,109,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,99,108,111,115,117,114,101,115,45,97,110,111,110,121,109,105,116,121,45,54,97,102,51,57,102,98,101,51,102,55,101,102,55,48,55,47,100,101,112,45,98,105,110,45,99,108,111,115,117,114,101,115,95,97,110,111,110,121,109,105,116,121,45,54,97,102,51,57,102,98,101,51,102,55,101,102,55,48,55]]},"features":"None","deps":[],"rustflags":[]}
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/aurelien/git/rust/closures-anonymity/target/debug/closures-anonymity: /home/aurelien/git/rust/closures-anonymity/src/main.rs
Binary file not shown.

closures-as-output-parameters/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "closures-as-output-parameters"
3+
version = "0.1.0"
4+
authors = ["Aurélien DESBRIÈRES <[email protected]>"]
5+
6+
[dependencies]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Aurélien DESBRIÈRES
2+
aurelien(at)hackers(dot)camp
3+
License GNU GPL latest */
4+
5+
// Rust experimentations
6+
// Closures as Output Parameters
7+
8+
fn create_fn() -> Box<Fn()> {
9+
let text = "Fn".to_owned();
10+
11+
Box::new(move || println!("This is a: {}", text))
12+
}
13+
14+
fn create_fnmut() -> Box<FnMut()> {
15+
let text = "FnMut".to_owned();
16+
17+
Box::new(move || println!("This is al {}", text))
18+
}
19+
20+
fn main() {
21+
let fn_plain = create_fn();
22+
let mut fn_mut = create_fnmut();
23+
24+
fn_plain();
25+
fn_mut();
26+
}
27+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

closures-as-output-parameters/target/debug/.cargo-lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4b6a32595b0d8568
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"rustc":7337822701906583572,"target":11229966374791113190,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1491497676,669321395],[47,104,111,109,101,47,97,117,114,101,108,105,101,110,47,103,105,116,47,114,117,115,116,47,99,108,111,115,117,114,101,115,45,97,115,45,111,117,116,112,117,116,45,112,97,114,97,109,101,116,101,114,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,99,108,111,115,117,114,101,115,45,97,115,45,111,117,116,112,117,116,45,112,97,114,97,109,101,116,101,114,115,45,56,98,101,48,97,51,57,52,51,97,56,98,57,98,97,99,47,100,101,112,45,98,105,110,45,99,108,111,115,117,114,101,115,95,97,115,95,111,117,116,112,117,116,95,112,97,114,97,109,101,116,101,114,115,45,56,98,101,48,97,51,57,52,51,97,56,98,57,98,97,99]]},"features":"None","deps":[],"rustflags":[]}
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/aurelien/git/rust/closures-as-output-parameters/target/debug/closures-as-output-parameters: /home/aurelien/git/rust/closures-as-output-parameters/src/main.rs

closures-input-functions/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

closures-input-functions/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "closures-input-functions"
3+
version = "0.1.0"
4+
authors = ["Aurélien DESBRIÈRES <[email protected]>"]
5+
6+
[dependencies]

closures-input-functions/src/main.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Aurélien DESBRIÈRES
2+
aurelien(at)hackers(dot)camp
3+
License GNU GPL latest */
4+
5+
// Rust experimentations
6+
// Closures as Input Functions
7+
8+
// Define a function which takes a generic `F` argument
9+
// bounded by `Fn`, and calls it
10+
fn call_me<F: Fn()>(f: F) {
11+
f();
12+
}
13+
14+
// Define a wrapper function satisfying the `Fn` bounded
15+
fn function() {
16+
println!("I'm a function!");
17+
}
18+
19+
fn main() {
20+
// Define a closure satisfying the `Fn` bound
21+
let closure = || println!("I'm a closure!");
22+
23+
call_me(closure);
24+
call_me(function);
25+
}
26+

closures-input-functions/src/main.rs~

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

closures-input-functions/target/debug/.cargo-lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
59f07fec80106cb4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"rustc":7337822701906583572,"target":17611836378413514346,"profile":14528549471338536373,"local":{"variant":"MtimeBased","fields":[[1491496483,209347855],[47,104,111,109,101,47,97,117,114,101,108,105,101,110,47,103,105,116,47,114,117,115,116,47,99,108,111,115,117,114,101,115,45,105,110,112,117,116,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,99,108,111,115,117,114,101,115,45,105,110,112,117,116,45,102,117,110,99,116,105,111,110,115,45,99,97,49,98,51,101,54,101,55,49,56,48,101,51,55,51,47,100,101,112,45,98,105,110,45,99,108,111,115,117,114,101,115,95,105,110,112,117,116,95,102,117,110,99,116,105,111,110,115,45,99,97,49,98,51,101,54,101,55,49,56,48,101,51,55,51]]},"features":"None","deps":[],"rustflags":[]}
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/aurelien/git/rust/closures-input-functions/target/debug/closures-input-functions: /home/aurelien/git/rust/closures-input-functions/src/main.rs

0 commit comments

Comments
 (0)