pub trait Dynamic<B: IsBound>: Sealed<B> {
// Required methods
unsafe fn clone_unchecked(this: &Self) -> Self
where Self: Sized;
unsafe fn debug_unchecked(
this: &Self,
f: &mut Formatter<'_>,
) -> Result<(), Error>;
// Provided methods
fn clone(this: &Self) -> Self
where Self: Sized,
<B as IsBound>::CloneMarker: Clone { ... }
fn debug(this: &Self, f: &mut Formatter<'_>) -> Result<(), Error>
where Self: Sized,
<B as IsBound>::DebugMarker: Debug { ... }
}Expand description
Trait implemented when the bound given by B is satisfied by Self.
Use this trait in combination with Bound to apply a trait bound
based on a generic type.
use dungeon_cell::bound::{Dynamic, bounds};
use dungeon_cell::marker_traits::IsBound;
fn test<T: Dynamic<B>, B: IsBound>() {}
// this failes because String isn't Copy
test::<String, bounds::Copy>();The traits with functionality (Clone and Debug)
have their implementation for the type available as Self::clone() and Self::debug(). If
the type doesn’t implement one or both of these traits then it’s method will be implemented
with unreachable_unchecked().
This trait is sealed and cannot be implemented outside of the implementations here.
Required Methods§
Sourceunsafe fn clone_unchecked(this: &Self) -> Selfwhere
Self: Sized,
unsafe fn clone_unchecked(this: &Self) -> Selfwhere
Self: Sized,
Unsafe form of Self::clone().
This method is only valid to call if B has Clone as part of it’s bound.
§Safety
This function must only be called if B::BOUND_BY_CLONE == true and/or B::CloneMarker: Clone.
Sourceunsafe fn debug_unchecked(
this: &Self,
f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( this: &Self, f: &mut Formatter<'_>, ) -> Result<(), Error>
Unsafe form of Self::debug().
This method is only valid to call if B has Debug as part of it’s bound.
§Safety
This function must only be called if B::BOUND_BY_DEBUG == true and/or B::DebugMarker: Debug.
Provided Methods§
Sourcefn clone(this: &Self) -> Self
fn clone(this: &Self) -> Self
Call the Clone::clone() implementation of Self.
This method is always safe to call because it’s bounded by the bound including
Clone. To emulate specialization, use Self::clone_unchecked and check
the B::BOUND_BY_CLONE flag at runtime.
Sourcefn debug(this: &Self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(this: &Self, f: &mut Formatter<'_>) -> Result<(), Error>
Call the Debug::fmt() implementation of Self.
This method is always safe to call because it’s bounded by the bound including
Debug. To emulate specialization, use Self::debug_unchecked and check
the B::BOUND_BY_DEBUG flag at runtime.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.