pub struct Impl<T>(_);
Expand description

Wrapper type for targeting and accessing actual implementation.

Impl has smart-pointer capabilities, as it implements std::ops::Deref and std::ops::DerefMut. You may freely choose what kind of T you want to wrap. It may be an owned one or it could be a &T. Each have different tradeoffs.

An owned T is the most flexible in implementations, but that requires always owning “sub-implementations” through an Impl:

use implementation::Impl;

struct MyConfig {
    param1: i32,
    sub_config: Impl<SubConfig>,
}

struct SubConfig {
    param2: i32,
}

A referenced &T makes it possible to borrow an Impl from any T, but that could prove to be more troublesome in some implementations. This also will require a reference-within-reference design in trait methods with a &self receiver, and some more boilerplate if it needs to be cloned:

use implementation::Impl;

trait DoSomething {
    fn something(&self);
}

impl<'t, T> DoSomething for Impl<&'t T>
    where T: Clone + Send + 'static
{
    // self is an `&Impl<&T>`:
    fn something(&self) {

        // it will require some more code to make a proper clone of T:
        let t_clone = self.into_inner().clone();

        let handle = std::thread::spawn(move || {
            let implementation = Impl::new(&t_clone);

            // Do something else with Impl<&T>
        });

        handle.join().unwrap();
    }
}

Implementations

Construct a new Impl.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.