Hacker Public Radio

HPR3426: Rust 101: Episode 0 - What in Tarnishing?


Listen Later

Talking Points
What is Rust?
" Garbage Collection " - Resource Acquisition Is Initialization (RAII)
Strict Typing with Type Inference
Reference pointers
Immutable by default
Unsafe Mode
Why use Rust over Python?
Speed
Compiled
Help from compiler
Smaller binary size
Useful in high throughput/embedded applications
Logically consistent
Why use Rust over C?
Safe by default
Easier to read
Forces you to write good code
Arrays without stupidity++ and built in vectors
Option<T> and Result<T> or a match {} made in heaven
Show Notes
Strict Typing
fn main() {
// Type declared with var: <T> syntax
let penguin_one: &str = "gentoo";
// Type &str is inherited from "gentoo"
let penguin_two = "gentoo";
// Will not panic if they are the same
assert_eq!(penguin_one, penguin_two);
}
Reference Pointers
Wrong Way:
fn print_u8_vector(vec: Vec<u8>) {
println!("{:?}", vec);
}
fn main() {
let penguin_ages: Vec<u8> = vec!(2, 4, 6);
print_u8_vector(penguin_ages);
// This line will throw an error
println!("{}", penguin_ages[0]);
}
Correct Way:
fn print_u8_vector(vec: &Vec<u8>) {
println!("{:?}", vec);
}
fn main() {
let penguin_ages: Vec<u8> = vec!(2, 4, 6);
print_u8_vector(&penguin_ages);
// This line will print '2'
println!("{}", penguin_ages[0]);
}
Immutable By Default
Wrong Way:
fn main() {
let my_num = 2;
// This line will throw an error
my_num = my_num + 1;
println!("{}", my_num);
}
Correct Way:
fn main() {
let mut my_num = 2;
my_num = my_num + 1;
// This line will print '3'
println!("{}", my_num);
}
Unsafe Code
Hello World Program in C in Rust:
extern "C" {
fn printf(input: &str);
}
fn main() {
unsafe {
printf("Hello, World!");
}
}
Important Links:
Rust Programming Language Homepage
Rust Playground
Ben Eater: Comparing C to machine language <WARNING: YouTube Hosted>
Wikipedia Pages:
Rust Programming Language Wikipedia article
Resource Acquisition Is Initialization (RAII)
Contact Me
Email: izzyleibowitz at pm dot me
Mastodon: at blackernel at nixnet dot social
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

290 Listeners

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec by Jerry Bell and Andrew Kalat

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec

372 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

268 Listeners

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast) by Johannes B. Ullrich

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast)

651 Listeners

Curious Cases by BBC Radio 4

Curious Cases

822 Listeners

The Strong Towns Podcast by Strong Towns

The Strong Towns Podcast

423 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

164 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,061 Listeners

Cybersecurity Today by Jim Love

Cybersecurity Today

179 Listeners

CISO Series Podcast by David Spark, Mike Johnson, and Andy Ellis

CISO Series Podcast

189 Listeners

TechCrunch Daily Crunch by TechCrunch

TechCrunch Daily Crunch

42 Listeners

Strict Scrutiny by Crooked Media

Strict Scrutiny

5,797 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

98 Listeners

Cyber Security Headlines by CISO Series

Cyber Security Headlines

139 Listeners

What the Hack? by DeleteMe

What the Hack?

228 Listeners