| ▲ | Fluorescence 2 hours ago | |||||||
Not sure that type is good advice:
You'd have to manually implement the traits to support the ergonomics of slices and iteration and costly reallocation if you need to pass ownership as a Vec:I'd expect:
The constructor would enforce the invariant and then you'd impl Deref and DerefMut for [T] to gain normal len/is_empty/indexing/iteration, passing as &[T] to other funcs and mutating values (which can't break the invariant).To mutate length while preserving the invariant it's dealers choice e.g. - add .into_vec() for unwrap/mutate/rewrap - add invariant preserving mutators of your choice | ||||||||
| ▲ | 21 minutes ago | parent | next [-] | |||||||
| [deleted] | ||||||||
| ▲ | Rusky 27 minutes ago | parent | prev | next [-] | |||||||
There's a whole follow up post about this: https://lexi-lambda.github.io/blog/2020/11/01/names-are-not-... | ||||||||
| ▲ | eptcyka an hour ago | parent | prev [-] | |||||||
Which deref must I use to get most of the existing interface sans `retain()`? | ||||||||
| ||||||||