Skip to content

Commit

Permalink
clean up API even further
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnie committed Sep 17, 2024
1 parent c259d55 commit 3120b5d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions planning/rkyv-migration2/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn send_message(connection: CID, mut message: Message) -> core::result::Resu
// emulated TextView
let mut buffer =
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let mut tv = buffer.to_original::<crate::testcases::TextView, _, rkyv::rancor::Error>().unwrap();
let mut tv = buffer.to_original::<crate::testcases::TextView, _>().unwrap();

println!("MSG: TextView");
println!("Contents: {:?}", tv);
Expand Down Expand Up @@ -218,15 +218,14 @@ impl<'buf> Buffer<'buf> {
self.replace_inner::<Identity, T>(src)
}

pub fn to_original<T, U, E>(&self) -> core::result::Result<T, E>
pub fn to_original<T, U>(&self) -> core::result::Result<T, ()>
where
T: rkyv::Archive<Archived = U>,
U: Portable,
E: std::fmt::Debug,
<T as Archive>::Archived: Deserialize<T, Strategy<rkyv::de::Pool, E>>,
<T as Archive>::Archived: Deserialize<T, Strategy<rkyv::de::Pool, rkyv::rancor::Error>>,
{
let r = unsafe { rkyv::access_unchecked::<U>(&self.slice[..self.used]) };
Ok(rkyv::deserialize::<T, E>(r).unwrap())
Ok(rkyv::deserialize::<T, rkyv::rancor::Error>(r).unwrap())
}

pub fn as_flat<T, U>(&self) -> core::result::Result<&U, ()>
Expand Down
4 changes: 2 additions & 2 deletions planning/rkyv-migration2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() {
let f = buf.as_flat::<Test, _>().unwrap();
println!("f: {:?}", f);

let t1 = buf.to_original::<Test, _, Error>().unwrap();
let t1 = buf.to_original::<Test, _>().unwrap();
println!("t copy 1: {:?}", t1);

println!("buf.slice: {:x?}", &buf[..buf.used()]);
Expand Down Expand Up @@ -74,7 +74,7 @@ fn main() {
match tv_buf.lend_mut(1, 1) {
Ok(r) => {
println!("Returned {:?}", r);
let mut tv_orig = tv_buf.to_original::<TextView, _, Error>().unwrap();
let mut tv_orig = tv_buf.to_original::<TextView, _>().unwrap();
println!("bounds_computed: {:?}", tv_orig.bounds_computed);
assert_eq!(tv_orig.bounds_computed.unwrap().tl.x, 42);
assert_eq!(tv_orig.bounds_computed.unwrap().tl.y, 42);
Expand Down
2 changes: 1 addition & 1 deletion planning/rkyv-migration2/src/testcases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub fn draw_textview(conn: xous::CID, tv: &mut TextView) -> Result<(), xous::Err
let mut buf = crate::Buffer::into_buf(tv);
buf.lend_mut(conn, Opcode::DrawTextView.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;

let tvr = buf.to_original::<TextView, _, rkyv::rancor::Error>().unwrap();
let tvr = buf.to_original::<TextView, _>().unwrap();
tv.bounds_computed = tvr.bounds_computed;
tv.cursor = tvr.cursor;
tv.overflow = tvr.overflow;
Expand Down

0 comments on commit 3120b5d

Please sign in to comment.