|
|
@ -94,7 +94,7 @@ |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
let a = 2; |
|
|
|
let a = 2; |
|
|
|
a = 3; |
|
|
|
a = 3; |
|
|
@ -104,7 +104,7 @@ fn main() { |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs" data-trim> |
|
|
|
3 | let a = 2; |
|
|
|
3 | let a = 2; |
|
|
|
| - |
|
|
|
| - |
|
|
|
| | |
|
|
|
| | |
|
|
@ -116,7 +116,7 @@ fn main() { |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
let mut a = 2; |
|
|
|
let mut a = 2; |
|
|
|
a = 3; |
|
|
|
a = 3; |
|
|
@ -132,25 +132,27 @@ fn main() { |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
a = 2 |
|
|
|
a = String::from("hello"); |
|
|
|
</code></pre> |
|
|
|
</code></pre> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
"Variável <code>a</code> tem o valor 2" |
|
|
|
"Variável <code>a</code> tem o valor <code>"hello"</code>" |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
"Posição de memória apontada por <code>a</code> tem o valor 2" |
|
|
|
"Posição de memória apontada por <code>a</code> tem o valor <code>"hello"</code>" |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div class="fragment"> |
|
|
|
<div class="fragment"> |
|
|
|
<pre><code> |
|
|
|
<pre><code> |
|
|
|
0x3f5cbf89 = 2 |
|
|
|
0x3f5cbf89 = "hello" |
|
|
|
</code></pre> |
|
|
|
</code></pre> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<img src="_images/rust-memory.png" alt="" class="fragment"> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
@ -165,7 +167,7 @@ a = 2 |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
let a = String::from("hello"); |
|
|
|
let a = String::from("hello"); |
|
|
|
let _b = a; |
|
|
|
let _b = a; |
|
|
@ -189,13 +191,13 @@ error[E0382]: borrow of moved value: `a` |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<h3>E se eu precisar acessar a variável em mais de um lugar?</h3> |
|
|
|
<p>E se eu precisar acessar a variável em mais de um lugar?</p> |
|
|
|
|
|
|
|
|
|
|
|
<p class="fragment">References</p> |
|
|
|
<h3 class="fragment">References</h3> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
let a = String::from("hello"); |
|
|
|
let a = String::from("hello"); |
|
|
|
let _b = &a; |
|
|
|
let _b = &a; |
|
|
@ -204,6 +206,10 @@ fn main() { |
|
|
|
</code></pre> |
|
|
|
</code></pre> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
|
|
|
|
<img src="_images/rust-reference.png" alt=""> |
|
|
|
|
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<h3>Regras do Borrow Checker</h3> |
|
|
|
<h3>Regras do Borrow Checker</h3> |
|
|
|
|
|
|
|
|
|
|
@ -225,11 +231,18 @@ fn main() { |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<img src="_images/rust-memory.png" alt=""> |
|
|
|
<img src="_images/dunno.jpg" alt=""> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<img src="_images/rust-reference.png" alt=""> |
|
|
|
<pre><code class="hljs go" data-trim>presente := Presente { ... } |
|
|
|
|
|
|
|
canal <- presente</code></pre> |
|
|
|
|
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
|
|
|
|
<pre><code class="hljs go" data-trim>presente := Presente { ... } |
|
|
|
|
|
|
|
canal <- presente |
|
|
|
|
|
|
|
presente.abrir()</code></pre> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
@ -239,11 +252,14 @@ fn main() { |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<h2>Enums</h2> |
|
|
|
<h2>Tipos Algébricos</h2> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<p class="fragment">(structs)</p> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<h3>enum</h3> |
|
|
|
|
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
enum IpAddr { |
|
|
|
enum IpAddr { |
|
|
|
V4, |
|
|
|
V4, |
|
|
|
V6 |
|
|
|
V6 |
|
|
@ -252,7 +268,7 @@ enum IpAddr { |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
enum IpAddr { |
|
|
|
enum IpAddr { |
|
|
|
V4(String), |
|
|
|
V4(String), |
|
|
|
V6(String), |
|
|
|
V6(String), |
|
|
@ -261,18 +277,18 @@ enum IpAddr { |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
let home = IpAddr::V4(String::from("127.0.0.1"); |
|
|
|
let home = IpAddr::V4(String::from("127.0.0.1"); |
|
|
|
|
|
|
|
|
|
|
|
match home { |
|
|
|
match home { |
|
|
|
V4(address) => println!("IPv4 addr: {}", address), |
|
|
|
V4(address) => println!("IPv4 addr: {}", address), |
|
|
|
V6(address) => println!("Ipv6 addr: {}", address), |
|
|
|
V6(address) => println!("Ipv6 addr: {}", address), |
|
|
|
} |
|
|
|
} |
|
|
|
</code></pre> |
|
|
|
</code></pre> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
enum Option<T> { |
|
|
|
enum Option<T> { |
|
|
|
Some(T), |
|
|
|
Some(T), |
|
|
|
None |
|
|
|
None |
|
|
@ -287,7 +303,7 @@ enum Option<T> { |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs python" data-trim> |
|
|
|
try: |
|
|
|
try: |
|
|
|
something() |
|
|
|
something() |
|
|
|
except Exception: |
|
|
|
except Exception: |
|
|
@ -296,7 +312,7 @@ except Exception: |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs java" data-trim> |
|
|
|
try { |
|
|
|
try { |
|
|
|
something(); |
|
|
|
something(); |
|
|
|
} catch (Exception ex) { |
|
|
|
} catch (Exception ex) { |
|
|
@ -306,7 +322,7 @@ try { |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs c" data-trim> |
|
|
|
FILE* f = fopen("someting.txt", "wb"); |
|
|
|
FILE* f = fopen("someting.txt", "wb"); |
|
|
|
fprintf(f, "Done!"); |
|
|
|
fprintf(f, "Done!"); |
|
|
|
fclose(f); |
|
|
|
fclose(f); |
|
|
@ -320,7 +336,7 @@ fclose(f); |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
enum Result<T, E> { |
|
|
|
enum Result<T, E> { |
|
|
|
Ok(T), |
|
|
|
Ok(T), |
|
|
|
Err(E), |
|
|
|
Err(E), |
|
|
@ -329,36 +345,36 @@ enum Result<T, E> { |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
File::create("something.txt") match { |
|
|
|
File::create("something.txt") match { |
|
|
|
Ok(fp) => fp.write_all(b"Hello world"), |
|
|
|
Ok(fp) => fp.write_all(b"Hello world"), |
|
|
|
Err(err) => println!("Failure! {}", err), |
|
|
|
Err(err) => println!("Failure! {}", err), |
|
|
|
} |
|
|
|
} |
|
|
|
</code></pre> |
|
|
|
</code></pre> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
File::create("something.txt") match { |
|
|
|
File::create("something.txt") match { |
|
|
|
Ok(fp) => fp.write_all(b"Hello world") match { |
|
|
|
Ok(fp) => fp.write_all(b"Hello world") match { |
|
|
|
Ok(_) => (), |
|
|
|
Ok(_) => (), |
|
|
|
Err(err) => println!("Can't write! {}", err), |
|
|
|
Err(err) => println!("Can't write! {}", err), |
|
|
|
} |
|
|
|
} |
|
|
|
Err(err) => println!("Failure! {}", err), |
|
|
|
Err(err) => println!("Failure! {}", err), |
|
|
|
} |
|
|
|
} |
|
|
|
</code></pre> |
|
|
|
</code></pre> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
let mut file = File::create("something.txt).unwrap(); |
|
|
|
let mut file = File::create("something.txt").unwrap(); |
|
|
|
file.write(b"Hello world").unwrap(); |
|
|
|
file.write(b"Hello world").unwrap(); |
|
|
|
</code></pre> |
|
|
|
</code></pre> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<pre><code> |
|
|
|
<pre><code class="hljs rust" data-trim> |
|
|
|
let mut file = File::create("something.txt)?; |
|
|
|
let mut file = File::create("something.txt")?; |
|
|
|
file.write(b"Hello world")?; |
|
|
|
file.write(b"Hello world")?; |
|
|
|
OK(()) |
|
|
|
OK(()) |
|
|
|
</code></pre> |
|
|
|
</code></pre> |
|
|
@ -379,7 +395,7 @@ OK(()) |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|
<img src="_images/rust-issues.png" alt="4.5k issues no Github"> |
|
|
|
<img src="_images/rust-issues.png" alt="4.5k issues no Github" class="stretch"> |
|
|
|
</section> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section> |
|
|
|
<section> |
|
|
|