Skip to content

Commit

Permalink
add missing Debug impls for primitive_list::Reader etc
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Dec 9, 2023
1 parent 53d2a4d commit 540b092
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 0 deletions.
9 changes: 9 additions & 0 deletions capnp/src/any_pointer_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,12 @@ impl<'a> From<Builder<'a>> for crate::dynamic_value::Builder<'a> {
))
}
}

impl<'a> core::fmt::Debug for Reader<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(
&::core::convert::Into::<crate::dynamic_value::Reader<'_>>::into(*self),
f,
)
}
}
9 changes: 9 additions & 0 deletions capnp/src/capability_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,12 @@ impl<'a, T: FromClientHook> From<Builder<'a, T>> for crate::dynamic_value::Build
))
}
}

impl<'a, T: FromClientHook> core::fmt::Debug for Reader<'a, T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(
&::core::convert::Into::<crate::dynamic_value::Reader<'_>>::into(self.reborrow()),
f,
)
}
}
9 changes: 9 additions & 0 deletions capnp/src/data_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,12 @@ impl<'a> From<Builder<'a>> for crate::dynamic_value::Builder<'a> {
})
}
}

impl<'a> core::fmt::Debug for Reader<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(
&::core::convert::Into::<crate::dynamic_value::Reader<'_>>::into(*self),
f,
)
}
}
9 changes: 9 additions & 0 deletions capnp/src/dynamic_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,12 @@ impl<'a> crate::traits::SetPointerBuilder for Reader<'a> {
pointer.set_list(&value.reader, canonicalize)
}
}

impl<'a> core::fmt::Debug for Reader<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(
&::core::convert::Into::<crate::dynamic_value::Reader<'_>>::into(*self),
f,
)
}
}
9 changes: 9 additions & 0 deletions capnp/src/dynamic_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,3 +782,12 @@ impl<'a> crate::traits::SetPointerBuilder for Reader<'a> {
pointer.set_struct(&value.reader, canonicalize)
}
}

impl<'a> core::fmt::Debug for Reader<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(
&::core::convert::Into::<crate::dynamic_value::Reader<'_>>::into(*self),
f,
)
}
}
11 changes: 11 additions & 0 deletions capnp/src/enum_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,14 @@ impl<'a, T: TryFrom<u16, Error = NotInSchema> + crate::introspect::Introspect> F
))
}
}

impl<'a, T: Copy + TryFrom<u16, Error = NotInSchema> + crate::introspect::Introspect>
core::fmt::Debug for Reader<'a, T>
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(
&::core::convert::Into::<crate::dynamic_value::Reader<'_>>::into(*self),
f,
)
}
}
9 changes: 9 additions & 0 deletions capnp/src/list_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,12 @@ impl<'a, T: crate::traits::Owned> From<Builder<'a, T>> for crate::dynamic_value:
))
}
}

impl<'a, T: crate::traits::Owned> core::fmt::Debug for Reader<'a, T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(
&::core::convert::Into::<crate::dynamic_value::Reader<'_>>::into(*self),
f,
)
}
}
11 changes: 11 additions & 0 deletions capnp/src/primitive_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,14 @@ impl<'a, T: PrimitiveElement + crate::introspect::Introspect> From<Builder<'a, T
))
}
}

impl<'a, T: Copy + PrimitiveElement + crate::introspect::Introspect> core::fmt::Debug
for Reader<'a, T>
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(
&::core::convert::Into::<crate::dynamic_value::Reader<'_>>::into(*self),
f,
)
}
}
9 changes: 9 additions & 0 deletions capnp/src/text_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,12 @@ impl<'a> From<Builder<'a>> for crate::dynamic_value::Builder<'a> {
})
}
}

impl<'a> core::fmt::Debug for Reader<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Debug::fmt(
&::core::convert::Into::<crate::dynamic_value::Reader<'_>>::into(*self),
f,
)
}
}
72 changes: 72 additions & 0 deletions capnpc/test/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,75 @@ fn test_stringify_union_list() {
]"#
);
}

#[test]
fn test_stringify_prim_list() {
use capnp::primitive_list;
let mut message = message::Builder::new_default();
let mut root: primitive_list::Builder<'_, u16> = message.initn_root(3);
root.set(0, 5);
root.set(1, 6);
root.set(2, 7);

let stringified = format!("{:?}", root.into_reader());
assert_eq!(stringified, "[5, 6, 7]");
}

#[test]
fn test_stringify_enum_list() {
use crate::test_capnp::TestEnum;
use capnp::enum_list;
let mut message = message::Builder::new_default();
let mut root: enum_list::Builder<'_, TestEnum> = message.initn_root(2);
root.set(0, TestEnum::Bar);
root.set(1, TestEnum::Garply);

let stringified = format!("{:?}", root.into_reader());
assert_eq!(stringified, "[bar, garply]");
}

#[test]
fn test_stringify_text_list() {
use capnp::text_list;
let mut message = message::Builder::new_default();
let mut root: text_list::Builder<'_> = message.initn_root(4);
root.set(0, "abcd".into());
root.set(1, "efgh".into());
root.set(2, "ijkl".into());
root.set(3, "mnop".into());

let stringified = format!("{:?}", root.into_reader());
assert_eq!(stringified, "[\"abcd\", \"efgh\", \"ijkl\", \"mnop\"]");
}

#[test]
fn test_stringify_data_list() {
let mut message = message::Builder::new_default();
let mut root: capnp::data_list::Builder<'_> = message.initn_root(2);
root.set(0, &[11, 12]);
root.set(1, &[22, 23]);

let stringified = format!("{:?}", root.into_reader());
assert_eq!(stringified, "[0x\"0b0c\", 0x\"1617\"]");
}

#[test]
fn test_stringify_list_list() {
use capnp::{list_list, primitive_list};
let mut message = message::Builder::new_default();
let mut root: list_list::Builder<'_, primitive_list::Owned<i32>> = message.initn_root(2);
{
let mut l0 = root.reborrow().init(0, 3);
l0.set(0, 1111);
l0.set(1, 2222);
l0.set(2, 3333);
}

{
let mut l1 = root.reborrow().init(1, 1);
l1.set(0, 123456);
}

let stringified = format!("{:?}", root.into_reader());
assert_eq!(stringified, "[[1111, 2222, 3333], [123456]]");
}

0 comments on commit 540b092

Please sign in to comment.