On Github vinipsmaker / propaganda-rust
fn main() { println!("Hello world") }
hashOut.data = hashes + SSL_MD5_DIGEST_LEN; hashOut.length = SSL_SHA1_DIGEST_LEN; if ((err = SSLFreeBuffer(&hashCtx)) != 0) goto fail; if ((err = ReadyHash(&SSLHashSHA1, &hashCtx)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &clientRandom)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail; /* MISTAKE! THIS LINE SHOULD NOT BE HERE */ if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0) goto fail; err = sslRawVerify(...);
db.query("SELECT first, last FROM users " "WHERE login = '#{login}' " "AND customer = '#{customer}' " "AND department = '#{department}'")
fn main() { println!("Hello world"); return; println!("Oops"); }
<std macros>:2:1: 2:58 warning: unreachable statement, #[warn(unreachable_code)] on by default
fn foo(n: i32) -> char { let ret; if n < 0 { ret = '-' } return ret } fn main() { println!("{}", foo(42)) }
test.rs:6:12: 6:15 error: use of possibly uninitialized variable: `ret` [E0381]
fn main() { let x = 0; if x = 2 { println!("HEY") } }
<anon>:3:8: 3:13 error: mismatched types: expected `bool`, found `()`
Afeta curva de aprendizado.
Elimina necessidade de GC.
Expressão que você escreve resulta no tipo especificado a esquerda.
int *p; // *p int a[3]; // a[2] int (*fp)(int a, int b); // (*fp)(1, 2) int (*fp)(int (*ff)(int x, int y), int b);
let a; let b: i32; let c = 42; let d = 42i32; let e: i32 = 42; let _f; let mut g; let (endpoint, _data) = socket.recv(); let (endpoint, _) = socket.recv();
fn main() { let x: () = (); return x; }
fn id(id_arg: String, a: &mut int, _: &Foo) -> bool { // ... }
let x = { "abc"; 55; if y > 2 { 30 } else { 14 } };
let x = if y > 2 { 30 } else { 14 };
let mut x; if y > 2 { x = 30 } else { x = 14 }; let x = x;
fn fibonacci(number: u32) -> u32 { match number { 0 => 1, 1 => 1, x => fibonacci(x - 1) + fibonacci(x - 2), } } fn main() { let number = 5; let fib_result = fibonacci(number); println!("fibonacci({}) = {}", number, fib_result); }
enum Option { Some(i32), None, } fn foo() -> Option { let x = Option::Some(42); x }
use std::io; use std::process::exit; fn main() { let reader = io::stdin(); let mut line = String::new(); if let Err(_) = reader.read_line(&mut line) { println!("Falhou ao ler"); exit(1) } let line = line.trim(); match line.parse::<i32>() { Ok(x) => println!("{}", x + 1), Err(_) => { println!("{:?} não é um número", line); exit(2) }, }; }