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
240604_FreeFn_VS_AssociatedFn
link
Free Functions vs. Associated Functions (Methods)
| Feature | Free Function | Associated Function (Method) |
|---|---|---|
| Definition | Defined at the module level, not within an impl block. | Defined within an impl block for a struct or a trait. |
| Calling Syntax | function_name(args) or module::function_name(args). | instance.method_name(args) or Struct::method_name(args) (if it doesn’t take &self, &mut self, or self). |
self Parameter | Does not take &self, &mut self, or self as a parameter. | Takes &self, &mut self, or self to operate on an instance of the struct. |
| Use Case | Often used for static utility functions, operations where no single data “owner” is clear, or generic functions. | Used when the function’s logic is tightly coupled to a specific data structure. |
같이 보면 좋은 글
240604_FreeFn_VS_AssociatedFn
https://younghakim7.github.io/blog/posts/240604_freefn_vs_associatedfn/