Categories
Tags
algorithms APIT arm assembly asynchronous base64 Blogging box c clang-format cmake compiler concurrency const_fn contravariant cos covariant cpp Customization cybersecurity DataStructure db Demo deserialization discrete doc DP Dynamic Example FFI flat_map FP Functional functions futures Fuwari GATs gccrs generics gitignore GUI hacking hashmap haskell heap interop invariant iterator justfile kernel LaTeX LFU linux MachineLearning Markdown math ML OnceLock optimization OS parallels perf physics pin postgresql release RPIT rust science Science serialization shift sin SmallProjects std String surrealdb swisstable synchronous tan traits triangulation utf16 utf8 Video 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/