use crate::error::OutOfMemory; /// Helper function to invoke `::try_new`. /// /// # Example /// /// ``` /// # use wasmtime_internal_core::alloc::*; /// # use wasmtime_internal_core::error::Result; /// # fn _foo() -> Result<()> { /// let boxed = try_new::>(36)?; /// assert_eq!(*boxed, 36); /// # Ok(()) /// # } /// ``` #[inline] pub fn try_new(value: T::Value) -> Result where T: TryNew, { TryNew::try_new(value) } /// Extension trait providing fallible allocation for types like `Arc` and /// `Box`. pub trait TryNew { /// The inner `T` type that is getting wrapped into an `Arc` or `Box`. type Value; /// Allocate a new `Self`, returning `Err(OutOfMemory)` on allocation /// failure. fn try_new(value: Self::Value) -> Result where Self: Sized; }