From 2e9b19d62d29002640bacd8c118c77dbdd6992ce Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 23 Sep 2024 19:02:19 +0800 Subject: [PATCH] fail, don't panic on serialization failure this allows us to handle the error. probably should propagate on to xous-ipc --- services/pddb/src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index 85dc5dcf4..bfbdf8101 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -404,7 +404,7 @@ use num_traits::*; use rkyv::{ Archive, Place, Serialize, api::low::LowSerializer, - rancor::Panic, + rancor::Failure, ser::{Positional, allocator::SubAllocator, writer::Buffer as RkyvBuffer}, with::{ArchiveWith, SerializeWith}, }; @@ -463,7 +463,7 @@ fn main() -> ! { } /// For manual serialization to rkyv in this crate. -type Serializer<'a, 'b> = LowSerializer, SubAllocator<'a>, Panic>; +type Serializer<'a, 'b> = LowSerializer, SubAllocator<'a>, Failure>; struct Wrap<'a, F, T>(&'a T, PhantomData); impl Archive for Wrap<'_, F, T> @@ -482,7 +482,10 @@ impl<'a, 'b, F, T> Serialize> for Wrap<'_, F, T> where F: SerializeWith>, { - fn serialize(&self, serializer: &mut Serializer<'a, 'b>) -> core::result::Result { + fn serialize( + &self, + serializer: &mut Serializer<'a, 'b>, + ) -> core::result::Result { F::serialize_with(self.0, serializer) } } @@ -1914,7 +1917,7 @@ fn wrapped_main() -> ! { let wrap = Wrap(&rec, PhantomData::); let writer = RkyvBuffer::from(&mut *sbuf); let alloc = SubAllocator::new(&mut scratch); - match rkyv::api::low::to_bytes_in_with_alloc::<_, _, Panic>( + match rkyv::api::low::to_bytes_in_with_alloc::<_, _, Failure>( &wrap, writer, alloc, ) { Ok(serbuf) => { @@ -1950,7 +1953,7 @@ fn wrapped_main() -> ! { let wrap = Wrap(&rec, PhantomData::); let writer = RkyvBuffer::from(&mut *buf); let alloc = SubAllocator::new(&mut scratch); - match rkyv::api::low::to_bytes_in_with_alloc::<_, _, Panic>( + match rkyv::api::low::to_bytes_in_with_alloc::<_, _, Failure>( &wrap, writer, alloc, ) { Ok(serbuf) => {