- Rust Standard Library Cookbook
- Jan Nils Ferner Daniel Durante
- 60字
- 2021-08-27 19:45:02
Using the constructor pattern
You may have asked yourself how to idiomatically initialize complex structs in Rust, considering it doesn't have constructors. The answer is simple, there is a constructor, it's just a convention rather than a rule. Rust's standard library uses this pattern very often, so we need to understand it if we want to use the std effectively.