Coggle requires JavaScript to display documents.
match
switch
let number = 13; match number { 1 => println!("One!"), 2 | 3 | 5 | 7 | 11 => println!("This is a prime"), 13...19 => println!("A teen"), _ => println!("Ain't special"), }
let reference = &1u32 match reference { &v => println!("Destructured value {:?}", v) }
let reference = &1u32 match *reference { v => println!("Dereferenced value {:?}", v) }
let value = 1u32 match value { ref r => println!("Destructured reference {:?}", r) }
let mut value = 1u32 match value { ref mut r => { *r += 1; println!("Destructured mutable reference {:?}", r) } }
(x, y) if x == y => println!("guarded")
loop
fn main() { let mut count = 0u32; loop { count += 1; if count == 3 { println!("three"); continue; } println!("{}", count); if count == 5 { break; } } }
#![allow(unreachable_code)] fn main() { 'outer: loop { println!("Entered the outer loop"); 'inner: loop { println!("Entered the inner loop"); // This would break only the inner loop //break; // This breaks the outer loop break 'outer; } println!("This point will never be reached"); } println!("Exited the outer loop"); }
for n in 0..100 { }
[0, 100[
for n in 0...100 { }
[0, 100]
if let Some(x) = maybe { ... }
Fn
&T
FnMut
&mut T
FnOnce
T
fn apply<F>(f: F) where F: Fn() { f(); }
fn apply<F: Fn()>(f: F) { f(); } fn function() { println!("Function satisfying `Fn` bound"); } fn main() { let closure = || println!("Closure satisfying `Fn` bound"); apply(closure); apply(function); }
fn create_fn() -> Box<Fn()> { Box::new(move || println!("Fn")) }
move
foo(&bar)
foo(bar)
let x = 1u32
let x = Box::new(1u32)
struct Foo { x: (u32, u32), y: u32 } let foo = Foo { x: (1, 2), y: 3 }; let Foo { x: (a, b), y } = foo; println!("a = {}, b = {}, y = {} ", a, b, y); // Variables can be ignored: let Foo { y, .. } = foo; println!("y = {}", y);
$ rustc --crate-type=lib rary.rs $ ls lib* library.rlib
#![crate_type = "lib"] #![crate_name = "rary"]
extern crate rary;
#[cfg(target_os = "linux")]
#[cfg(not(target_os = "linux"))]
type NanoSecond = u64
type IoResult<T> = Result<T, IoError>