코딩Coding/Rust연습
-
-
Rust연습]Easy Rust 024: Control flow 1(match+if)코딩Coding/Rust연습 2021. 12. 12. 20:56
// CONTROL FLOW fn main() { let children = 5; let married = true; match (children, married) { (children, married) if married == false => { println!("Not married with {} children", children) } (children, married) if children == 0 && married == true => { println!("Married but no children") } _ => println!("Married? {}. Number of children: {}", married, children), } } 출처 : https://www.youtube.com/w..
-
[Rust연습]Easy Rust 024: Control flow 1(if, else if, else)코딩Coding/Rust연습 2021. 12. 12. 20:25
// CONTROL FLOW fn main() { let my_number = 17; if my_number == 7 { println!("It's seven"); } else if my_number == 6 { println!("It's six") } else { println!("It's something else"); } } 출처 : https://www.youtube.com/watch?v=UAymDOpv_us&list=PLfllocyHVgsRwLkTAhG0E-2QxCf-ozBkk&index=25
-
RUST연습]Easy Rust 022: Vecs코딩Coding/Rust연습 2021. 12. 12. 18:12
// Vecs fn main() { let vec_of_ten = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // Everthing is the same as above except we added vec!. let three_to_five = &vec_of_ten[2..5]; let start_at_two = &vec_of_ten[1..]; let end_at_five = &vec_of_ten[..5]; let everything = &vec_of_ten[..]; println!( " Three to five: {:?},\n start at two: {:?},\n end at five: {:?},\n everything: {:?}", three_to_five, start_at_t..
-
RUST연습]변수 사이즈크기 알아보기(use std::mem::size_of;)코딩Coding/Rust연습 2021. 12. 10. 22:04
use std::mem::size_of; fn main() { println!("Size of a char: {}", size_of::()); // 4 bytes println!("Size of string containing 'a': {}", "a".len()); // .len() gives the size of the string in bytes println!("Size of string containing 'ß': {}", "ß".len()); println!("Size of string containing '国': {}", "国".len()); println!("Size of string containing '𓅱': {}", "𓅱".len()); } 출처 : https://dhghomon.git..
-
Rust연습]Shadowing코딩Coding/Rust연습 2021. 12. 9. 23:29
// mutability // shadowing 같은 이름을 다시 쓰는 것 fn main() { let my_variable = 9; println!("{}", my_variable); { let my_variable = "Some string"; println!("{}", my_variable); } println!("{}", my_variable); } 출처 : https://www.youtube.com/watch?v=uHuMJw73ukg&list=TLPQMDkxMjIwMjHuFJxHs478XA&index=2
-
RUST연습]Rust Crash Course | Rustlang -44:47부터코딩Coding/Rust연습 2021. 12. 7. 21:42
main.rs // mod print; // mod vars; // mod types; mod strings; fn main() { // print::run(); // vars::run(); // types::run(); strings::run(); } strings.rs // Primitive str = Immutable fixed-length string somewhere in memory // String = Growable, heap-allocated data structure - Use when you need modify or own string data pub fn run() { let mut hello = String::from("Hello "); //Get length println!("..
-
Rust☆]Understanding ☆Ownership☆ in Rust&☆The Rules of References☆코딩Coding/Rust연습 2021. 12. 6. 01:24
Ownership rules 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. Ownership rules 1. Rust의 각 값에는 소유자라는 변수가 있습니다. 2. 한 번에 한 명의 소유자만 있을 수 있습니다. 3. 소유자가 범위(scope)를 벗어나면 값이 떨어집니다.(dropped) The Rules of References 1. At any given time, you can have either one mutable reference or any ..