Skip to content

Commit

Permalink
Add missing Option impl for CastRaw and TryCastRaw
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Mar 30, 2023
1 parent f35a926 commit 1b167c2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,16 @@ where
}
}

unsafe impl<T, U> CastRaw<Option<U>> for Option<T>
where
T: CastRaw<U>,
U: Copy,
{
fn cast_raw(self) -> Option<U> {
self.map(|x| x.cast_raw())
}
}

#[cfg(feature = "extern_crate_alloc")]
unsafe impl<T, U> CastRaw<RawCow<*const U, U>> for RawCow<*const T, T>
where
Expand Down Expand Up @@ -811,6 +821,19 @@ where
}
}

unsafe impl<T, U> TryCastRaw<Option<U>> for Option<T>
where
T: TryCastRaw<U>,
U: Copy,
{
fn try_cast_raw(self) -> Result<Option<U>, PodCastError> {
match self {
Some(x) => Ok(Some(x.try_cast_raw()?)),
None => Ok(None),
}
}
}

#[cfg(feature = "extern_crate_alloc")]
unsafe impl<T, U> TryCastRaw<RawCow<*const U, U>> for RawCow<*const T, T>
where
Expand Down

0 comments on commit 1b167c2

Please sign in to comment.