Remove transmute in Vm{Reader,Writer}

This commit is contained in:
Ruihan Li 2025-04-20 23:14:03 +08:00 committed by Junyang Zhang
parent 2c21b2a3a8
commit e1e5f9f575

View File

@ -548,10 +548,13 @@ impl<'a> VmReader<'a, Infallible> {
/// Converts to a fallible reader. /// Converts to a fallible reader.
pub fn to_fallible(self) -> VmReader<'a, Fallible> { pub fn to_fallible(self) -> VmReader<'a, Fallible> {
// SAFETY: It is safe to transmute to a fallible reader since // It is safe to construct a fallible reader since an infallible reader covers the
// 1. the fallibility is a zero-sized marker type, // capabilities of a fallible reader.
// 2. an infallible reader covers the capabilities of a fallible reader. VmReader {
unsafe { core::mem::transmute(self) } cursor: self.cursor,
end: self.end,
phantom: PhantomData,
}
} }
} }
@ -799,10 +802,13 @@ impl<'a> VmWriter<'a, Infallible> {
/// Converts to a fallible writer. /// Converts to a fallible writer.
pub fn to_fallible(self) -> VmWriter<'a, Fallible> { pub fn to_fallible(self) -> VmWriter<'a, Fallible> {
// SAFETY: It is safe to transmute to a fallible writer since // It is safe to construct a fallible reader since an infallible reader covers the
// 1. the fallibility is a zero-sized marker type, // capabilities of a fallible reader.
// 2. an infallible reader covers the capabilities of a fallible reader. VmWriter {
unsafe { core::mem::transmute(self) } cursor: self.cursor,
end: self.end,
phantom: PhantomData,
}
} }
} }