1use crate::*;
2
3#[allow(deprecated)]
4impl<T: ToSimpleDataBytes> ToBytes for Option<T> {
5 #[inline(always)]
6 fn to_bytes(self) -> Bytes {
7 unsafe { Bytes::from_raw_bytes(self.to_raw_bytes()) }
8 }
9}
10#[allow(deprecated)]
11impl<T: ToComplexDataBytes + Default> ToBytes for Option<AsIs<T>> {
12 #[inline(always)]
13 fn to_bytes(self) -> Bytes {
14 unsafe {
15 let raw = self.to_raw_bytes();
16 Bytes::from_raw_with_drops(raw, Some(vec![(0, the_drop::<Option<AsIs<T>>>)]))
17 }
18 }
19}
20
21#[allow(deprecated)]
24impl<'a, T> ReadBack<'a> for Option<T>
25where
26 Self: ToBytes,
27{
28 #[inline(always)]
29 unsafe fn read_back(ptr: *const u8) -> &'a Self {
30 &*(ptr as *const Self)
31 }
32}
33#[allow(deprecated)]
34impl<'a, T> ReadBackMut<'a> for Option<T>
35where
36 Self: ToBytes,
37{
38 #[inline(always)]
39 unsafe fn read_back_mut(ptr: *mut u8) -> &'a mut Self {
40 &mut *(ptr as *mut Self)
41 }
42}
43#[allow(deprecated)]
44impl<T: TransmuteBack> TransmuteBack for Option<T>
45where
46 Self: ToBytes,
47{
48 #[inline(always)]
49 unsafe fn transmute_back(ptr: *const u8) -> Self {
50 let full = core::mem::size_of::<Self>();
51 let sub = core::mem::size_of::<T>();
52 let offset = full - sub;
53 let r = Self::read_back(ptr);
54 match r {
55 Some(_) => Some(T::transmute_back(ptr.add(offset))),
56 None => None,
57 }
58 }
59}