https://github.com/tralahm/rust_example
A case for Oxidation with Rust-Lang...and the Future of Serverless with WEB Assembly WASM... A primer in rust programming and systems programming
https://github.com/tralahm/rust_example
cargo cargo-plugin crates getting-started rust-lang rust-library tralahm tralahtek wasm webassembly
Last synced: 4 months ago
JSON representation
A case for Oxidation with Rust-Lang...and the Future of Serverless with WEB Assembly WASM... A primer in rust programming and systems programming
- Host: GitHub
- URL: https://github.com/tralahm/rust_example
- Owner: TralahM
- Created: 2020-01-22T22:00:11.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-26T20:52:12.000Z (over 5 years ago)
- Last Synced: 2025-01-13T08:45:28.417Z (9 months ago)
- Topics: cargo, cargo-plugin, crates, getting-started, rust-lang, rust-library, tralahm, tralahtek, wasm, webassembly
- Language: Rust
- Homepage:
- Size: 556 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
Introduction to Rust Programming
====================================
- Created by Mozilla Devs
- Good for chat clients,games,servers
- System Programming Candidate
- Designed for easy simple multithreading to address common issues faced by programmers
- C/C++ family code blocks delimited with {}.
- Strict types language
- LLVM Based- Comparable to **CYCLONE** a programming language without a garbage collector
- High Level Abstraction
- Build System
- Data Race Free (!?)
Contents
----------
:ref: `A case for Oxidation `:ref: ``
:ref: ``
:ref: ``
:ref: ``
:ref: `See Screenshots `
A Case for Oxidation (Rust)
----------------------------.. _Memory Safety:
Memory Safety
**************Dereferences always succeed, always points to values of a correct type
if r:&Foo then * r is always equal to Foo
- No dangling pointers- No access after memory free
- Forced Initialization+ Restricted aliasing+ Ownership = memory safety
All at *compile-time*
Aliasing Is hard! avoid **segmentation faults** like in C/C++
So we restrict aliasing so only 1 mutable alias or N immutable aliasesBorrowing
^^^^^^^^^^^.. code:: rust
let x=Person("Tralah");
let y=&x;
let z=&x;
//let z=x; would fail as x is already borrowed
/* Ownership
*let x=32;
*let y=x;
*let z=x;fails as x already belongs to y
*/Concurrency
^^^^^^^^^^^^^
Not supported natively by the language because of the safe mem feature of Rust
Only Provided by Third Party Libraries which do this by using a concept of unsafe nemory
or unsafe rust.- Minimal Runtime
- StrongType System
- Performance
Why Should we Care?
---------------------
We want secure systems
We want the right tools
C/C++ is old and ill designed, have to write Makefiles and toolchains
Prevents us from doing the wrong things
Good for writing System Software
Guaranteed SecurityGuarantees
-------------
Memory safety without garbage collection
No data races.. _Getting started with Rust:
Getting started with Rust
******************************- Data types are immutable by default
- WASM webassembly- **cargo** package manager for Rust
.. code:: bash
# The Rust Compiler
rustc --version
# The Package Manager|Build Tool
cargo --versionFunctions and Macros
--------------------
.. code:: rust// C like Comments
/*Multiple
* Line
Comments*/
fn main(){
println!("Text");
add(21,34);
}
fn add(x: &int,y: &int){
println!("{} + {} = {}",x,y,x+y);
}.. _Projects:
Projects
***********.. code:: bash
cargo new project_name
cd project_name
ls
#Cargo.toml, src,
cargo run build
# OR
cargo runVariables,Types and Such
-------------------------
.. code:: rustlet x=32;//immutable
let mut y=32;//mutable
println!("x= {} \n y={}",x,y);//macros
//x=43; causes error as x is immutable
y=231;//is ok as y is mutable* Integers 1
* Floats 2.3
* Booleans true || false
* Strings[Characters]Basic Types, Loops
--------------------------
.. code:: rustlet dyn_math= 8*8-2+221;
const NAME:str="Tralah M Brian";
const ID: i32 =001;
println!("{}",NAME);
println!("{}",ID);pritnln!("Dynamic math {}",dyn_math);
let my_array=[1,2,3,4,5,6,7];
let my_tuple=(,42,34.3,"tralah");
let (dyn_x,dyn_y,dyn_z)=my_tuple;//tuple unpacking as python
// Array Indexing
println!("{}",my_array[3]);// Array Looping
for i in my_array.iter(){
println!("{}",i);
}.. _Crates:
Crates
*******
``_
Third Party Libraries for- Games
- Math
- Networks
- Graphics [ OpenGL ]
.. _Rocket:
Rocket
*******Web Framework written is rust makes it secure by avoiding
- XSS,
- Directory Travesals,
.. code:: rust
#[get("/")]
fn retrieve(user: User,pid: PastebinId){
File::f=12;
}- Remote Code Exec
- Sql Injection
- Authentication
- Authorization
- CORS
- Mosconfiguration
- Input Validation
.. _Screenshots:
Screenshots
***********.. image:: helloworld.png