devela::_dep::bytemuck

Function try_cast

pub fn try_cast<A, B>(a: A) -> Result<B, PodCastError> 
where A: NoUninit, B: AnyBitPattern,
Available on crate feature dep_bytemuck only.
Expand description

Try to cast A into B.

Note that for this particular type of cast, alignment isn’t a factor. The input value is semantically copied into the function and then returned to a new memory location which will have whatever the required alignment of the output type is.

§Failure

  • If the types don’t have the same size this fails.