Path: blob/main/crates/core/src/alloc/try_new.rs
3073 views
use crate::error::OutOfMemory;12/// Helper function to invoke `<T as TryNew>::try_new`.3///4/// # Example5///6/// ```7/// # use wasmtime_internal_core::alloc::*;8/// # use wasmtime_internal_core::error::Result;9/// # fn _foo() -> Result<()> {10/// let boxed = try_new::<Box<u32>>(36)?;11/// assert_eq!(*boxed, 36);12/// # Ok(())13/// # }14/// ```15#[inline]16pub fn try_new<T>(value: T::Value) -> Result<T, OutOfMemory>17where18T: TryNew,19{20TryNew::try_new(value)21}2223/// Extension trait providing fallible allocation for types like `Arc<T>` and24/// `Box<T>`.25pub trait TryNew {26/// The inner `T` type that is getting wrapped into an `Arc<T>` or `Box<T>`.27type Value;2829/// Allocate a new `Self`, returning `Err(OutOfMemory)` on allocation30/// failure.31fn try_new(value: Self::Value) -> Result<Self, OutOfMemory>32where33Self: Sized;34}353637