diff --git a/capnp/src/any_pointer_list.rs b/capnp/src/any_pointer_list.rs index 1c4e9e40c..c50d7af10 100644 --- a/capnp/src/any_pointer_list.rs +++ b/capnp/src/any_pointer_list.rs @@ -206,3 +206,12 @@ impl<'a> From> 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::>::into(*self), + f, + ) + } +} diff --git a/capnp/src/capability_list.rs b/capnp/src/capability_list.rs index 083794e07..8da9edcfe 100644 --- a/capnp/src/capability_list.rs +++ b/capnp/src/capability_list.rs @@ -295,3 +295,12 @@ impl<'a, T: FromClientHook> From> 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::>::into(self.reborrow()), + f, + ) + } +} diff --git a/capnp/src/data_list.rs b/capnp/src/data_list.rs index 2cd1a6a6c..556e63f50 100644 --- a/capnp/src/data_list.rs +++ b/capnp/src/data_list.rs @@ -222,3 +222,12 @@ impl<'a> From> 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::>::into(*self), + f, + ) + } +} diff --git a/capnp/src/dynamic_list.rs b/capnp/src/dynamic_list.rs index f2c93e1cb..f68dbae42 100644 --- a/capnp/src/dynamic_list.rs +++ b/capnp/src/dynamic_list.rs @@ -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::>::into(*self), + f, + ) + } +} diff --git a/capnp/src/dynamic_struct.rs b/capnp/src/dynamic_struct.rs index 8bceb5df7..88d8e7402 100644 --- a/capnp/src/dynamic_struct.rs +++ b/capnp/src/dynamic_struct.rs @@ -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::>::into(*self), + f, + ) + } +} diff --git a/capnp/src/enum_list.rs b/capnp/src/enum_list.rs index 8fa713029..74dad4076 100644 --- a/capnp/src/enum_list.rs +++ b/capnp/src/enum_list.rs @@ -235,3 +235,14 @@ impl<'a, T: TryFrom + crate::introspect::Introspect> F )) } } + +impl<'a, T: Copy + TryFrom + 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::>::into(*self), + f, + ) + } +} diff --git a/capnp/src/list_list.rs b/capnp/src/list_list.rs index 7c3156095..ef5bae001 100644 --- a/capnp/src/list_list.rs +++ b/capnp/src/list_list.rs @@ -294,3 +294,12 @@ impl<'a, T: crate::traits::Owned> From> 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::>::into(*self), + f, + ) + } +} diff --git a/capnp/src/primitive_list.rs b/capnp/src/primitive_list.rs index 0a25a3b83..947ffd249 100644 --- a/capnp/src/primitive_list.rs +++ b/capnp/src/primitive_list.rs @@ -282,3 +282,14 @@ impl<'a, T: PrimitiveElement + crate::introspect::Introspect> From 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::>::into(*self), + f, + ) + } +} diff --git a/capnp/src/text_list.rs b/capnp/src/text_list.rs index ae99e77f5..8fcfb7bb5 100644 --- a/capnp/src/text_list.rs +++ b/capnp/src/text_list.rs @@ -220,3 +220,12 @@ impl<'a> From> 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::>::into(*self), + f, + ) + } +} diff --git a/capnpc/test/dynamic.rs b/capnpc/test/dynamic.rs index bfa2d182c..bd8f373ce 100644 --- a/capnpc/test/dynamic.rs +++ b/capnpc/test/dynamic.rs @@ -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> = 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]]"); +}