Categories
Tags
3d algorithms alignment analyze APIT Arc Architecture arm ascii assembly asynchronous base64 BitHacks Blogging box c c23 clang clang-format client clippy cmake compiler Computer concat concurrency const_fn constexpr contravariant cos covariant cpp cpu crate CS Customization cybersecurity DataStructure db debugging Demo deserialization discrete doc DP drawio dtruss Dynamic emulator example Example FFI flamegraph flat_map fold format FP fsanitize Functional FunctionalProgramming functions futures Fuwari game GATs gcc gccrs generics gitignore glibc GUI hacking hashmap haskell heap hyperfine Imperative interop invariant iterator join justfile kernel LaTeX leak LFU linux lto MachineLearning macOS map Markdown math ML mmap mod nc OnceLock optimization OS ownership panic parallels perf physics pin postgresql product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift sin size SmallProjects socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous tan thread time toml tracing traits triangulation uint32_t UnsafeRust utf16 utf8 Video vulkan 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/