From c7e42459c69e88bc02a096c1de80406780937001 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Wed, 29 Nov 2023 19:11:36 -0500 Subject: [PATCH] improve doc comment for dynamic_struct::Reader::has(), and increase test coverage --- capnp/src/dynamic_struct.rs | 4 +++- capnpc/test/dynamic.rs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/capnp/src/dynamic_struct.rs b/capnp/src/dynamic_struct.rs index d0244fc29..8bceb5df7 100644 --- a/capnp/src/dynamic_struct.rs +++ b/capnp/src/dynamic_struct.rs @@ -194,7 +194,9 @@ impl<'a> Reader<'a> { } } - /// Returns `false` if the field is a pointer and the pointer is null. + /// On a field that is part of a union, returns `true` if the field + /// is active in the union and is not a null pointer. On non-union fields, + /// returns `true` if the field is not a null pointer. pub fn has(&self, field: Field) -> Result { assert_eq!(self.schema.raw, field.parent.raw); let proto = field.get_proto(); diff --git a/capnpc/test/dynamic.rs b/capnpc/test/dynamic.rs index 815cc9c74..d42e5ae8c 100644 --- a/capnpc/test/dynamic.rs +++ b/capnpc/test/dynamic.rs @@ -67,6 +67,8 @@ fn test_unions() { let dynamic: dynamic_struct::Reader<'_> = dynamic.downcast(); { let u: dynamic_struct::Reader<'_> = dynamic.get_named("union0").unwrap().downcast(); + assert!(u.has_named("u0f1s32").unwrap()); + assert!(!u.has_named("u0f1s16").unwrap()); assert_eq!( "u0f1s32", u.which().unwrap().unwrap().get_proto().get_name().unwrap()