Categories
Tags
algorithms APIT Arc arm assembly asynchronous base64 BitHacks Blogging box c clang-format client cmake compiler concat concurrency const_fn contravariant cos covariant cpp Customization cybersecurity DataStructure db debugging Demo deserialization discrete doc DP dtruss Dynamic Example FFI flat_map format FP fsanitize Functional functions futures Fuwari GATs gccrs generics gitignore glibc GUI hacking hashmap haskell heap interop invariant iterator join justfile kernel LaTeX leak LFU linux lto MachineLearning macOS Markdown math ML mmap nc OnceLock optimization OS panic parallels perf physics pin postgresql radare2 release reverse RPIT rust sanitizer science Science serialization server shift sin SmallProjects socket std strace String StringView strip strlen surrealdb SWAR swisstable synchronous tan toml traits triangulation UnsafeRust utf16 utf8 Video wsl x86_64 xilem zig
461 words
2 minutes
250102_default
link
default기본 사용법|🔝|
#[derive(Default, Debug)]
struct 피자가게Config {
치즈를_원함: bool,
올리브_no: i32,
특별한_메세지: String,
크러스트_type: CrustType,
}
#[derive(Debug)]
enum CrustType {
두껍게,
중간,
얇게,
}
impl Default for CrustType {
fn default() -> CrustType {
CrustType::얇게
}
}
fn main() {
let my_default_no: i64 = Default::default();
println!("i64 default 하면 : {my_default_no}");
let 피자: 피자가게Config = Default::default();
println!("내가 원하는 피자(치즈를 원함??) : {}", 피자.치즈를_원함);
println!("내가 원하는 피자(올리브 갯수) : {}", 피자.올리브_no);
println!("내가 원하는 피자(특별한 메세지) : {}", 피자.특별한_메세지);
println!("내가 원하는 피자(크러스트 type) : {:?}", 피자.크러스트_type);
let 나만의_피자 = 피자가게Config {
치즈를_원함: true,
올리브_no: 20,
특별한_메세지: "무조건 많이~~~".to_string(),
크러스트_type: CrustType::두껍게,
};
println!("~~~~\n다르게 해 보자~~\n");
println!("나의 피자 스타일 : {:#?}", 나만의_피자);
let 피자주문_002 = 피자가게Config {
치즈를_원함: true,
올리브_no: 20,
..Default::default()
};
println!("~~~~\n다르게 해 보자~~\n");
println!("다른 주문 귀찮은거 처리: {:#?}", 피자주문_002);
}- result
i64 default 하면 : 0
내가 원하는 피자(치즈를 원함??) : false
내가 원하는 피자(올리브 갯수) : 0
내가 원하는 피자(특별한 메세지) :
내가 원하는 피자(크러스트 type) : 얇게
~~~~
다르게 해 보자~~
나의 피자 스타일 : 피자가게Config {
치즈를_원함: true,
올리브_no: 20,
특별한_메세지: "무조건 많이~~~",
크러스트_type: 두껍게,
}
~~~~
다르게 해 보자~~
다른 주문 귀찮은거 처리: 피자가게Config {
치즈를_원함: true,
올리브_no: 20,
특별한_메세지: "",
크러스트_type: 얇게,
}같이 보면 좋은 글|🔝|
250102_default
https://younghakim7.github.io/blog/posts/250102_default/