Aside: into_inner
Special case of into: for exclusive pointer types or newtypes, extract the
internal value.
#![allow(unused)] fn main() { pub struct Wrapper<T>(T); impl<T> Wrapper<T> { fn into_inner(self) -> T; } pub struct NonZeroU32(u32); impl NonZeroU32 { fn into_inner(self) -> u32; } impl<T> Cell<T> { fn into_inner(self) -> T; } }
into_inneris a method usually found on newtypes: types whose main purpose is to wrap around an existing type and be semantically distinct from other uses of that inner type.
This kind of method is also found on types like Cell, which exclusively own
the internal data.
The purpose of this kind of method is to consume the “wrapper” type and return the “contained” value.
-
When defining a type with exactly one field, consider if it makes sense to implement an
into_innermethod that consumesselfand returns the field as an owned value.Don’t write a method like this if more fields will be added in the future.