Rust

 

A language empowering everyone to build reliable and efficient software.

Why?

Certain areas need 

Speed + Control

Eg.

Browsers

Games

Interpreters

Operating Systems

Trading systems 👀

 

C/C++'s offering

Direct Memory Access

 

Zero Cost Abstrations

No Garbage Collection

Compiled

Where it falls short

Manual Memory Management

Segfaults ( Runtime errors )

Fundamental Language Tradeoffs

Data Races

Control,

Performance

Safety

C

C++

Java

Go

Haskell

Rust

C/C++

More control,

less safety

Python, Ruby etc

Less control

More safety

Java

 

Rust

More control, MOAR Safety

Rust

  • Modern C/C++ replacement
  • Memory Safety without Garbage Collection
  • No runtime
  • Rich Typesystem
  • Strong functional programming influence

Fast

Compiles to binery

LLVMs suite of optimizations

Competitive with C/C++

Goodbye Crashes

Safe by default

Sophisticated type system and analysis

No segfaults/null pointers/dangling pointers

Goodbye Data Races

Ownership guarantees

Borrowing prevents dangling pointers

Strong Safe Abstrations

Ownership

Garbage Collection

class Circle(object):
    def __init__(self,radius):
        self.radius = radius

    def area(self):
        return 3.14 * self.radius * self.radius

Garbage Collection

def calc_circle(circle_count, radius):
    area = 0
    for i in circle_count:
        circle = Circle(radius)
        area += circle.area()
    return area

>>> calc_circle(3, 5)
Heap Memory
Circle(5)
Circle(5)
Circle(5)

Eventually GC clears it up

int main() {
    int *slot = malloc(sizeof(int));
    *slot = 3;
    helper(slot);
    helper(slot); // use after free!
}

void helper(int *slot) {
    printf("The number was: %d\n", *slot);
    free(slot);
}

a.out(62940,0x7fff7b9ea310) malloc: *** error for object 0x7fecb0c03b10:
pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
zsh: abort      ./a.out
int main(void)
{
     char *s = "hello world";
     *s = 'H';
}

fn main() {
    let s = &"hello world";
    *s = "H";
}

segfault.rs:3:4: 3:6 error: type &str cannot be dereferenced
segfault.rs:3     *s = "H";
                  ^~
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', ...
Made with Slides.com