+
+
+
+
+
+ "Variável a
tem o valor 2"
+
+
+
+
+ "Posição de memória apontada por a
tem o valor 2"
+
+
+
+
+
+
+
+ A language that doesn't affect the way you think
+ about programming, is not worth knowing.
+
+
+
+ -- Alan Perlis, "ALGOL"
+
+
+
+
+
+fn main() {
+ let a = String::from("hello");
+ let _b = a;
+ println!("{}", a)
+}
+
+
+
+
+
+error[E0382]: borrow of moved value: `a`
+ --> src/main.rs:5:20
+ |
+4 | let _b = a;
+ | - value moved here
+5 | println!("{}", a)
+ | ^ value borrowed here after move
+ |
+ = note: move occurs because `a` has type `std::string::String`, which does not implement the `Copy` trait
+
+
+
+
+
+fn main() {
+ let a = 2;
+ let b = a;
+ println!("{}", a);
+ println!("{}", b);
+}
+
+
+
+
+
+2
+2
+
+
+ "Copy trait"
+
+
+
+
+
+
+
+
+try:
+ something()
+except Exception:
+ pass
+
+
+
+
+
+try {
+ something();
+} catch (Exception ex) {
+ System.out.println(ex);
+}
+
+
+
+
+
+FILE* f = fopen("someting.txt", "wb");
+fprintf(f, "Done!");
+fclose(f);
+
+
+
+
+
+ Onde o erro foi tratado nisso?
+
+
+
+
+
+enum Result<T, E> {
+ Ok(T),
+ Err(E),
+}
+
+
+
+
+
+File::create("something.txt") match {
+ Ok(fp) => fp.write_all(b"Hello world"),
+ Err(err) => println!("Failure! {}", err),
+}
+
+
+
+
+
+File::create("something.txt") match {
+ Ok(fp) => fp.write_all(b"Hello world") match {
+ Ok(_) => (),
+ Err(err) => println!("Can't write! {}", err),
+ }
+ Err(err) => println!("Failure! {}", err),
+}
+
+
+
+
+
+let mut file = File::create("something.txt).unwrap();
+file.write(b"Hello world").unwrap();
+
+
+
+
+
+let mut file = File::create("something.txt)?;
+file.write(b"Hello world")?;
+OK(())
+
+
+