Categories
Tags
3d ABI Actions algorithms alignment analyze APIT Arc Architecture arm array ascii ash assembly asynchronous attribute base64 bithacks Blogging box c c23 cdylib CHAR_BIT clamp 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 dll doc DP drawio dtruss dylib Dynamic emulator example Example FFI ffmpeg 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 inference intel interop invariant iterator join justfile kernel LaTeX leak LFU limits linux lto MachineLearning macOS map Markdown math ML mmap mod mp3 nc nextest OnceLock optimization OS ownership panic parallels perf physics pin postgresql procedure product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift SIMD sin size SmallProjects so socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous syscall tan test thread time toml tracing traits trap triangulation type uint32_t UnsafeRust utf16 utf8 vector Video vulkan wsl x86_64 xilem zig
109 words
1 minutes
260107_traits03_debug_display
Debug 구현하기
- derive macro를 써서 손 쉽게 구현
#[derive(Debug)]
struct Young {
data: String,
}
fn main() {
let my_str = Young {
data: "test".to_string(),
};
println!("Debug {:?}", my_str);
} - 복잡한 타입일수록 내가 구현해줘야한다.
use std::fmt;
struct Young {
data: String,
}
impl fmt::Debug for Young {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.data)
}
}
fn main() {
let my_str = Young {
data: "test".to_string(),
};
println!("Debug {:?}", my_str);
}Debug과 Display 구현은 똑같다.
{:?}Debug{}Display
260107_traits03_debug_display
https://younghakim7.github.io/blog/posts/260107_traits03_debug_display/