diff --git a/capnp/src/text_list.rs b/capnp/src/text_list.rs index 72cbd2647..3d4b7476d 100644 --- a/capnp/src/text_list.rs +++ b/capnp/src/text_list.rs @@ -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> { diff --git a/capnpc/test/test_util.rs b/capnpc/test/test_util.rs index c4e38ffa7..9f794f2cc 100644 --- a/capnpc/test/test_util.rs +++ b/capnpc/test/test_util.rs @@ -187,6 +187,15 @@ pub fn init_test_message(mut builder: test_all_types::Builder<'_>) { // ... + { + let mut text_list = builder.reborrow().init_text_list(3); + text_list.set(0, "plugh".into()); + text_list.set(1, "xyzzy".into()); + text_list.set(2, "thud".into()); + } + + // ... + { let mut struct_list = builder.reborrow().init_struct_list(3); struct_list @@ -393,6 +402,16 @@ check_test_message_impl(($mod:ident::$typ:ident) => ( // ... + { + let mut text_list = reader.reborrow().get_text_list().unwrap(); + assert_eq!(3, text_list.len()); + assert_eq!("plugh", text_list.reborrow().get(0).unwrap()); + assert_eq!("xyzzy", text_list.reborrow().get(1).unwrap()); + assert_eq!("thud", text_list.reborrow().get(2).unwrap()); + } + + // ... + { let mut struct_list = reader.reborrow().get_struct_list().unwrap(); assert_eq!(3, struct_list.len());