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 6, 2017
1 parent 8676d7b commit 4b99a70
Show file tree
Hide file tree
Showing 33 changed files with 126 additions and 0 deletions.
4 changes: 4 additions & 0 deletions closures-anonymity/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 closures-anonymity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "closures-anonymity"
version = "0.1.0"
authors = ["Aurélien DESBRIÈRES <[email protected]>"]

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

// Rust experimentations
// Closures as Type Anonymity in Rust

//`F` must implement `Fn` for a closure which takes no
// inputs and returns nothing - exactly what is required
// for `print`.
fn apply<F>(f: F) where
F: Fn() {
f();
}

fn main() {
let x = 7;

// Capture `x` into an anonymous type and implement
// `Fn` for it. Sotre in `print`.
let print = || println!("{}", x);

apply(print);
}

3 changes: 3 additions & 0 deletions closures-anonymity/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 @@
e5523b0cfc4c3222
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Binary file not shown.
1 change: 1 addition & 0 deletions closures-anonymity/target/debug/closures-anonymity.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/aurelien/git/rust/closures-anonymity/target/debug/closures-anonymity: /home/aurelien/git/rust/closures-anonymity/src/main.rs
Binary file not shown.
4 changes: 4 additions & 0 deletions closures-as-output-parameters/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 closures-as-output-parameters/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "closures-as-output-parameters"
version = "0.1.0"
authors = ["Aurélien DESBRIÈRES <[email protected]>"]

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

// Rust experimentations
// Closures as Output Parameters

fn create_fn() -> Box<Fn()> {
let text = "Fn".to_owned();

Box::new(move || println!("This is a: {}", text))
}

fn create_fnmut() -> Box<FnMut()> {
let text = "FnMut".to_owned();

Box::new(move || println!("This is al {}", text))
}

fn main() {
let fn_plain = create_fn();
let mut fn_mut = create_fnmut();

fn_plain();
fn_mut();
}

3 changes: 3 additions & 0 deletions closures-as-output-parameters/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 @@
4b6a32595b0d8568
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +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
Binary file not shown.
4 changes: 4 additions & 0 deletions closures-input-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 closures-input-functions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "closures-input-functions"
version = "0.1.0"
authors = ["Aurélien DESBRIÈRES <[email protected]>"]

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

// Rust experimentations
// Closures as Input Functions

// Define a function which takes a generic `F` argument
// bounded by `Fn`, and calls it
fn call_me<F: Fn()>(f: F) {
f();
}

// Define a wrapper function satisfying the `Fn` bounded
fn function() {
println!("I'm a function!");
}

fn main() {
// Define a closure satisfying the `Fn` bound
let closure = || println!("I'm a closure!");

call_me(closure);
call_me(function);
}

3 changes: 3 additions & 0 deletions closures-input-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 @@
59f07fec80106cb4
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/aurelien/git/rust/closures-input-functions/target/debug/closures-input-functions: /home/aurelien/git/rust/closures-input-functions/src/main.rs
Binary file not shown.

0 comments on commit 4b99a70

Please sign in to comment.