From 240ad91c13415a8df5b7296c0d62af6354385fa0 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Mon, 3 Jul 2023 12:27:21 -0400 Subject: [PATCH] work in progress on supporting setting primitive lists from native Rust slices --- capnp/src/any_pointer.rs | 7 +++- capnp/src/any_pointer_list.rs | 2 +- capnp/src/capability_list.rs | 2 +- capnp/src/data.rs | 2 +- capnp/src/data_list.rs | 2 +- capnp/src/dynamic_list.rs | 2 +- capnp/src/dynamic_struct.rs | 2 +- capnp/src/enum_list.rs | 2 +- capnp/src/list_list.rs | 2 +- capnp/src/message.rs | 7 +++- capnp/src/primitive_list.rs | 2 +- capnp/src/schema_capnp.rs | 70 ++++++++++++++++----------------- capnp/src/struct_list.rs | 2 +- capnp/src/text.rs | 2 +- capnp/src/text_list.rs | 2 +- capnp/src/traits.rs | 6 +-- capnpc/src/codegen.rs | 4 +- capnpc/src/pointer_constants.rs | 4 +- 18 files changed, 65 insertions(+), 57 deletions(-) diff --git a/capnp/src/any_pointer.rs b/capnp/src/any_pointer.rs index c49216cd0..8da9c5f28 100644 --- a/capnp/src/any_pointer.rs +++ b/capnp/src/any_pointer.rs @@ -111,7 +111,7 @@ impl<'a> FromPointerReader<'a> for Reader<'a> { } } -impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { +impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder<'b>( mut pointer: crate::private::layout::PointerBuilder<'b>, value: Reader<'a>, @@ -165,7 +165,10 @@ impl<'a> Builder<'a> { FromPointerBuilder::init_pointer(self.builder, size) } - pub fn set_as(&mut self, value: From) -> Result<()> { + pub fn set_as>( + &mut self, + value: From, + ) -> Result<()> { SetPointerBuilder::set_pointer_builder(self.builder.reborrow(), value, false) } diff --git a/capnp/src/any_pointer_list.rs b/capnp/src/any_pointer_list.rs index 1c4e9e40c..643ffefdc 100644 --- a/capnp/src/any_pointer_list.rs +++ b/capnp/src/any_pointer_list.rs @@ -169,7 +169,7 @@ impl<'a> FromPointerBuilder<'a> for Builder<'a> { } } -impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { +impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder<'b>( mut pointer: PointerBuilder<'b>, value: Reader<'a>, diff --git a/capnp/src/capability_list.rs b/capnp/src/capability_list.rs index bca9d2380..fedb1eaec 100644 --- a/capnp/src/capability_list.rs +++ b/capnp/src/capability_list.rs @@ -256,7 +256,7 @@ where } } -impl<'a, T> crate::traits::SetPointerBuilder for Reader<'a, T> +impl<'a, T> crate::traits::SetPointerBuilder> for Reader<'a, T> where T: FromClientHook, { diff --git a/capnp/src/data.rs b/capnp/src/data.rs index 89e0c6c19..947478f61 100644 --- a/capnp/src/data.rs +++ b/capnp/src/data.rs @@ -71,7 +71,7 @@ impl<'a> crate::traits::FromPointerBuilder<'a> for Builder<'a> { } } -impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { +impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder<'b>( mut pointer: PointerBuilder<'b>, value: Reader<'a>, diff --git a/capnp/src/data_list.rs b/capnp/src/data_list.rs index f5fee2575..4a0e34c88 100644 --- a/capnp/src/data_list.rs +++ b/capnp/src/data_list.rs @@ -179,7 +179,7 @@ impl<'a> Builder<'a> { } } -impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { +impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder<'b>( mut pointer: crate::private::layout::PointerBuilder<'b>, value: Reader<'a>, diff --git a/capnp/src/dynamic_list.rs b/capnp/src/dynamic_list.rs index 4a17e3503..1bea5d035 100644 --- a/capnp/src/dynamic_list.rs +++ b/capnp/src/dynamic_list.rs @@ -381,7 +381,7 @@ impl<'a> Builder<'a> { } } -impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { +impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder<'b>( mut pointer: crate::private::layout::PointerBuilder<'b>, value: Reader<'a>, diff --git a/capnp/src/dynamic_struct.rs b/capnp/src/dynamic_struct.rs index 98845bbf5..2d9f5f557 100644 --- a/capnp/src/dynamic_struct.rs +++ b/capnp/src/dynamic_struct.rs @@ -721,7 +721,7 @@ impl<'a> Builder<'a> { } } -impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { +impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder<'b>( mut pointer: crate::private::layout::PointerBuilder<'b>, value: Reader<'a>, diff --git a/capnp/src/enum_list.rs b/capnp/src/enum_list.rs index 8fa713029..a40aa75cd 100644 --- a/capnp/src/enum_list.rs +++ b/capnp/src/enum_list.rs @@ -195,7 +195,7 @@ impl<'a, T: Into + TryFrom> Builder<'a, T> { } } -impl<'a, T> crate::traits::SetPointerBuilder for Reader<'a, T> { +impl<'a, T> crate::traits::SetPointerBuilder> for Reader<'a, T> { fn set_pointer_builder<'b>( mut pointer: crate::private::layout::PointerBuilder<'b>, value: Reader<'a, T>, diff --git a/capnp/src/list_list.rs b/capnp/src/list_list.rs index 9c7349637..eb71f6931 100644 --- a/capnp/src/list_list.rs +++ b/capnp/src/list_list.rs @@ -255,7 +255,7 @@ where } } -impl<'a, T> crate::traits::SetPointerBuilder for Reader<'a, T> +impl<'a, T> crate::traits::SetPointerBuilder> for Reader<'a, T> where T: crate::traits::Owned, { diff --git a/capnp/src/message.rs b/capnp/src/message.rs index fe40e0a7c..2862008b9 100644 --- a/capnp/src/message.rs +++ b/capnp/src/message.rs @@ -486,7 +486,7 @@ where } /// Sets the root to a deep copy of the given value. - pub fn set_root(&mut self, value: From) -> Result<()> { + pub fn set_root>(&mut self, value: From) -> Result<()> { let mut root = self.get_root_internal(); root.set_as(value) } @@ -494,7 +494,10 @@ where /// Sets the root to a canonicalized version of `value`. If this was the first action taken /// on this `Builder`, then a subsequent call to `get_segments_for_output()` should return /// a single segment, containing the full canonicalized message. - pub fn set_root_canonical(&mut self, value: From) -> Result<()> { + pub fn set_root_canonical>( + &mut self, + value: From, + ) -> Result<()> { if self.arena.is_empty() { self.arena .allocate_segment(1) diff --git a/capnp/src/primitive_list.rs b/capnp/src/primitive_list.rs index 9468c05b5..a5409581f 100644 --- a/capnp/src/primitive_list.rs +++ b/capnp/src/primitive_list.rs @@ -231,7 +231,7 @@ impl<'a, T: PrimitiveElement> Builder<'a, T> { } } -impl<'a, T> crate::traits::SetPointerBuilder for Reader<'a, T> +impl<'a, T> crate::traits::SetPointerBuilder> for Reader<'a, T> where T: PrimitiveElement, { diff --git a/capnp/src/schema_capnp.rs b/capnp/src/schema_capnp.rs index 4f92ee288..36b640d5e 100644 --- a/capnp/src/schema_capnp.rs +++ b/capnp/src/schema_capnp.rs @@ -245,7 +245,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -958,7 +958,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -1252,7 +1252,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -1588,7 +1588,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -1981,7 +1981,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -2304,7 +2304,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -2771,7 +2771,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -3098,7 +3098,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -3476,7 +3476,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -3874,7 +3874,7 @@ pub mod node { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -4514,7 +4514,7 @@ pub mod field { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -5008,7 +5008,7 @@ pub mod field { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -5404,7 +5404,7 @@ pub mod field { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -5681,7 +5681,7 @@ pub mod field { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -6010,7 +6010,7 @@ pub mod enumerant { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -6378,7 +6378,7 @@ pub mod superclass { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -6765,7 +6765,7 @@ pub mod method { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -7347,7 +7347,7 @@ pub mod type_ { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -8026,7 +8026,7 @@ pub mod type_ { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -8335,7 +8335,7 @@ pub mod type_ { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -8665,7 +8665,7 @@ pub mod type_ { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -8996,7 +8996,7 @@ pub mod type_ { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -9323,7 +9323,7 @@ pub mod type_ { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -9667,7 +9667,7 @@ pub mod type_ { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -10028,7 +10028,7 @@ pub mod type_ { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -10334,7 +10334,7 @@ pub mod type_ { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -10618,7 +10618,7 @@ pub mod brand { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -10944,7 +10944,7 @@ pub mod brand { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -11332,7 +11332,7 @@ pub mod brand { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -11737,7 +11737,7 @@ pub mod value { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -12531,7 +12531,7 @@ pub mod annotation { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -13028,7 +13028,7 @@ pub mod capnp_version { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -13401,7 +13401,7 @@ pub mod code_generator_request { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -13901,7 +13901,7 @@ pub mod code_generator_request { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, @@ -14300,7 +14300,7 @@ pub mod code_generator_request { } } - impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { + impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder( mut pointer: crate::private::layout::PointerBuilder<'_>, value: Self, diff --git a/capnp/src/struct_list.rs b/capnp/src/struct_list.rs index 7c8103e23..20c44193d 100644 --- a/capnp/src/struct_list.rs +++ b/capnp/src/struct_list.rs @@ -259,7 +259,7 @@ where } } -impl<'a, T> crate::traits::SetPointerBuilder for Reader<'a, T> +impl<'a, T> crate::traits::SetPointerBuilder> for Reader<'a, T> where T: crate::traits::OwnedStruct, { diff --git a/capnp/src/text.rs b/capnp/src/text.rs index 50344d7b9..f0a30f012 100644 --- a/capnp/src/text.rs +++ b/capnp/src/text.rs @@ -140,7 +140,7 @@ impl<'a> crate::traits::FromPointerBuilder<'a> for Builder<'a> { } } -impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { +impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder<'b>( mut pointer: crate::private::layout::PointerBuilder<'b>, value: Reader<'a>, diff --git a/capnp/src/text_list.rs b/capnp/src/text_list.rs index 72cbd2647..a919142ad 100644 --- a/capnp/src/text_list.rs +++ b/capnp/src/text_list.rs @@ -178,7 +178,7 @@ impl<'a> Builder<'a> { } } -impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { +impl<'a> crate::traits::SetPointerBuilder for Reader<'a> { fn set_pointer_builder<'b>( mut pointer: crate::private::layout::PointerBuilder<'b>, value: Reader<'a>, diff --git a/capnp/src/traits.rs b/capnp/src/traits.rs index 39e050ab4..0f01fef39 100644 --- a/capnp/src/traits.rs +++ b/capnp/src/traits.rs @@ -59,12 +59,12 @@ pub trait FromPointerReader<'a>: Sized { /// nonetheless as a type parameter, e.g. for a generic container that owns a Cap'n Proto /// message of type `T: capnp::traits::Owned`. pub trait Owned: crate::introspect::Introspect { - type Reader<'a>: FromPointerReader<'a> + SetPointerBuilder; + type Reader<'a>: FromPointerReader<'a> + SetPointerBuilder; type Builder<'a>: FromPointerBuilder<'a>; } pub trait OwnedStruct: crate::introspect::Introspect { - type Reader<'a>: From> + SetPointerBuilder + IntoInternalStructReader<'a>; + type Reader<'a>: From> + SetPointerBuilder + IntoInternalStructReader<'a>; type Builder<'a>: From> + HasStructSize; } @@ -80,7 +80,7 @@ pub trait FromPointerBuilder<'a>: Sized { ) -> Result; } -pub trait SetPointerBuilder { +pub trait SetPointerBuilder { fn set_pointer_builder( builder: PointerBuilder<'_>, from: Self, diff --git a/capnpc/src/codegen.rs b/capnpc/src/codegen.rs index 7cd7ef89c..0371452b4 100644 --- a/capnpc/src/codegen.rs +++ b/capnpc/src/codegen.rs @@ -2305,7 +2305,7 @@ fn generate_node( from_pointer_builder_impl, Line(fmt!(ctx, - "impl <'a,{0}> {capnp}::traits::SetPointerBuilder for Reader<'a,{0}> {1} {{", + "impl <'a,{0}> {capnp}::traits::SetPointerBuilder> for Reader<'a,{0}> {1} {{", params.params, params.where_clause)), indent(Line(fmt!(ctx,"fn set_pointer_builder(mut pointer: {capnp}::private::layout::PointerBuilder<'_>, value: Self, canonicalize: bool) -> {capnp}::Result<()> {{ pointer.set_struct(&value.reader, canonicalize) }}"))), line("}"), @@ -2701,7 +2701,7 @@ fn generate_node( mod_interior.push(Branch(vec![ Line(fmt!(ctx, - "impl <{0}> {capnp}::traits::SetPointerBuilder for Client<{0}> {1} {{", + "impl <{0}> {capnp}::traits::SetPointerBuilder> for Client<{0}> {1} {{", params.params, params.where_clause)), indent(vec![ Line(fmt!(ctx,"fn set_pointer_builder(mut pointer: {capnp}::private::layout::PointerBuilder<'_>, from: Self, _canonicalize: bool) -> {capnp}::Result<()> {{")), diff --git a/capnpc/src/pointer_constants.rs b/capnpc/src/pointer_constants.rs index ba528648a..c8131f33c 100644 --- a/capnpc/src/pointer_constants.rs +++ b/capnpc/src/pointer_constants.rs @@ -30,7 +30,9 @@ pub struct WordArrayDeclarationOptions { pub public: bool, } -fn word_array_declaration_aux( +fn word_array_declaration_aux< + T: ::capnp::traits::SetPointerBuilder, +>( ctx: &GeneratorContext, name: &str, value: T,