Difference between r1.2 and the current
@@ -52,3 +52,33 @@
println!("Hello, {}", language);
}
```
}
```
```
fn main() {
println!("Factorial: {}", factorial(5));
}
fn factorial(i: u64) -> u64 {
let mut acc = 1;
for num in 2..i+1 {
acc *= num;
}
acc
}
```
= Rust =
* statement & expression
* statement : no return value
* let statement
* expression : evaluate to a resulting value
* operation
* calling a function
* calling a macro
* block
== ownership(소유권) ==
* enables memory safety guarantees without a garbage collector.
=== Ownership Rules ===
* Each value in Rust has a variable that's called its owner.
* There can only be one owner at a time.
* When the owner goes out of scope, the value will be dropped. -> lifetime
* At any given time, you can have either one mutable reference or any number of immutable references.
* References must always be valid.
.rs ¶
feature ¶
- zero-cost abstractions
- move semantics
- guaranteed memory safety
- threads without data races
- trait-based generics
- pattern matching
Fast ¶
- LLVM
- Compile to binary
- no GC
- minimal runtime
Prevent segfaults ¶
- No dangling pointer
- No null pointer
- No segfault
thread safety ¶
- No data race
- Ownership guarantee
- Ownership guarantee
- hard to compile
Cargo ¶
- The Rust package manager
- downloads dependencies
- downloads dependencies
Rustup ¶
- Rust toolchain installer
- stable
- beta
- nightly
- stable
playground ¶
Hello, rust ¶
`fn main(){
println!("Hello World");
}
`
`fn main() {
let language = "rust";
println!("Hello, {}", language);
}println!("Hello, {}", language);
`
`fn main() {
println!("Factorial: {}", factorial(5));
}fn factorial(i: u64) -> u64 {
let mut acc = 1;
for num in 2..i+1 {
acc
}for num in 2..i+1 {
acc *= num;
}acc
`Rust ¶
- statement & expression
- statement : no return value
- let statement
- let statement
- expression : evaluate to a resulting value
- operation
- calling a function
- calling a macro
- block
- operation
- statement : no return value
ownership(소유권) ¶
- enables memory safety guarantees without a garbage collector.
Ownership Rules ¶
- Each value in Rust has a variable that's called its owner.
- There can only be one owner at a time.
- When the owner goes out of scope, the value will be dropped. -> lifetime
- At any given time, you can have either one mutable reference or any number of immutable references.
- References must always be valid.