### Handle allocation failure with match Source: https://github.com/aatifsyed/trybox/blob/main/README.md Use a match statement to handle successful heap allocation or recover the original object from the stack upon failure. ```rust match trybox::new(1) { Ok(heaped) => { let _: Box = heaped; } Err(ErrorWith(stacked)) => { let _: i32 = stacked; // failed object is returned on the stack }, } ``` -------------------------------- ### Verify error size Source: https://github.com/aatifsyed/trybox/blob/main/README.md The Error type is optimized to be the same size as a usize. ```rust assert_eq!(size_of::(), size_of::()); ``` -------------------------------- ### Convert to std::io::Result Source: https://github.com/aatifsyed/trybox/blob/main/README.md When the std feature is enabled, allocation errors can be converted to std::io::Result. ```rust fn fallible(x: T) -> std::io::Result> { Ok(trybox::or_drop(x)?) } ``` -------------------------------- ### Propagate allocation errors Source: https://github.com/aatifsyed/trybox/blob/main/README.md Use or_drop to automatically drop the object and propagate the error when allocation fails. ```rust fn fallible(x: T) -> Result, Box> { Ok(trybox::or_drop(x)?) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.