Skip to content

Commit

Permalink
cover data_list too
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Nov 29, 2023
1 parent a4fcf1b commit 0fc9a04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions capnp/src/data_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl<'a> Reader<'a> {
let l = self.len();
ListIter::new(self, l)
}

pub fn reborrow<'b>(&'b self) -> Reader<'b> {
Reader {
reader: self.reader,
}
}
}

impl<'a> FromPointerReader<'a> for Reader<'a> {
Expand Down
15 changes: 13 additions & 2 deletions capnpc/test/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ pub fn init_test_message(mut builder: test_all_types::Builder<'_>) {
text_list.set(2, "thud".into());
}

// ...
{
let mut data_list = builder.reborrow().init_data_list(3);
data_list.set(0, b"oops");
data_list.set(1, b"exhausted");
data_list.set(2, b"rfc3092");
}

{
let mut struct_list = builder.reborrow().init_struct_list(3);
Expand Down Expand Up @@ -410,7 +415,13 @@ check_test_message_impl(($mod:ident::$typ:ident) => (
assert_eq!("thud", text_list.reborrow().get(2).unwrap());
}

// ...
{
let mut data_list = reader.reborrow().get_data_list().unwrap();
assert_eq!(3, data_list.len());
assert_eq!(b"oops", data_list.reborrow().get(0).unwrap());
assert_eq!(b"exhausted", data_list.reborrow().get(1).unwrap());
assert_eq!(b"rfc3092", data_list.reborrow().get(2).unwrap());
}

{
let mut struct_list = reader.reborrow().get_struct_list().unwrap();
Expand Down

0 comments on commit 0fc9a04

Please sign in to comment.