Is making in-place operations return the object a bad idea?

Yes, it is a bad idea. The reason is that if in-place and non-in-place operations have apparently identical output, then programmers will frequently mix up in-place operations and non-in-place operations (List.sort() vs. sorted()) and that results in hard-to-detect errors. In-place operations returning themselves can allow you to perform “method chaining”, however, this is bad practice … Read more

How to use struct self in member method closure

Split your data and methods into smaller components, then you can take disjoint borrows to various components on self: fn fetch_access_token(_base_url: &str) -> String { String::new() } fn get_env_url() -> String { String::new() } #[derive(Default)] struct BaseUrl(Option<String>); impl BaseUrl { fn get(&mut self) -> &str { self.0.get_or_insert_with(|| get_env_url()) } } #[derive(Default)] struct App { base_url: … Read more