IntoInner

Trait IntoInner 

Source
pub trait IntoInner {
    type InnerType;

    // Required method
    fn into_inner(self) -> Self::InnerType;
}
Expand description

A trait for consuming a wrapper type and extracting its inner value.

The IntoInner trait is designed for types that act as wrappers around a single inner value. It provides a method, IntoInner::into_inner(), which consumes the wrapper and returns the inner value.

This trait is particularly useful for tuple structs with a single field, where the wrapper is used to encapsulate or add functionality to the inner value.

§Associated Types

  • InnerType: The type of the inner value that will be extracted.

§Examples

§Manual Implementation

use into_inner::IntoInner; // import both the trait and the derive macro

struct MyWrapper(String);

impl IntoInner for MyWrapper {
    type InnerType = String;

    fn into_inner(self) -> Self::InnerType {
        self.0
    }
}

let wrapper = MyWrapper("Hello, world!".to_string());
let inner = wrapper.into_inner();
assert_eq!(inner, "Hello, world!");

§Using the Derive Macro

The IntoInner trait can also be automatically implemented for tuple structs with a single field using the #[derive(IntoInner)] macro:

use into_inner::IntoInner; // import both the trait and the derive macro

#[derive(IntoInner)]
struct MyWrapper(String);

let wrapper = MyWrapper("Hello, world!".to_string());
let inner = wrapper.into_inner();
assert_eq!(inner, "Hello, world!");

Required Associated Types§

Source

type InnerType

The type of the inner value that will be extracted.

Required Methods§

Source

fn into_inner(self) -> Self::InnerType

Consumes the wrapper and returns the inner value.

Implementations on Foreign Types§

Source§

impl IntoInner for bool

Source§

impl IntoInner for char

Source§

impl IntoInner for f32

Source§

impl IntoInner for f64

Source§

impl IntoInner for i8

Source§

impl IntoInner for i16

Source§

impl IntoInner for i32

Source§

impl IntoInner for i64

Source§

impl IntoInner for i128

Source§

impl IntoInner for isize

Source§

impl IntoInner for u8

Source§

impl IntoInner for u16

Source§

impl IntoInner for u32

Source§

impl IntoInner for u64

Source§

impl IntoInner for u128

Source§

impl IntoInner for usize

Source§

impl IntoInner for Complex<f32>

Source§

impl IntoInner for Complex<f64>

Implementors§