My presentations, using Reveal.js (mostly in Portuguese).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

481 lines
11 KiB

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Rust</title>
<meta name="description" content="O que Rust tem de legal">
<meta name="author" content="Julio Biason">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<link rel="stylesheet" href="reveal.js/css/theme/night.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
<style type="text/css" media="screen">
.happy {
color: yellow;
}
.reveal section img {
border: none;
}
.reveal ul.empty {
list-style: none outside;
}
li {
display: block;
}
.cursor {
background-color: #666;
color: white;
}
img {
max-height: 90%;
}
td.seen {
font-style: italic;
font-weight: bold;
}
.semi-opaque {
background-color: rgba(0, 0, 0, 0.7);
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<section data-background="_images/rust.png" data-header>
<h1 class="semi-opaque">O Que Rust Tem de Legal</h1>
</section>
</section>
<section>
<section>
<h2>Borrow Checker</h2>
</section>
<section>
<pre><code>
a = 2
</code></pre>
</section>
<section>
"Variável <code>a</code> tem o valor 2"
</section>
<section>
<div>
"Posição de memória apontada por <code>a</code> tem o valor 2"
</div>
<div class="fragment">
<pre><code>
0x3f5cbf89 = 2
</code></pre>
</div>
</section>
<section>
<div>
A language that doesn't affect the way you think
about programming, is not worth knowing.
</div>
<div>
-- Alan Perlis, "ALGOL"
</div>
</section>
<section>
<pre><code>
fn main() {
let a = String::from("hello");
let _b = a;
println!("{}", a)
}
</code></pre>
</section>
<section>
<pre><code>
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
</code></pre>
</section>
<section>
<pre><code>
fn main() {
let a = 2;
let b = a;
println!("{}", a);
println!("{}", b);
}
</code></pre>
</section>
<section>
<pre><code>
2
2
</code></pre>
6 years ago
<p class="fragment">"Copy trait"</p>
</section>
<section>
<a href="https://swift.org/blog/swift-5-exclusivity/">Swift 5 Exclusivity Enforcement</a>
</section>
</section>
<section>
<section>
<h2>Imutabilidade por Default</h2>
</section>
<section>
<pre><code>
fn main() {
let a = 2;
a = 3;
println!("{}", a);
}
</code></pre>
</section>
<section>
<pre><code>
3 | let a = 2;
| -
| |
| first assignment to `a`
| help: make this binding mutable: `mut a`
4 | a = 3;
| ^^^^^ cannot assign twice to immutable variable
</code></pre>
</section>
<section>
<pre><code>
fn main() {
let mut a = 2;
a = 3;
println!("{}", a);
}
</code></pre>
</section>
</section>
<section>
<section>
<h2>Enums</h2>
</section>
<section>
<pre><code>
enum IpAddr {
V4,
V6
}
</code></pre>
</section>
<section>
<pre><code>
enum IpAddr {
V4(String),
V6(String),
}
</code></pre>
</section>
<section>
<pre><code>
let home = IpAddr::V4(String::from("127.0.0.1");
match home {
V4(address) => println!("IPv4 addr: {}", address),
V6(address) => println!("Ipv6 addr: {}", address),
}
</code></pre>
</section>
<section>
<pre><code>
enum Option&lt;T&gt; {
Some(T),
None
}
</code></pre>
</section>
</section>
<section>
<section>
<h2>Error Control</h2>
</section>
<section>
<pre><code>
try:
something()
except Exception:
pass
</code></pre>
</section>
<section>
<pre><code>
try {
something();
} catch (Exception ex) {
System.out.println(ex);
}
</code></pre>
</section>
<section>
<pre><code>
FILE* f = fopen("someting.txt", "wb");
fprintf(f, "Done!");
fclose(f);
</code></pre>
</section>
<section>
<div>
Onde o erro foi tratado nisso?
</div>
</section>
<section>
<pre><code>
enum Result&lt;T, E&gt; {
Ok(T),
Err(E),
}
</code></pre>
</section>
<section>
<pre><code>
File::create("something.txt") match {
Ok(fp) => fp.write_all(b"Hello world"),
Err(err) => println!("Failure! {}", err),
}
</code></pre>
</section>
<section>
<pre><code>
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),
}
</code></pre>
</section>
<section>
<pre><code>
let mut file = File::create("something.txt).unwrap();
file.write(b"Hello world").unwrap();
</code></pre>
</section>
<section>
<pre><code>
let mut file = File::create("something.txt)?;
file.write(b"Hello world")?;
OK(())
</code></pre>
</section>
</section>
6 years ago
<section>
<section>
<h2>Crazy stuff</h2>
</section>
<section>
<a href="https://medium.com/@shnatsel/how-rusts-standard-library-was-vulnerable-for-years-and-nobody-noticed-aebf0503c3d6">How Rust’s standard library was vulnerable for years and nobody noticed</a>
</section>
<section>
<a href="https://medium.com/@sgrif/no-the-problem-isnt-bad-coders-ed4347810270">No, the problem isn’t “bad coders”</a>
</section>
<section>
<img src="_images/rust-issues.png" alt="4.5k issues no Github">
</section>
<section>
<a href="https://rustup.rs/">rustup</a>
<div class="fragment">
<small>stable-x86_64-pc-windows-msvc</small>
</div>
<div class="fragment">
<small>armv7-unknown-linux-gnueabihf</small>
</div>
<div class="fragment">
<small>wasm32-unknown-unknown</small> <small class="fragment">(WebAssembly)</small>
</div>
</section>
</section>
<section>
<section>
<h2>Bibliotecas</h2>
</section>
<section>
<h3>Rayon</h3>
<pre><code>
fn sum_of_squares(input: &amp;[i32]) -&gt; i32 {
input.iter()
.map(|&amp;i| i * i)
.sum()
}
</code></pre>
</section>
<section>
<h3>Rayon</h3>
<pre><code>
fn sum_of_squares(input: &amp;[i32]) -&gt; i32 {
input.par_iter()
.map(|&amp;i| i * i)
.sum()
}
</code></pre>
</section>
<section>
<h3>Log-Derive</h3>
<pre><code>
#[logfn(ok = "TRACE", err = "ERROR")]
fn call_isan(num: &amp;str) -&gt; Result&lt;Success, Error&gt; {
if num.len() &gt;= 10 &amp;&amp; num.len() &lt;= 15 {
Ok(Success)
} else {
Err(Error)
}
}
</code></pre>
</section>
</section>
<section>
<section>
<h2>E quem usa?</h2>
</section>
<section>
<h3>Magic Pocket</h3>
<p>Dropbox</p>
<p>Petabyte storage</p>
</section>
<section>
<h3>Servo</h3>
<p>Mozilla</p>
<p>Base do Firefox Quantum</p>
</section>
<section>
<h3>Azure</h3>
<p>Microsoft</p>
<p>Usado na parte de IoT do Azure</p>
</section>
<section>
<h3>Tor</h3>
</section>
</section>
<section data-background='_images/thats-all-folks.jpg'>
</section>
</div>
</div>
<script src="reveal.js/lib/js/head.min.js"></script>
<script src="reveal.js/js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
// showNotes: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true },
{ src: 'reveal.js/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>