From 3b8d5d9f6046164a7a3d8df94f9f5b8bd0161d7b Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 11 Feb 2019 21:04:32 -0200 Subject: [PATCH] Cool things about rust --- _images/rust.png | Bin 0 -> 4585 bytes cargo-cult.html | 4 + rust-legal.html | 365 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 _images/rust.png create mode 100644 rust-legal.html diff --git a/_images/rust.png b/_images/rust.png new file mode 100644 index 0000000000000000000000000000000000000000..95257d597a958e8f76dfe5bc0b087b563f852ec2 GIT binary patch literal 4585 zcmeHKc{tST9-pl-O=D=0b*_<3f4cW9_j&Gp?mf>r=ehr!d1jv9yzlq(`F`K`^Srtcm6a7Pm&@bvzI^$@=ktX^AuzDN zK7T3jXDh&!;gM(u%&+>4`w)kudGb zH{aaoB}|5=Y}yFQDP^yS(bF?EuYY6lJHC^92Ftn)T{I(Iwz>&2#%>wrHav5CfGnCV zzDJ)+AG>{bA^7}{M`YW0hK?7w%N20u`8y_OFv6hA&wfbN^do4r4Ma~I;x@uZ^Y4kq zGg38cMOnR`M_&s=mTD~t4lxzg1Otaj$4YzglQ8c{fDQH89W5nD1XR~ z{-}Hb8YHj%GH>_Y`8-jUsiQ2dPhm6WCuS8m46|l@Fn@n8@fk}cb*T-!GcnQMWvk># z7sw_aM`V4EZK>L3apM4N<+V2gNV5X}oh*`S6|BOMfj39j!YmMlibRCpcedQuI4pd0 zySXtILp65qekiyXK|U^7RGyi$9r}u>sasVMxxu__S5!+v5t!@yjRNf|L81J#(^p+s zhiR7y`jD7<`e|ueVue5y#Zs`otq@GWHI`}2@07igt-~7xbBE*P1qJvE!qw#{^O@O$ zYTzr`!zuH7Z_>eGc4pYk*HA3fKwY6QEDY(!eg3X}p?Bs|>cwAdD05~#C$Za`h49*T z9h^x8mrAXK2l7zTRLcWS2H4>h@|M`Bg3qx$J10Q&k&BJ#no-8XFJ`){S1jwq<{$5m ze4&DBZ_ez-3A5QPv`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1yzG z6IrgHCYP~*h;@(bogX3T0<>IDJXOpq-{eeU_XhVy)%QZBKg*(}9k}^zdSiy+W!1FC z9uD=AehZ(|{J9ACL2Njo2)7hElzUZ6xaYxzoot>-wZ~4&Rg7MVC$JQLZpcc3IKu&H z8zq9Cl3Ivbb93)!Hv>#fs~CReR($B28a!Q~^hh(Iv<@m#l_(B_LVjCgw};@a0=B7Q zcyV4ZB^qNo7AJ$_%}9R^%w*tZk3G}MX)5>Ady0RxQCUsJuqV1Ss1*_bHCf#~-y_NJDoc zJn?a){($pgz#E5yU1SN^R+vMQPcLdq$B=FFKKG6 zR7(I5_P*L`^nLZ|%&oyLM?ZBTx9C4qxuY{;8d;-0jc?dhV+?Broa$#FYqOoFdzh!Zy%Zh2w6 zykY;7#*DZuK}6`Uf$Piu1(+21{|DN0r_m2eoAw8LHm->VobeM~-)(g(ZJMzEhyrA$ z#AubByD##lXE>)uYZ&7M9QWeN6d$X^vL4c+>RC7v;{?pqzV)_(T}W(I*AHObkZNy#%X4wZ0Ut1c**&5fBDI>3O*M{7W8mIPlr4d7 z=@07cQK|)Y0b;M+)u)Wkmz3kH~pCp#mqP1pF$)tWS&$AJ^z{cQx z9fgSND=WXUYHu+6ytfakT}ig`M`(!8w=ZY9UP-jzXRrHvgfsVV0QQ@Sr-N>P21dRF z*f5b_LsQc!o8PKVJAx{Ikd|qxXl?npLI5hr;=VNj#A*v~y>Sifgk&srbV;RI>7IHn zGSxMZ&&extsV(gIlFYK#_2F= zYNozn-Qezl8m{;)JKQYBX)PnZ7N#M{w9Kc$he|Y|9|@TyRLG;HE{ARZ+=V&o`Zl8bN~PV literal 0 HcmV?d00001 diff --git a/cargo-cult.html b/cargo-cult.html index ff8a2c9..a172951 100644 --- a/cargo-cult.html +++ b/cargo-cult.html @@ -62,6 +62,10 @@ font-style: italic; font-weight: bold; } + + .semi-opaque { + background-color: rgba(0, 0, 0, 0.7); + } diff --git a/rust-legal.html b/rust-legal.html new file mode 100644 index 0000000..55054e4 --- /dev/null +++ b/rust-legal.html @@ -0,0 +1,365 @@ + + + + + + Rust + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

O Que Rust Tem de Legal

+
+
+ +
+
+

Borrow Checker

+
+ +
+

+a = 2
+						
+
+ +
+ "Variável a tem o valor 2" +
+ +
+
+ "Posição de memória apontada por a tem o valor 2" +
+ +
+

+0x3f5cbf89 = 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
+						
+
+ +
+ Swift 5 Exclusivity Enforcement +
+
+ +
+
+

Imutabilidade por Default

+
+ +
+

+fn main() {
+    let a = 2;
+    a = 3;
+    println!("{}", a);
+}
+						
+
+ +
+

+3 |     let a = 2;
+  |         -
+  |         |
+  |         first assignment to `a`
+  |         help: make this binding mutable: `mut a`
+4 |     a = 3;
+  |     ^^^^^ cannot assign twice to immutable variable
+						
+
+ +
+

+fn main() {
+    let mut a = 2;
+    a = 3;
+    println!("{}", a);
+}
+						
+
+
+ +
+
+

Enums

+
+ +
+

+enum IpAddr {
+   V4,
+   V6
+}
+						
+
+ +
+

+enum IpAddr {
+    V4(String),
+    V6(String),
+}
+						
+
+ +
+

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

+enum Option<T> {
+    Some(T),
+    None
+}
+						
+
+
+ +
+
+

Error Control

+
+ +
+

+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(())
+                        
+
+
+ +
+
+
+
+ + + + + + + +