pub struct Impl<T>(_);
Expand description
Re-exported from the implementation crate. 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
sourceimpl<T> Impl<T>
impl<T> Impl<T>
Re-exported from the implementation crate.
Trait Implementations
sourceimpl<T> Ord for Impl<T>where
T: Ord,
impl<T> Ord for Impl<T>where
T: Ord,
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl<T> PartialEq<Impl<T>> for Impl<T>where
T: PartialEq<T>,
impl<T> PartialEq<Impl<T>> for Impl<T>where
T: PartialEq<T>,
sourceimpl<T> PartialOrd<Impl<T>> for Impl<T>where
T: PartialOrd<T>,
impl<T> PartialOrd<Impl<T>> for Impl<T>where
T: PartialOrd<T>,
sourcefn partial_cmp(&self, other: &Impl<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &Impl<T>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more