[−][src]Struct thinbox::ThinBox
A consistently-sized pointer type for heap allocation.
See the crate documentation for an example using ThinBox
.
Implementations
impl<T: ?Sized> ThinBox<T>
[src]
pub fn unsize<U: Unsize<T>>(value: U) -> Self
[src]
Creates a new ThinBox
by unsizing a value and placing it on the heap.
pub unsafe fn from_raw(raw: *mut ()) -> Self
[src]
Recovers ThinBox
ownership of a boxed pointee.
Along with into_raw
, this function provides one of the core operations
which makes ThinBox
useful for interoperation with foreign functions.
Safety
raw
must be result ofBox::<U>::into_raw
as *mut ()
orThinBox::<U>::into_raw
whereU
safe totransmute
intoT
.- The alignment requirements of
T
must not be more strict than those ofU
. - It must be generally safe to dereference
raw
, keeping in mind thatraw
does not actually point to()
and does not necessarily even point to aU
.
The first requirement implies that:
Furthermore, support for Box::<U>::into_raw
is not guaranteed to be
preserved across major versions of thinbox
.
pub fn into_raw(thin: Self) -> *mut ()
[src]
Converts the ThinBox
to a single-pointer-sized representation.
Along with from_raw
, this function provides one of the core operations
which makes ThinBox
useful for interoperation with foreign functions.
Notes
It is not safe to dereference this representation. The type of the pointee
depends not only on T
but also on whether or not T
is Sized
.
pub fn as_ptr(thin: &Self) -> *mut T
[src]
Obtains a raw pointer to the boxed value.
The pointee remains owned by the ThinBox
. If you wish to relinquish
ownership, use into_raw
or leak
.
Notes
This method returns a raw mutable pointer, which is dangerous to use.
However ThinBox
is guaranteed to never store an internal reference to its
owned value so dereferencing this pointer does not necessarily cause
undefined behavior.
pub fn leak<'a>(thin: Self) -> &'a mut T
[src]
Leaks the contained value in a manner similar to Box::leak
.
Unlike Box::leak
, if T
is unsized it is not valid to pass the
returned reference to Box::from_raw
or ThinBox::from_raw
.
To restore a ThinBox
from the reference produced by this function use
unleak
.
pub unsafe fn unleak(leaked: &mut T) -> Self
[src]
pub unsafe fn transmute_into<U>(thin: Self, dest: *mut U)
[src]
Moves the owned value into dest
by transmuting it into the Sized
type
U
.
Notes
- The value pointed to by
dest
, if any, is not dropped. - The owned value of the
ThinBox
does not need to be properly aligned as aU
.
Safety
Immediate undefined behavior occurs if U
is larger in size than the owned
value or if dest
is not valid for writes. Otherwise any undefined behavior
is deferred to later operations which dereference dest
and thereby
observe the result of the transmutation.
impl<T> ThinBox<T>
[src]
pub fn new(value: T) -> Self
[src]
Creates a new ThinBox
by moving a Sized
value to the heap.
Notes
Doing this passes up your opportunity to coerce the value to an unsized
type, thereby defeating most of the usefulness of ThinBox
. Instead, you
should consider using Box
unless you are constrained by some other code
which requires instances of ThinBox
.
pub fn from_box(boxed: Box<T>) -> Self
[src]
pub fn into_box(thin: Self) -> Box<T>
[src]
pub fn into_inner(thin: Self) -> T
[src]
Moves the owned value out of a Sized
ThinBox
.
Trait Implementations
impl<T: ?Sized> AsMut<T> for ThinBox<T>
[src]
impl<T: ?Sized> AsRef<T> for ThinBox<T>
[src]
impl<T: ?Sized> Borrow<T> for ThinBox<T>
[src]
impl<T: ?Sized> BorrowMut<T> for ThinBox<T>
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T: Clone> Clone for ThinBox<T>
[src]
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug + ?Sized> Debug for ThinBox<T>
[src]
impl<T: ?Sized> Deref for ThinBox<T>
[src]
impl<T: ?Sized> DerefMut for ThinBox<T>
[src]
impl<T: Display + ?Sized> Display for ThinBox<T>
[src]
impl<T: ?Sized> Drop for ThinBox<T>
[src]
impl<T> From<T> for ThinBox<T>
[src]
impl<T: Hash + ?Sized> Hash for ThinBox<T>
[src]
pub fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: ?Sized> Pointer for ThinBox<T>
[src]
impl<T: Send + ?Sized> Send for ThinBox<T>
[src]
impl<T: Sync + ?Sized> Sync for ThinBox<T>
[src]
impl<T: UnwindSafe + ?Sized> UnwindSafe for ThinBox<T>
[src]
Auto Trait Implementations
impl<T: ?Sized> RefUnwindSafe for ThinBox<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T: ?Sized> Unpin for ThinBox<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<!> for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,