Browse Source

A few more technical bits

master
Julio Biason 5 years ago
parent
commit
f753ea4abb
  1. 133
      quick-rust.html

133
quick-rust.html

@ -122,25 +122,23 @@
<img class="fragment" src="_images/AYV1X0yv.png" alt="" style="width:100px;margin:0"> <img class="fragment" src="_images/AYV1X0yv.png" alt="" style="width:100px;margin:0">
</h2> </h2>
<p> <p class="fragment">
<span class="fragment">Basic</span> Basic (com números e estruturado),
<span class="fragment"> (com números e estruturado)</span> dBase III Plus,
<span class="fragment">, dBase III Plus</span> Clipper,
<span class="fragment">, Clipper</span> Pascal,
<span class="fragment">, Pascal</span> Cobol,
<span class="fragment">, Cobol</span> Delphi (ObjectPascal),
<span class="fragment">, Delphi (ObjectPascal)</span> C,
<span class="fragment">, C</span> C++,
<span class="fragment">, C++</span> ActionScript (Flash),
<span class="fragment">, ActionScript (Flash)</span> PHP,
<span class="fragment">, PHP</span> JavaScript,
<span class="fragment">, JavaScript</span> Python,
<span class="fragment">, Python</span> Objective-C,
<span class="fragment">, Objective-C</span> Clojure,
<span class="fragment">, Clojure</span> Java,
<span class="fragment">, Java</span> Scala<strong>, Rust.</strong>
<span class="fragment">, Scala</span>
<span class="fragment"><strong>, Rust.</strong></span>
</p> </p>
<aside class="notes"> <aside class="notes">
@ -220,9 +218,7 @@ fn main() {
</section> </section>
<section> <section>
<h3>Meu Primeiro Rust</h3> <h3><code>cargo init</code></h3>
<code>cargo init</code>
<aside class="notes"> <aside class="notes">
Apesar do compilar do rust ser o `rustc`, a linguagem vem Apesar do compilar do rust ser o `rustc`, a linguagem vem
@ -268,11 +264,11 @@ fn main() {
<section> <section>
<section> <section>
<h3>Mas De Volta Ao Rust</h3> <h3>De Volta Ao Rust - Static Typed</h3>
<pre><code class="rust"> <pre><code class="rust">
fn main() { fn main() {
let a:u8 = 2; let a: u8 = 2;
println!("{}", a); println!("{}", a);
} }
</code></pre> </code></pre>
@ -319,9 +315,11 @@ fn main() {
irá encontrar o melhor tipo que "caiba" o valor e seja irá encontrar o melhor tipo que "caiba" o valor e seja
eficiente para a máquina destino. eficiente para a máquina destino.
</aside> </aside>
</section>
<section> <section>
<h3>Mas De Volta ao Rust</h3> <section>
<h3>De Volta ao Rust - Pattern Matching</h3>
<pre><code class="rust"> <pre><code class="rust">
fn factorial(i: u64) -&gt; u64 { fn factorial(i: u64) -&gt; u64 {
@ -346,9 +344,11 @@ fn factorial(i: u64) -&gt; u64 {
`n`, e a expressão termina com esse valor multiplicado `n`, e a expressão termina com esse valor multiplicado
pelo fatorial dele menos 1. pelo fatorial dele menos 1.
</aside> </aside>
</section>
<section> <section>
<h3>Mas De Volta ao Rust</h3> <section>
<h3>De Volta ao Rust - Returns are not necessary</h3>
<pre><code class="rust"> <pre><code class="rust">
fn is_pred(i: u64) -&gt; Bool { fn is_pred(i: u64) -&gt; Bool {
@ -370,7 +370,7 @@ fn is_pred(i: u64) -&gt; Bool {
</section> </section>
<section> <section>
<h3>Mas De Volta ao Rust</h3> <h3>De Volta ao Rust - Returns are not necessary</h3>
<pre><code class="rust"> <pre><code class="rust">
fn is_pred(i: u64) -&gt; Bool { fn is_pred(i: u64) -&gt; Bool {
@ -382,9 +382,11 @@ fn is_pred(i: u64) -&gt; Bool {
Uma forma mais simples de escrever a função anterior. Uma forma mais simples de escrever a função anterior.
</aside> </aside>
</section> </section>
</section>
<section> <section>
<h3>Mas De Volta ao Rust</h3> <section>
<h3>De Volta ao Rust - Enums</h3>
<pre><code class="rust"> <pre><code class="rust">
enum IPAddr { enum IPAddr {
@ -423,6 +425,79 @@ match home {
</section> </section>
</section> </section>
<section>
<section>
<h3>De Volta ao Rust - No OO</h3>
</section>
<section>
<h3>No OO</h3>
<pre><code class="rust">
struct MyStruct {
a_field: String,
r_a: [2; 10u64],
}
</code></pre>
</section>
<section>
<h3>No OO - But "functions in structs"</h3>
<pre><code class="rust">
impl MyStruct {
fn first_element(&amp;self) -&gt; u64 {
self.r_a.get(1)
}
}
</code></pre>
</section>
<section>
<h3>No OO - But Traits</h3>
<pre><code class="rust">
trait Summarize {
fn summarize(&amp;self) -&gt; String;
}
</code></pre>
</section>
<section>
<h3>No OO - But Traits</h3>
<pre><code class="rust">
impl Summarize for MyStruct {
fn summarize(&amp;self) -&gt; String {
self.a_field
}
}
</code></pre>
</section>
<section>
<h3>No OO - But Generics</h3>
<pre><code class="rust">
fn make_summary&lt;T&gt;(summarizable: T) {
T.summarize()
}
</code></pre>
</section>
<section>
<h3>No OO - But Generic Traits</h3>
<pre><code class="rust">
fn make_summary&lt;T&gt;(summarizable: T)
where T: Summarize
{
T.summarize()
}
</code></pre>
</section>
</section>
<section> <section>
<section> <section>
<h2>E Aquela "Segurança de Memória"?</h2> <h2>E Aquela "Segurança de Memória"?</h2>
@ -432,7 +507,7 @@ match home {
<h3>1. No Null Pointers</h3> <h3>1. No Null Pointers</h3>
<pre><code class="rust"> <pre><code class="rust">
match may_not_exist(value: Option&lt;String&gt;) { fn may_not_exist(value: Option&lt;String&gt;) {
match value { match value {
Some(the_string) =&gt; println!("I got a string! {}", the_string), Some(the_string) =&gt; println!("I got a string! {}", the_string),
None =&gt; println!("I got nothing") None =&gt; println!("I got nothing")

Loading…
Cancel
Save