Lines Matching full:box
3 //! The `Box<T>` type for heap allocation.
5 //! [`Box<T>`], casually referred to as a 'box', provides the simplest form of
12 //! Move a value from the stack to the heap by creating a [`Box`]:
16 //! let boxed: Box<u8> = Box::new(val);
19 //! Move a value from a [`Box`] back to the stack by [dereferencing]:
22 //! let boxed: Box<u8> = Box::new(5);
31 //! Cons(T, Box<List<T>>),
35 //! let list: List<i32> = List::Cons(1, Box::new(List::Cons(2, Box::new(List::Nil))));
52 //! for a `Cons`. By introducing a [`Box<T>`], which has a defined size, we know how
57 //! For non-zero-sized values, a [`Box`] will use the [`Global`] allocator for
58 //! its allocation. It is valid to convert both ways between a [`Box`] and a
62 //! with `Layout::for_value(&*value)` may be converted into a box using
63 //! [`Box::<T>::from_raw(value)`]. Conversely, the memory backing a `value: *mut
64 //! T` obtained from [`Box::<T>::into_raw`] may be deallocated using the
67 //! For zero-sized values, the `Box` pointer still has to be [valid] for reads
71 //! not valid. The recommended way to build a Box to a ZST if `Box::new` cannot
74 //! So long as `T: Sized`, a `Box<T>` is guaranteed to be represented
78 //! Rust functions using `Box<T>` types, and use `T*` as corresponding
94 //! `struct Foo*` type from C is translated to `Box<Foo>`, which captures
96 //! `foo_delete` is represented in Rust as `Option<Box<Foo>>`, since `Box<Foo>`
104 //! pub extern "C" fn foo_new() -> Box<Foo> {
105 //! Box::new(Foo)
109 //! pub extern "C" fn foo_delete(_: Option<Box<Foo>>) {}
112 //! Even though `Box<T>` has the same representation and C ABI as a C pointer,
113 //! this does not mean that you can convert an arbitrary `T*` into a `Box<T>`
114 //! and expect things to work. `Box<T>` values will always be fully aligned,
115 //! non-null pointers. Moreover, the destructor for `Box<T>` will attempt to
117 //! is to only use `Box<T>` for pointers that originated from the global
121 //! `Box<T>` types for functions that are defined in C but invoked
123 //! as closely as possible. Using types like `Box<T>` where the C
133 //! The aliasing rules for `Box<T>` are the same as for `&mut T`. `Box<T>`
134 //! asserts uniqueness over its content. Using raw pointers derived from a box
135 //! after that box has been mutated through, moved or borrowed as `&mut T`
136 //! is not allowed. For more guidance on working with box from unsafe code, see
143 //! [`Box::<T>::from_raw(value)`]: Box::from_raw
196 // The declaration of the `Box` struct must be kept in sync with the
199 pub struct Box< struct
204 impl<T> Box<T> { implementation
212 /// let five = Box::new(5);
221 Box::new(x) in new()
224 /// Constructs a new box with uninitialized contents.
231 /// let mut five = Box::<u32>::new_uninit();
246 pub fn new_uninit() -> Box<mem::MaybeUninit<T>> { in new_uninit()
250 /// Constructs a new `Box` with uninitialized contents, with the memory
261 /// let zero = Box::<u32>::new_zeroed();
272 pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> { in new_zeroed()
276 /// Constructs a new `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
279 /// Constructing and pinning of the `Box` can also be done in two steps: `Box::pin(x)`
280 /// does the same as <code>[Box::into_pin]\([Box::new]\(x))</code>. Consider using
281 /// [`into_pin`](Box::into_pin) if you already have a `Box<T>`, or if you want to
282 /// construct a (pinned) `Box` in a different way than with [`Box::new`].
287 pub fn pin(x: T) -> Pin<Box<T>> { in pin()
288 Box::new(x).into() in pin()
301 /// let five = Box::try_new(5)?;
310 /// Constructs a new box with uninitialized contents on the heap,
318 /// let mut five = Box::<u32>::try_new_uninit()?;
333 pub fn try_new_uninit() -> Result<Box<mem::MaybeUninit<T>>, AllocError> { in try_new_uninit()
334 Box::try_new_uninit_in(Global) in try_new_uninit()
337 /// Constructs a new `Box` with uninitialized contents, with the memory
348 /// let zero = Box::<u32>::try_new_zeroed()?;
359 pub fn try_new_zeroed() -> Result<Box<mem::MaybeUninit<T>>, AllocError> { in try_new_zeroed()
360 Box::try_new_zeroed_in(Global) in try_new_zeroed()
364 impl<T, A: Allocator> Box<T, A> { implementation
376 /// let five = Box::new_in(5, System);
405 /// let five = Box::try_new_in(5, System)?;
421 /// Constructs a new box with uninitialized contents in the provided allocator.
430 /// let mut five = Box::<u32, _>::new_uninit_in(System);
445 pub fn new_uninit_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> in new_uninit_in()
452 match Box::try_new_uninit_in(alloc) { in new_uninit_in()
458 /// Constructs a new box with uninitialized contents in the provided allocator,
468 /// let mut five = Box::<u32, _>::try_new_uninit_in(System)?;
482 pub fn try_new_uninit_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError> in try_new_uninit_in()
492 unsafe { Ok(Box::from_raw_in(ptr.as_ptr(), alloc)) } in try_new_uninit_in()
495 /// Constructs a new `Box` with uninitialized contents, with the memory
508 /// let zero = Box::<u32, _>::new_zeroed_in(System);
519 pub fn new_zeroed_in(alloc: A) -> Box<mem::MaybeUninit<T>, A> in new_zeroed_in()
526 match Box::try_new_zeroed_in(alloc) { in new_zeroed_in()
532 /// Constructs a new `Box` with uninitialized contents, with the memory
546 /// let zero = Box::<u32, _>::try_new_zeroed_in(System)?;
556 pub fn try_new_zeroed_in(alloc: A) -> Result<Box<mem::MaybeUninit<T>, A>, AllocError> in try_new_zeroed_in()
566 unsafe { Ok(Box::from_raw_in(ptr.as_ptr(), alloc)) } in try_new_zeroed_in()
569 /// Constructs a new `Pin<Box<T, A>>`. If `T` does not implement [`Unpin`], then
572 /// Constructing and pinning of the `Box` can also be done in two steps: `Box::pin_in(x, alloc)`
573 /// does the same as <code>[Box::into_pin]\([Box::new_in]\(x, alloc))</code>. Consider using
574 /// [`into_pin`](Box::into_pin) if you already have a `Box<T, A>`, or if you want to
575 /// construct a (pinned) `Box` in a different way than with [`Box::new_in`].
587 /// Converts a `Box<T>` into a `Box<[T]>`
591 pub fn into_boxed_slice(boxed: Self) -> Box<[T], A> { in into_boxed_slice()
592 let (raw, alloc) = Box::into_raw_with_allocator(boxed); in into_boxed_slice()
593 unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) } in into_boxed_slice()
596 /// Consumes the `Box`, returning the wrapped value.
603 /// let c = Box::new(5);
605 /// assert_eq!(Box::into_inner(c), 5);
614 impl<T> Box<[T]> { implementation
622 /// let mut values = Box::<[u32]>::new_uninit_slice(3);
638 pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> { in new_uninit_slice()
653 /// let values = Box::<[u32]>::new_zeroed_slice(3);
663 pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> { in new_zeroed_slice()
675 /// let mut values = Box::<[u32]>::try_new_uninit_slice(3)?;
689 pub fn try_new_uninit_slice(len: usize) -> Result<Box<[mem::MaybeUninit<T>]>, AllocError> { in try_new_uninit_slice()
713 /// let values = Box::<[u32]>::try_new_zeroed_slice(3)?;
723 pub fn try_new_zeroed_slice(len: usize) -> Result<Box<[mem::MaybeUninit<T>]>, AllocError> { in try_new_zeroed_slice()
737 impl<T, A: Allocator> Box<[T], A> { impl
747 /// let mut values = Box::<[u32], _>::new_uninit_slice_in(3, System);
764 pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> { in new_uninit_slice_in()
781 /// let values = Box::<[u32], _>::new_zeroed_slice_in(3, System);
792 pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> { in new_zeroed_slice_in()
797 impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> { implementation
798 /// Converts to `Box<T, A>`.
815 /// let mut five = Box::<u32>::new_uninit();
817 /// let five: Box<u32> = unsafe {
828 pub unsafe fn assume_init(self) -> Box<T, A> { in assume_init()
829 let (raw, alloc) = Box::into_raw_with_allocator(self); in assume_init()
830 unsafe { Box::from_raw_in(raw as *mut T, alloc) } in assume_init()
833 /// Writes the value and converts to `Box<T, A>`.
835 /// This method converts the box similarly to [`Box::assume_init`] but
845 /// let big_box = Box::<[usize; 1024]>::new_uninit();
854 /// let big_box = Box::write(big_box, array);
862 pub fn write(mut boxed: Self, value: T) -> Box<T, A> { in write()
870 impl<T, A: Allocator> Box<[mem::MaybeUninit<T>], A> { impl
871 /// Converts to `Box<[T], A>`.
888 /// let mut values = Box::<[u32]>::new_uninit_slice(3);
903 pub unsafe fn assume_init(self) -> Box<[T], A> { in assume_init()
904 let (raw, alloc) = Box::into_raw_with_allocator(self); in assume_init()
905 unsafe { Box::from_raw_in(raw as *mut [T], alloc) } in assume_init()
909 impl<T: ?Sized> Box<T> { implementation
910 /// Constructs a box from a raw pointer.
913 /// resulting `Box`. Specifically, the `Box` destructor will call
916 /// with the [memory layout] used by `Box` .
928 /// Recreate a `Box` which was previously converted to a raw pointer
929 /// using [`Box::into_raw`]:
931 /// let x = Box::new(5);
932 /// let ptr = Box::into_raw(x);
933 /// let x = unsafe { Box::from_raw(ptr) };
935 /// Manually create a `Box` from scratch by using the global allocator:
945 /// let x = Box::from_raw(ptr);
953 #[must_use = "call `drop(Box::from_raw(ptr))` if you intend to drop the `Box`"]
959 impl<T: ?Sized, A: Allocator> Box<T, A> { impl
960 /// Constructs a box from a raw pointer in the given allocator.
963 /// resulting `Box`. Specifically, the `Box` destructor will call
966 /// with the [memory layout] used by `Box` .
977 /// Recreate a `Box` which was previously converted to a raw pointer
978 /// using [`Box::into_raw_with_allocator`]:
984 /// let x = Box::new_in(5, System);
985 /// let (ptr, alloc) = Box::into_raw_with_allocator(x);
986 /// let x = unsafe { Box::from_raw_in(ptr, alloc) };
988 /// Manually create a `Box` from scratch by using the system allocator:
1000 /// let x = Box::from_raw_in(ptr, System);
1011 Box(unsafe { Unique::new_unchecked(raw) }, alloc) in from_raw_in()
1014 /// Consumes the `Box`, returning a wrapped raw pointer.
1019 /// memory previously managed by the `Box`. In particular, the
1021 /// into account the [memory layout] used by `Box`. The easiest way to
1022 /// do this is to convert the raw pointer back into a `Box` with the
1023 /// [`Box::from_raw`] function, allowing the `Box` destructor to perform
1027 /// to call it as `Box::into_raw(b)` instead of `b.into_raw()`. This
1031 /// Converting the raw pointer back into a `Box` with [`Box::from_raw`]
1034 /// let x = Box::new(String::from("Hello"));
1035 /// let ptr = Box::into_raw(x);
1036 /// let x = unsafe { Box::from_raw(ptr) };
1044 /// let x = Box::new(String::from("Hello"));
1045 /// let p = Box::into_raw(x);
1059 /// Consumes the `Box`, returning a wrapped raw pointer and the allocator.
1064 /// memory previously managed by the `Box`. In particular, the
1066 /// into account the [memory layout] used by `Box`. The easiest way to
1067 /// do this is to convert the raw pointer back into a `Box` with the
1068 /// [`Box::from_raw_in`] function, allowing the `Box` destructor to perform
1072 … /// to call it as `Box::into_raw_with_allocator(b)` instead of `b.into_raw_with_allocator()`. This
1076 /// Converting the raw pointer back into a `Box` with [`Box::from_raw_in`]
1083 /// let x = Box::new_in(String::from("Hello"), System);
1084 /// let (ptr, alloc) = Box::into_raw_with_allocator(x);
1085 /// let x = unsafe { Box::from_raw_in(ptr, alloc) };
1095 /// let x = Box::new_in(String::from("Hello"), System);
1096 /// let (ptr, alloc) = Box::into_raw_with_allocator(x);
1108 let (leaked, alloc) = Box::into_unique(b); in into_raw_with_allocator()
1115 reason = "use `Box::leak(b).into()` or `Unique::from(Box::leak(b))` instead"
1120 // Box is recognized as a "unique pointer" by Stacked Borrows, but internally it is a in into_unique()
1123 … // so all raw pointer methods have to go through `Box::leak`. Turning *that* to a raw pointer in into_unique()
1126 (Unique::from(Box::leak(b)), alloc) in into_unique()
1132 /// to call it as `Box::allocator(&b)` instead of `b.allocator()`. This
1141 /// Consumes and leaks the `Box`, returning a mutable reference,
1149 /// with the [`Box::from_raw`] function producing a `Box`. This `Box` can
1154 /// to call it as `Box::leak(b)` instead of `b.leak()`. This
1162 /// let x = Box::new(41);
1163 /// let static_ref: &'static mut usize = Box::leak(x);
1172 /// let static_ref = Box::leak(x);
1185 /// Converts a `Box<T>` into a `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
1192 /// Constructing and pinning a `Box` with <code>Box::into_pin([Box::new]\(x))</code>
1193 /// can also be written more concisely using <code>[Box::pin]\(x)</code>.
1194 /// This `into_pin` method is useful if you already have a `Box<T>`, or you are
1195 /// constructing a (pinned) `Box` in a different way than with [`Box::new`].
1199 /// It's not recommended that crates add an impl like `From<Box<T>> for Pin<T>`,
1206 /// impl From<Box<()>> for Pin<Foo> {
1207 /// fn from(_: Box<()>) -> Pin<Foo> {
1212 /// let foo = Box::new(());
1221 // It's not possible to move or replace the insides of a `Pin<Box<T>>` in into_pin()
1229 unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> { implementation
1232 // the T in the Box is dropped by the compiler before the destructor is run in drop()
1247 impl<T: Default> Default for Box<T> { implementation
1248 /// Creates a `Box<T>`, with the `Default` value for T.
1251 Box::new(T::default()) in default()
1257 impl<T> Default for Box<[T]> { implementation
1261 Box(ptr, Global) in default()
1267 impl Default for Box<str> { implementation
1275 Box(ptr, Global) in default()
1281 impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> { implementation
1282 /// Returns a new box with a `clone()` of this box's contents.
1287 /// let x = Box::new(5);
1311 /// let x = Box::new(5);
1312 /// let mut y = Box::new(10);
1331 impl Clone for Box<str> { implementation
1334 let buf: Box<[u8]> = self.as_bytes().into(); in clone()
1340 impl<T: ?Sized + PartialEq, A: Allocator> PartialEq for Box<T, A> { implementation
1351 impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Box<T, A> { implementation
1374 impl<T: ?Sized + Ord, A: Allocator> Ord for Box<T, A> { implementation
1381 impl<T: ?Sized + Eq, A: Allocator> Eq for Box<T, A> {} implementation
1384 impl<T: ?Sized + Hash, A: Allocator> Hash for Box<T, A> { implementation
1391 impl<T: ?Sized + Hasher, A: Allocator> Hasher for Box<T, A> { implementation
1444 impl<T> From<T> for Box<T> { implementation
1445 /// Converts a `T` into a `Box<T>`
1454 /// let boxed = Box::new(5);
1456 /// assert_eq!(Box::from(x), boxed);
1459 Box::new(t) in from()
1464 impl<T: ?Sized, A: Allocator> From<Box<T, A>> for Pin<Box<T, A>>
1468 /// Converts a `Box<T>` into a `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
1473 /// This is also available via [`Box::into_pin`].
1475 /// Constructing and pinning a `Box` with <code><Pin<Box\<T>>>::from([Box::new]\(x))</code>
1476 /// can also be written more concisely using <code>[Box::pin]\(x)</code>.
1477 /// This `From` implementation is useful if you already have a `Box<T>`, or you are
1478 /// constructing a (pinned) `Box` in a different way than with [`Box::new`].
1479 fn from(boxed: Box<T, A>) -> Self { in from()
1480 Box::into_pin(boxed) in from()
1491 impl<T: Clone> BoxFromSlice<T> for Box<[T]> { implementation
1499 impl<T: Copy> BoxFromSlice<T> for Box<[T]> { implementation
1513 impl<T: Clone> From<&[T]> for Box<[T]> { implementation
1514 /// Converts a `&[T]` into a `Box<[T]>`
1521 /// // create a &[u8] which will be used to create a Box<[u8]>
1523 /// let boxed_slice: Box<[u8]> = Box::from(slice);
1528 fn from(slice: &[T]) -> Box<[T]> { in from()
1535 impl<T: Clone> From<Cow<'_, [T]>> for Box<[T]> { implementation
1536 /// Converts a `Cow<'_, [T]>` into a `Box<[T]>`
1543 fn from(cow: Cow<'_, [T]>) -> Box<[T]> { in from()
1545 Cow::Borrowed(slice) => Box::from(slice), in from()
1546 Cow::Owned(slice) => Box::from(slice), in from()
1553 impl From<&str> for Box<str> { implementation
1554 /// Converts a `&str` into a `Box<str>`
1562 /// let boxed: Box<str> = Box::from("hello");
1566 fn from(s: &str) -> Box<str> { in from()
1567 unsafe { from_boxed_utf8_unchecked(Box::from(s.as_bytes())) } in from()
1573 impl From<Cow<'_, str>> for Box<str> { implementation
1574 /// Converts a `Cow<'_, str>` into a `Box<str>`
1587 /// let boxed: Box<str> = Box::from(unboxed);
1594 /// let boxed: Box<str> = Box::from(unboxed);
1598 fn from(cow: Cow<'_, str>) -> Box<str> { in from()
1600 Cow::Borrowed(s) => Box::from(s), in from()
1601 Cow::Owned(s) => Box::from(s), in from()
1607 impl<A: Allocator> From<Box<str, A>> for Box<[u8], A> { implementation
1608 /// Converts a `Box<str>` into a `Box<[u8]>`
1614 /// // create a Box<str> which will be used to create a Box<[u8]>
1615 /// let boxed: Box<str> = Box::from("hello");
1616 /// let boxed_str: Box<[u8]> = Box::from(boxed);
1618 /// // create a &[u8] which will be used to create a Box<[u8]>
1620 /// let boxed_slice = Box::from(slice);
1625 fn from(s: Box<str, A>) -> Self { in from()
1626 let (raw, alloc) = Box::into_raw_with_allocator(s); in from()
1627 unsafe { Box::from_raw_in(raw as *mut [u8], alloc) } in from()
1633 impl<T, const N: usize> From<[T; N]> for Box<[T]> { implementation
1634 /// Converts a `[T; N]` into a `Box<[T]>`
1641 /// let boxed: Box<[u8]> = Box::from([4, 2]);
1644 fn from(array: [T; N]) -> Box<[T]> { in from()
1645 Box::new(array)
1655 boxed_slice: Box<[T], A>, in boxed_slice_as_array_unchecked()
1656 ) -> Box<[T; N], A> { in boxed_slice_as_array_unchecked()
1659 let (ptr, alloc) = Box::into_raw_with_allocator(boxed_slice);
1660 // SAFETY: Pointer and allocator came from an existing box,
1662 unsafe { Box::from_raw_in(ptr as *mut [T; N], alloc) }
1666 impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> { implementation
1667 type Error = Box<[T]>;
1669 /// Attempts to convert a `Box<[T]>` into a `Box<[T; N]>`.
1676 /// Returns the old `Box<[T]>` in the `Err` variant if
1678 fn try_from(boxed_slice: Box<[T]>) -> Result<Self, Self::Error> { in try_from()
1689 impl<T, const N: usize> TryFrom<Vec<T>> for Box<[T; N]> { implementation
1692 /// Attempts to convert a `Vec<T>` into a `Box<[T; N]>`.
1707 /// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap();
1720 impl<A: Allocator> Box<dyn Any, A> { implementation
1721 /// Attempt to downcast the box to a concrete type.
1728 /// fn print_if_string(value: Box<dyn Any>) {
1735 /// print_if_string(Box::new(my_string));
1736 /// print_if_string(Box::new(0i8));
1740 pub fn downcast<T: Any>(self) -> Result<Box<T, A>, Self> { in downcast()
1744 /// Downcasts the box to a concrete type.
1755 /// let x: Box<dyn Any> = Box::new(1_usize);
1770 pub unsafe fn downcast_unchecked<T: Any>(self) -> Box<T, A> { in downcast_unchecked()
1773 let (raw, alloc): (*mut dyn Any, _) = Box::into_raw_with_allocator(self); in downcast_unchecked()
1774 Box::from_raw_in(raw as *mut T, alloc) in downcast_unchecked()
1779 impl<A: Allocator> Box<dyn Any + Send, A> { implementation
1780 /// Attempt to downcast the box to a concrete type.
1787 /// fn print_if_string(value: Box<dyn Any + Send>) {
1794 /// print_if_string(Box::new(my_string));
1795 /// print_if_string(Box::new(0i8));
1799 pub fn downcast<T: Any>(self) -> Result<Box<T, A>, Self> { in downcast()
1803 /// Downcasts the box to a concrete type.
1814 /// let x: Box<dyn Any + Send> = Box::new(1_usize);
1829 pub unsafe fn downcast_unchecked<T: Any>(self) -> Box<T, A> { in downcast_unchecked()
1832 let (raw, alloc): (*mut (dyn Any + Send), _) = Box::into_raw_with_allocator(self); in downcast_unchecked()
1833 Box::from_raw_in(raw as *mut T, alloc) in downcast_unchecked()
1838 impl<A: Allocator> Box<dyn Any + Send + Sync, A> { implementation
1839 /// Attempt to downcast the box to a concrete type.
1846 /// fn print_if_string(value: Box<dyn Any + Send + Sync>) {
1853 /// print_if_string(Box::new(my_string));
1854 /// print_if_string(Box::new(0i8));
1858 pub fn downcast<T: Any>(self) -> Result<Box<T, A>, Self> { in downcast()
1862 /// Downcasts the box to a concrete type.
1873 /// let x: Box<dyn Any + Send + Sync> = Box::new(1_usize);
1888 pub unsafe fn downcast_unchecked<T: Any>(self) -> Box<T, A> { in downcast_unchecked()
1892 Box::into_raw_with_allocator(self); in downcast_unchecked()
1893 Box::from_raw_in(raw as *mut T, alloc) in downcast_unchecked()
1899 impl<T: fmt::Display + ?Sized, A: Allocator> fmt::Display for Box<T, A> { implementation
1906 impl<T: fmt::Debug + ?Sized, A: Allocator> fmt::Debug for Box<T, A> { implementation
1913 impl<T: ?Sized, A: Allocator> fmt::Pointer for Box<T, A> { implementation
1915 // It's not possible to extract the inner Uniq directly from the Box, in fmt()
1923 impl<T: ?Sized, A: Allocator> Deref for Box<T, A> { implementation
1932 impl<T: ?Sized, A: Allocator> DerefMut for Box<T, A> { implementation
1939 impl<T: ?Sized, A: Allocator> Receiver for Box<T, A> {} implementation
1942 impl<I: Iterator + ?Sized, A: Allocator> Iterator for Box<I, A> { implementation
1963 impl<I: Iterator + ?Sized, A: Allocator> BoxIter for Box<I, A> { implementation
1978 impl<I: Iterator, A: Allocator> BoxIter for Box<I, A> { implementation
1985 impl<I: DoubleEndedIterator + ?Sized, A: Allocator> DoubleEndedIterator for Box<I, A> { implementation
1994 impl<I: ExactSizeIterator + ?Sized, A: Allocator> ExactSizeIterator for Box<I, A> { implementation
2004 impl<I: FusedIterator + ?Sized, A: Allocator> FusedIterator for Box<I, A> {} implementation
2007 impl<Args: Tuple, F: FnOnce<Args> + ?Sized, A: Allocator> FnOnce<Args> for Box<F, A> { implementation
2016 impl<Args: Tuple, F: FnMut<Args> + ?Sized, A: Allocator> FnMut<Args> for Box<F, A> { implementation
2023 impl<Args: Tuple, F: Fn<Args> + ?Sized, A: Allocator> Fn<Args> for Box<F, A> { implementation
2030 impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {} implementation
2033 impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T, Global> {} implementation
2037 impl<I> FromIterator<I> for Box<[I]> { implementation
2045 impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A> { implementation
2047 let alloc = Box::allocator(self).clone(); in clone()
2061 impl<T: ?Sized, A: Allocator> borrow::Borrow<T> for Box<T, A> { implementation
2068 impl<T: ?Sized, A: Allocator> borrow::BorrowMut<T> for Box<T, A> { implementation
2075 impl<T: ?Sized, A: Allocator> AsRef<T> for Box<T, A> { implementation
2082 impl<T: ?Sized, A: Allocator> AsMut<T> for Box<T, A> { implementation
2091 * function of Pin<Box<T>> to Pin<T>. Such a function would not be sound,
2092 * because Box<T> implements Unpin even when T does not, as a result of
2099 * (Box<T> is the only pointer type in std for which this would be
2101 * - It is in practice very useful to have Box<T> be unconditionally
2103 * trait functionality does not apply (e.g., Box<dyn Foo> would
2106 * Another type with the same semantics as Box but only a conditional
2111 impl<T: ?Sized, A: Allocator> Unpin for Box<T, A> where A: 'static {} implementation
2114 impl<G: ?Sized + Generator<R> + Unpin, R, A: Allocator> Generator<R> for Box<G, A> implementation
2127 impl<G: ?Sized + Generator<R>, R, A: Allocator> Generator<R> for Pin<Box<G, A>>
2140 impl<F: ?Sized + Future + Unpin, A: Allocator> Future for Box<F, A> implementation
2152 impl<S: ?Sized + AsyncIterator + Unpin> AsyncIterator for Box<S> { implementation
2168 /// Attempts to downcast the box to a concrete type.
2169 pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error>> { in downcast()
2172 let raw: *mut dyn Error = Box::into_raw(self); in downcast()
2173 Ok(Box::from_raw(raw as *mut T)) in downcast()
2185 /// Attempts to downcast the box to a concrete type.
2186 pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error + Send>> { in downcast()
2187 let err: Box<dyn Error> = self; in downcast()
2190 Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send)) in downcast()
2199 /// Attempts to downcast the box to a concrete type.
2200 pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Self>> { in downcast()
2201 let err: Box<dyn Error> = self; in downcast()
2204 Box::from_raw(Box::into_raw(s) as *mut (dyn Error + Send + Sync)) in downcast()
2211 impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> { implementation
2212 /// Converts a type of [`Error`] into a box of dyn [`Error`].
2234 /// let a_boxed_error = Box::<dyn Error>::from(an_error);
2235 /// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
2237 fn from(err: E) -> Box<dyn Error + 'a> { in from()
2238 Box::new(err) in from()
2244 impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync + 'a> { implementation
2245 /// Converts a type of [`Error`] + [`Send`] + [`Sync`] into a box of
2272 /// let a_boxed_error = Box::<dyn Error + Send + Sync>::from(an_error);
2274 /// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
2276 fn from(err: E) -> Box<dyn Error + Send + Sync + 'a> { in from()
2277 Box::new(err) in from()
2283 impl From<String> for Box<dyn Error + Send + Sync> { implementation
2284 /// Converts a [`String`] into a box of dyn [`Error`] + [`Send`] + [`Sync`].
2293 /// let a_boxed_error = Box::<dyn Error + Send + Sync>::from(a_string_error);
2295 /// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
2298 fn from(err: String) -> Box<dyn Error + Send + Sync> { in from()
2321 Box::new(StringError(err)) in from()
2327 impl From<String> for Box<dyn Error> { implementation
2328 /// Converts a [`String`] into a box of dyn [`Error`].
2337 /// let a_boxed_error = Box::<dyn Error>::from(a_string_error);
2338 /// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
2340 fn from(str_err: String) -> Box<dyn Error> { in from()
2341 let err1: Box<dyn Error + Send + Sync> = From::from(str_err); in from()
2342 let err2: Box<dyn Error> = err1; in from()
2349 impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> { implementation
2350 /// Converts a [`str`] into a box of dyn [`Error`] + [`Send`] + [`Sync`].
2361 /// let a_boxed_error = Box::<dyn Error + Send + Sync>::from(a_str_error);
2363 /// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
2366 fn from(err: &str) -> Box<dyn Error + Send + Sync + 'a> { in from()
2373 impl From<&str> for Box<dyn Error> { implementation
2374 /// Converts a [`str`] into a box of dyn [`Error`].
2385 /// let a_boxed_error = Box::<dyn Error>::from(a_str_error);
2386 /// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
2388 fn from(err: &str) -> Box<dyn Error> { in from()
2395 impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a> { implementation
2396 /// Converts a [`Cow`] into a box of dyn [`Error`] + [`Send`] + [`Sync`].
2406 /// let a_boxed_error = Box::<dyn Error + Send + Sync>::from(a_cow_str_error);
2408 /// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
2410 fn from(err: Cow<'b, str>) -> Box<dyn Error + Send + Sync + 'a> { in from()
2417 impl<'a> From<Cow<'a, str>> for Box<dyn Error> { implementation
2418 /// Converts a [`Cow`] into a box of dyn [`Error`].
2428 /// let a_boxed_error = Box::<dyn Error>::from(a_cow_str_error);
2429 /// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
2431 fn from(err: Cow<'a, str>) -> Box<dyn Error> { in from()
2437 impl<T: core::error::Error> core::error::Error for Box<T> { implementation