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§
Trait Implementations§
source§impl<T> Ord for Impl<T>where
T: Ord,
impl<T> Ord for Impl<T>where
T: Ord,
source§impl<T> PartialEq<Impl<T>> for Impl<T>where
T: PartialEq<T>,
impl<T> PartialEq<Impl<T>> for Impl<T>where
T: PartialEq<T>,
source§impl<T> PartialOrd<Impl<T>> for Impl<T>where
T: PartialOrd<T>,
impl<T> PartialOrd<Impl<T>> for Impl<T>where
T: PartialOrd<T>,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T> Copy for Impl<T>where
T: Copy,
impl<T> Eq for Impl<T>where
T: Eq,
impl<T> StructuralEq for Impl<T>
impl<T> StructuralPartialEq for Impl<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for Impl<T>where
T: RefUnwindSafe,
impl<T> Send for Impl<T>where
T: Send,
impl<T> Sync for Impl<T>where
T: Sync,
impl<T> Unpin for Impl<T>where
T: Unpin,
impl<T> UnwindSafe for Impl<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> ProperDebug for Twhere
T: Debug,
impl<T> ProperDebug for Twhere
T: Debug,
source§fn unimock_try_debug(&self) -> String
fn unimock_try_debug(&self) -> String
Format a debug representation.