diff --git a/porque-rust.html b/porque-rust.html index 74f6eac..d23dfd4 100644 --- a/porque-rust.html +++ b/porque-rust.html @@ -94,7 +94,7 @@
-

+						

 fn main() {
     let a = 2;
     a = 3;
@@ -104,7 +104,7 @@ fn main() {
 					
-

+						

 3 |     let a = 2;
   |         -
   |         |
@@ -116,7 +116,7 @@ fn main() {
 					
-

+						

 fn main() {
     let mut a = 2;
     a = 3;
@@ -132,25 +132,27 @@ fn main() {
 					
-

-a = 2
+						

+a = String::from("hello");
 						
- "Variável a tem o valor 2" + "Variável a tem o valor "hello""
- "Posição de memória apontada por a tem o valor 2" + "Posição de memória apontada por a tem o valor "hello""

-0x3f5cbf89 = 2
+0x3f5cbf89 = "hello"
 							
+ +
@@ -165,7 +167,7 @@ a = 2
-

+						

 fn main() {
     let a = String::from("hello");
     let _b = a;
@@ -189,13 +191,13 @@ error[E0382]: borrow of moved value: `a`
 					
-

E se eu precisar acessar a variável em mais de um lugar?

+

E se eu precisar acessar a variável em mais de um lugar?

-

References

+

References

-

+						

 fn main() {
     let a = String::from("hello");
     let _b = &a;
@@ -204,6 +206,10 @@ fn main() {
 						
+
+ +
+

Regras do Borrow Checker

@@ -225,11 +231,18 @@ fn main() {
- +
- +
presente := Presente { ... }
+canal <- presente
+
+ +
+
presente := Presente { ... }
+canal <- presente
+presente.abrir()
@@ -239,11 +252,14 @@ fn main() {
-

Enums

+

Tipos Algébricos

+ +

(structs)

-

+						

enum

+

 enum IpAddr {
    V4,
    V6
@@ -252,7 +268,7 @@ enum IpAddr {
 					
-

+						

 enum IpAddr {
     V4(String),
     V6(String),
@@ -261,18 +277,18 @@ enum IpAddr {
 					
-

+						

 let home = IpAddr::V4(String::from("127.0.0.1");
 
 match home {
-    V4(address) => println!("IPv4 addr: {}", address),
-    V6(address) => println!("Ipv6 addr: {}", address),
+    V4(address) => println!("IPv4 addr: {}", address),
+    V6(address) => println!("Ipv6 addr: {}", address),
 }
 						
-

+						

 enum Option<T> {
     Some(T),
     None
@@ -287,7 +303,7 @@ enum Option<T> {
 					
-

+						

 try:
     something()
 except Exception:
@@ -296,7 +312,7 @@ except Exception:
 					
-

+						

 try {
    something();
 } catch (Exception ex) {
@@ -306,7 +322,7 @@ try {
 					
-

+						

 FILE* f = fopen("someting.txt", "wb");
 fprintf(f, "Done!");
 fclose(f);
@@ -320,7 +336,7 @@ fclose(f);
 					
-

+						

 enum Result<T, E> {
     Ok(T),
     Err(E),
@@ -329,36 +345,36 @@ enum Result<T, E> {
 					
-

+						

 File::create("something.txt") match {
-    Ok(fp) => fp.write_all(b"Hello world"),
-    Err(err) => println!("Failure! {}", err),
+    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),
+    Ok(fp) => fp.write_all(b"Hello world") match {
+        Ok(_) => (),
+        Err(err) => println!("Can't write! {}", err),
     }
-    Err(err) => println!("Failure! {}", err),
+    Err(err) => println!("Failure! {}", err),
 }
 						
-

-let mut file = File::create("something.txt).unwrap();
+                        

+let mut file = File::create("something.txt").unwrap();
 file.write(b"Hello world").unwrap();
                         
-

-let mut file = File::create("something.txt)?;
+                        

+let mut file = File::create("something.txt")?;
 file.write(b"Hello world")?;
 OK(())
                         
@@ -379,7 +395,7 @@ OK(())
- 4.5k issues no Github + 4.5k issues no Github