Skip to content

Instantly share code, notes, and snippets.

View Shaun289's full-sized avatar

Sunjong Park Shaun289

View GitHub Profile
@Shaun289
Shaun289 / methods.rs
Created November 8, 2021 04:40
Rust study : methods
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/fn/methods.html
compiled on https://play.rust-lang.org/
result :
*/
#[derive(Debug)]
struct Point {
x: f64,
y: f64,
@Shaun289
Shaun289 / while_let.rs
Created November 8, 2021 04:17
Rust study : while let
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/flow_control/while_let.html
compiled on https://play.rust-lang.org/
result :
optional is Some(0)
optional is Some(1)
optional is Some(2)
optional is Some(3)
optional is Some(4)
optional is Some(5)
@Shaun289
Shaun289 / if_let.rs
Created November 8, 2021 00:39
Rust study : if let
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/flow_control/if_let.html
compiled on https://play.rust-lang.org/
result :
Matched 7!
Not matched : letter
emoticon is None!
*/
fn main()
@Shaun289
Shaun289 / match_guard.rs
Created November 4, 2021 10:44
Rust study : match guards
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/flow_control/match/guard.html
compiled on https://play.rust-lang.org/
result :
Antimatter! 2 and -2
x:2 == y
The first ons is odd
No correlation...
*/
@Shaun289
Shaun289 / destruct_struct.rs
Created November 4, 2021 10:34
Rust study : destruct structure
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/flow_control/match/destructuring/destructure_structures.html
compiled on https://play.rust-lang.org/
result :
a = 1, b = 2, y = 3
x = (1, 2), y = 3
i = 3, j = (1, 2)
y = 3
*/
@Shaun289
Shaun289 / match_reference.rs
Created November 4, 2021 04:31
Rust study : match pointer/reference
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/flow_control/match/destructuring/destructure_pointers.html
compiled on https://play.rust-lang.org/
result :
Got a value via destructuring 4
Got a value via dereferencing 4
Got a reference to a value 5
We added 10. `mut_value`: 16
mut_value after match : 16
*/
@Shaun289
Shaun289 / match_enum.rs
Created November 4, 2021 04:22
Rust study : match enum
/*
The rust by example ko httpshttps://hanbum.gitbooks.io/rustbyexample/content/flow_control/match/destructuring/destructure_enum.html
compiled on https://play.rust-lang.org/
result :
This color is Red
This color is Blue
This color is Green
R:255 G:255 B:255
C:128 M:128 Y:128 K:128
*/
@Shaun289
Shaun289 / match_pair.rs
Created November 3, 2021 10:55
Rust study : tuples and match
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/flow_control/match/destructuring/destructure_tuple.html
compiled on https://play.rust-lang.org/
result :
Tell me about (0, -2)
First is 0 and y is -2
Tell me about (2, 0)
x is 2 and last is 0
Tell me about (1, 1)
It doesn't matter what they are
@Shaun289
Shaun289 / alias.rs
Created November 3, 2021 00:32
Rust study : alias
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/cast/alias.html
compiled on https://play.rust-lang.org/
result :
5 nanoseconds + 2 inches = 7 unit?
*/
// NanoSecond는 u64의 새로운 이름. 반드시 CamelCase로 이름을 지어야함.
type NanoSecond = u64;
type Inch = u64;
@Shaun289
Shaun289 / literals.rs
Created November 3, 2021 00:26
Rust study : literals
/*
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/cast/literals.html
compiled on https://play.rust-lang.org/
result :
size of x in bytes: 1
size of x in bytes: 4
size of x in bytes: 4
size of x in bytes: 4
size of x in bytes: 8
*/