Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE4102/5102 Team Project Rust Programming Language

Similar presentations


Presentation on theme: "CSE4102/5102 Team Project Rust Programming Language"— Presentation transcript:

1 CSE4102/5102 Team Project Rust Programming Language
Andrew Armstrong Peter Zaffetti

2 What is Rust? Rust is a systems programming language that is sponsored by Mozilla The purpose of its design is to allow for control of low-level details such as memory usage without the difficulties that are typically associated with this, concurrency, and speed It is an open source language allowing for the community to help develop and expand the language. It has its own compiler called rustc that is written in Rust that has a special focus on memory safety and not allowing code to compile if there any possible errors found

3 How did Rust get started?
Rust was originally started as a side project in 2006 by Graydon Hoare, an employee at Mozilla The language was worked on for 3 years until 2009 when Mozilla began to sponsor the project The compiler was able to successfully compile itself in 2011 after it was switched from being written in Ocaml to Rust itself January of 2012 saw the first pre-alpha release of Rust with the first stable release of the language occurring 3 years later in May of 2015 Every 6 weeks a new release of Rust is published

4 Biography – Graydon Hoare
Started working on Rust in 2006 as his own personal project In 2009 he showed the language to his manager at Mozilla which resulted in the company sponsoring the project. Worked as the lead developer for Rust until 2013 he moved on to a less demanding project at Mozilla In 2014 he quit working at Mozilla and started working at Stellar for a year and a half Most recently got hired by Apple in 2016 to help work on Swift

5 Biography – Brian Anderson
Graduated the University of Cincinnati in 2005 with a BS in Computer Science Worked at Clifton Labs as a Software Engineer from 2005 to Helped develop a application to visually simulate spinal surgical procedures. Worked at Cintas from 2008 to May 2011 as a mobile device programmer using C# and C++ Worked at Mozilla as a Senior Research Engineer from 2001 to Helped lead the Rust project when it was first started before becoming the lead engineer when Graydon Hoare stepped down in 2013

6 The Current Rust Team The current Rust team is split up into multiple groups, each one focusing on one aspect of the language The list of different teams is the core team, the language team, the language team shepherds, the library team, the compiler team, the dev tools team, the dev tools peers, the cargo team, the infrastructure team, the release team, the community team, the documentation team, the documentation peers, the moderation team, and the style team. Between these 15 teams there are a total of over 100 Mozilla employees working on Rust In addition to the employees at Mozilla over 2,000 community members have contributed to the language in some way

7 Achievements Since 2016 Rust has won first place for “most loved programming language” in Stack Overflow’s Developer Survey and won third place in 2015 It is the language being used to develop Servo, a web browser layout engine currently being developed by Mozilla. It is currently being used to power Dropbox’s file system that powers their Diskotech petabyte storage machines. Rust has also been used to create video game engines, virtual reality engines, block chain applications and has even been involved in creation of an open source distributed ledger for cryptocurrency

8 Motivation for development
The three main goals for developing Rust were safety, control of low-level details such as memory layout, and concurrency Rustc was created with the intention to catch subtle bugs that can usually only be found through extensive testing and thorough code review in other languages Low-level details such as memory management, memory safety, and concurrency are either automated by the language or implemented in such a way that they prevent most of the difficulties being put on the coder Due to the ownership model and type system implemented in Rust most concurrency problems are not runtime errors but compile time errors. This allows Rustc to find the errors and suggest what fix should be used

9 Programming Paradigms
Rust is built to follow functional, concurrent, and imperative-procedural programming paradigms Functional programming treats computation as evaluation of mathematical functions and attempts to avoid changing states or mutating data Concurrent programming allows for multiple computations to be executed at the same time instead of sequentially Imperative-procedural programming uses statements to change a programs state

10 Programming Paradigms – Functional Programming
Rust uses Functional Programming which can be seen in the way that default variables are handled and how expressions are used By default all variables in Rust are immutable Variables can be declared immutable by the use of the mut keyword By making variables immutable by default Rust seeks to ensure that any values that are being set do not get changed unless the coder specifically says otherwise All function bodies are filled with either statements or expressions Expressions in Rust evaluate to a resulting value and return the value by default

11 Programming Paradigms – Concurrency
One of the main design decisions of Rust was to make sure that it could provide a high level of concurrency Rust is able to create multiple threads at once in order to let multiple pieces of code to be run at the same time Rust contains Message passing concurrency which allows channels to send messages from one thread to another Shared state concurrency is implemented allowing for multiple threads to have access to the same piece of data Rust provides concurrency traits that can be extended to user-defined types in order to ensure that they are able to interact properly with elements from the standard library

12 Programming Paradigms – Imperative Procedural
Rust allows for functions to be created and handles passing parameters in and out Functions, as well as structures and enumerations, can be moved into modules to help organize code Each module can decide which functions and data it contains should be visible outside the module, or limited to use inside of it.

13 Programming Paradigms – Imperative Procedural
Rust allows for functions to be created and handles passing parameters in and out Functions, as well as structures and enumerations, can be moved into modules to help organize code Each module can decide which functions and data it contains should be visible outside the module, or limited to use inside of it.

14 Programming Paradigms – Imperative Procedural
Rust allows for functions to be created and handles passing parameters in and out Functions, as well as structures and enumerations, can be moved into modules to help organize code Each module can decide which functions and data it contains should be visible outside the module, or limited to use inside of it.

15 Rust IDE Doesn’t have have a single official IDE from Mozilla
Supported by a number of popular IDEs Visual Studio + Visual Studio Code Intellij IDEA Eclispe Sublime Text Vim Emacs Atom

16 Supported Platforms Three tiers of supported platforms
Tier 1 – “guaranteed to work” Official releases Automated tests Full documentation Tier 2 – “guaranteed to build” Automated building but no automated testing Documentation not necessarily available Tier 3 – “might work” Rust codebase has support for but platforms are not built or tested automatically No official release

17 Supported Platforms Cont.
Tier 1 platforms 32-bit / 64-bit OSX 32-bit / 64-bit Window 7+ 32-bit / 64-bit Linux Tier 2 platforms ARMv6, ARMv7, ARM64 iOS Android Solaris FreeBSD Tier 3 platforms Bare Cortex (M0, M3, M4, M7) Windows XP Microcontrollers + Nvidia GPUs

18 Rust Compiler Originally compiled with OCaml compiler
Rust now compiles itself Stage 0- obtain current rustc beta compiler Stage 1- feed rustc code to the Stage 0 compiler Stage 2- feed the rustc code to the Stage 1 compiler Rust compiler releases must be Stage 2 compiled Alternative compilers were created by the community to remove LLVM framework C++ : mrustc Produces identical code to the Stage 0 compiler Rest of process is the same Stage 3 – produces identical binary as above

19 Rust Typing Rust is statically typed
Compiler catches almost all errors Little to no runtime errors assuming that there is no “unsafe” code Implicitly typed Includes type inference and shadowing Types can be coerced (type annotations)

20 Rust Array, Tuples, Structs, and Enums
Arrays are collections of all the same type Tuples are a collections of different types but values don’t have names Structs resemble structures in C Contain a collection of name value pairs Enums contain a complete enumeration of some type Enum values can be initialized with values similar to how Java enums can have constructors Prevents having to create a struct with an enum and a value component to link the two

21 Rust Generics and Traits
Generics are similar to Java’s generics Generic types are specified and used throughout functions, enums, structs, and methods No runtime performance hit for using generics Monomorphization occurs at compile time Generic types are replaced and filled in with concrete types Traits are similar to Java interfaces Traits define functions that can be called directly on the type that has the trait assigned to it Types with traits need to implement behavior for the given functions in the trait

22 Rust Generics and Traits Cont.
Traits can provide default behavior Specifies what will happen if no implementation is given for the trait function Traits can be used to specified subsets of various types Blacklists any type that doesn’t implement the desired trait functions Gives runtime assumptions so that the functions can be safely called Traits from other packages can be implemented on your types

23 Rust Ownership Rust manages memory through ownership, not garbage collection 3 Rules of Ownership 1. “Each value in Rust has a variable that’s called its owner.” 2. “There can only be one owner at a time.” 3. “When the owner goes out of scope, the value will be dropped.” A variables goes out of scope if it is reassigned Shadow copy of the variable is created Rust provides deep copy functionality with clone

24 Rust Ownership Cont. References allow you to refer to a value without taking ownership of it References are immutable by default Can have as many immutable references as desired Can only have ONE mutable reference Prevents data races References allow borrowing ownership so variables can be used across function calls Compiler “will ensure that the data will not go out of scope before the reference to the data does” Can’t return a reference from a function because the reference goes out of scope when the function ends

25 Rust Smart Pointers Idea is borrowed from C++
Smart pointers allow for multiple owners of the data Data are cleaned up when there are no more owners Smart pointers OWN the data they point to Often resembled as structs Different from structs since smart pointers implement “Deref” and “Drop” traits Deref allows “*” dereferencing of the pointer Drop runs when the variable is about to go out of scope (dereference) Smart pointers don’t guarantee no memory leaks exist Reference cycles can still exist despite Rusts’ compile time checks

26 Object Oriented Rust Provides lightweight class functionality using structs and enums Traits are equivalent to the class methods Structs and enums encapsulate the raw data they contain and the methods they implement Rust does not have inheritance Pub is used as a module modifier Allows certain functions to be publically facing Private functions are encapsulated within the module itself Trait objects allows for polymorphism Trait objects point to instances of a type that implement the trait specified (Box<Draw>)

27 Rust Modules Modules are “namespaces that contain definitions of functions and types” Default functions are private Visible within the module only Functions can be made public to expose to other program and modules Modules can be nested with other modules Cargo is a tool packaged with the Rust install that allows other modules to be used Cargo pulls in crates Crates contain modules

28 Rust Concurrency Ownership system allows for many concurrency error to be caught at compile time rather than runtime Rust support spawning threads Message passing is used to communicate between threads Threads talk by sending each other messages with data over “channels” Channels promote a single ownership model Channels contain a transmitter and receiver Transmitter places messages on the channel Receiver takes messages off of the channel Rust supports shared memory concurrency Mutexes allow multiple ownership of the same shared data

29 Rust Common Collections
Common collections are data types that aren’t known at compile time Collections live on the heap Can grow and shrink Rust’s standard library contain 3 common collections; Vector, String, and Hash Map Vectors are similar to array lists Vectors can only store values of the same type Strings are collections of characters Hash Maps are a key value association

30 Programming Paradigms – Imperative Procedural
Rust allows for functions to be created and handles passing parameters in and out Functions, as well as structures and enumerations, can be moved into modules to help organize code Each module can decide which functions and data it contains should be visible outside the module, or limited to use inside of it.


Download ppt "CSE4102/5102 Team Project Rust Programming Language"

Similar presentations


Ads by Google