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