Skip to content

Commit

Permalink
improve doc comment for dynamic_struct::Reader::has(), and increase t…
Browse files Browse the repository at this point in the history
…est coverage
  • Loading branch information
dwrensha committed Nov 30, 2023
1 parent 2b06400 commit c7e4245
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion capnp/src/dynamic_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
assert_eq!(self.schema.raw, field.parent.raw);
let proto = field.get_proto();
Expand Down
2 changes: 2 additions & 0 deletions capnpc/test/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c7e4245

Please sign in to comment.