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
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/