Let us say we have the following type:
struct Wrapper(Content);
Say that I often need to access the Content value of this type, destructuring it every time gets cumbersome quickly. What would be the idiomatic approach to unwrapping this value? I know of two approaches: implementing Into<Content> and implementing Deref. Maybe one of these is preferred? Or maybe there's some better-accepted way to do it?
Into approach:
impl Into<Content> for Wrapper {
fn into(self) -> Content {
let Wrapper(content) = self;
content
}
}
// ...
let content: Content = wrapper.into();
Deref approach:
impl Deref for Wrapper {
type Target = Content;
fn deref(&self) -> &Self::Target {
let Wrapper(content) = self;
content
}
}
// ...
let content: Content = *wrapper;