pub struct TypeHelper<T: ?Sized>(/* private fields */);Expand description
A helper struct used to determine whether a type implements traits like
Send, Sync, and Clone by cooperating with helper traits like
NotSend , NotSync, and NotClone.
Helper traits basically have associated constants meaning whether a type
imeplements a trait such as Send. They are set to false by default, and
all types implement the helper types by blanket implementation. In other
words, all types are not Send, Sync by the helper traits, etc. But
TypeHelper can overwrite it for types that actually implement those
traits thanks to its trait bound. As a result, clients can be aware of
whether a type impelments a certain trait through TypeHelper. This is
especially useful when you make a library that receives anonymous type and
you need such type information.
§How it works
If a struct has function foo<T: Send> and it also implement Foo which
has the same signature function foo<T>, then rust will look for callable
function in the order below.
- Inherent function
- Trait function
So if the type is Send, then rust chooses inherent function due to the
search order. But rust will choose trait function if the type is not Send
due to the T: Send bound.
See https://doc.rust-lang.org/reference/expressions/method-call-expr.html (Document describes about methods, but I believe the same rule is applied to associated functions as well)
Here, more specific rules are written.
- https://rust-lang.github.io/rfcs/0195-associated-items.html#via-an-id_segment-prefix
- https://rust-lang.github.io/rfcs/0195-associated-items.html#via-a-type_segment-prefix
1tells starting with ID_SEGMENT is equivalent to starting with TYPE_SEGMENT. ‘A::b’ is equivalent to ‘<A>::b’2tells inherent members are prioritized over in-scope traits.
Implementations§
Source§impl<T: ?Sized + UnwindSafe> TypeHelper<T>
impl<T: ?Sized + UnwindSafe> TypeHelper<T>
pub const IS_UNWIND_SAFE: bool = true
Source§impl<T: Debug> TypeHelper<T>
impl<T: Debug> TypeHelper<T>
Source§impl<T: Default> TypeHelper<T>
impl<T: Default> TypeHelper<T>
pub const IS_DEFAULT: bool = true
pub const FN_DEFAULT: FnDefaultRaw
Sourcepub const fn fn_default() -> FnDefaultRaw
pub const fn fn_default() -> FnDefaultRaw
Returns raw function pointer of Default::default for the given type.
But the given type is not Default, then calling the returned
function will cause panic.
Source§impl<T: Clone> TypeHelper<T>
impl<T: Clone> TypeHelper<T>
pub const IS_CLONE: bool = true
pub const FN_CLONE: FnCloneRaw
Sourcepub const fn fn_clone() -> FnCloneRaw
pub const fn fn_clone() -> FnCloneRaw
Returns raw function pointer of Clone::clone for the given type.
But the given type is not Clone, then calling the returned function
will cause panic.
Source§impl<T> TypeHelper<(T, T)>
impl<T> TypeHelper<(T, T)>
pub const IS_EQUAL_TYPE: bool = true
Trait Implementations§
Source§impl<T: ?Sized> NotClone for TypeHelper<T>
impl<T: ?Sized> NotClone for TypeHelper<T>
Source§impl<T: ?Sized> NotDebug for TypeHelper<T>
impl<T: ?Sized> NotDebug for TypeHelper<T>
Source§impl<T: ?Sized> NotDefault for TypeHelper<T>
impl<T: ?Sized> NotDefault for TypeHelper<T>
const IS_DEFAULT: bool = false
const FN_DEFAULT: FnDefaultRaw = {ds::types::unimpl_default as unsafe fn(*mut u8)}
Source§impl<T> NotEqualType for TypeHelper<T>
impl<T> NotEqualType for TypeHelper<T>
const IS_EQUAL_TYPE: bool = false
Source§impl<T: ?Sized> NotUnwindSafe for TypeHelper<T>
impl<T: ?Sized> NotUnwindSafe for TypeHelper<T>
const IS_UNWIND_SAFE: bool = false
Auto Trait Implementations§
impl<T> Freeze for TypeHelper<T>where
T: ?Sized,
impl<T> RefUnwindSafe for TypeHelper<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for TypeHelper<T>
impl<T> Sync for TypeHelper<T>
impl<T> Unpin for TypeHelper<T>
impl<T> UnwindSafe for TypeHelper<T>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more