Skip to content

Commit

Permalink
work in progress on supporting setting primitive lists from native Ru…
Browse files Browse the repository at this point in the history
…st slices
  • Loading branch information
dwrensha committed Aug 29, 2023
1 parent c702d16 commit 240ad91
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 57 deletions.
7 changes: 5 additions & 2 deletions capnp/src/any_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'a> FromPointerReader<'a> for Reader<'a> {
}
}

impl<'a> crate::traits::SetPointerBuilder for Reader<'a> {
impl<'a> crate::traits::SetPointerBuilder<Owned> for Reader<'a> {
fn set_pointer_builder<'b>(
mut pointer: crate::private::layout::PointerBuilder<'b>,
value: Reader<'a>,
Expand Down Expand Up @@ -165,7 +165,10 @@ impl<'a> Builder<'a> {
FromPointerBuilder::init_pointer(self.builder, size)
}

pub fn set_as<From: SetPointerBuilder>(&mut self, value: From) -> Result<()> {
pub fn set_as<From: SetPointerBuilder<impl crate::traits::Owned>>(
&mut self,
value: From,
) -> Result<()> {
SetPointerBuilder::set_pointer_builder(self.builder.reborrow(), value, false)
}

Expand Down
2 changes: 1 addition & 1 deletion capnp/src/any_pointer_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<'a> FromPointerBuilder<'a> for Builder<'a> {
}
}

impl<'a> crate::traits::SetPointerBuilder for Reader<'a> {
impl<'a> crate::traits::SetPointerBuilder<Owned> for Reader<'a> {
fn set_pointer_builder<'b>(
mut pointer: PointerBuilder<'b>,
value: Reader<'a>,
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/capability_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ where
}
}

impl<'a, T> crate::traits::SetPointerBuilder for Reader<'a, T>
impl<'a, T> crate::traits::SetPointerBuilder<Owned<T>> for Reader<'a, T>
where
T: FromClientHook,
{
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Owned> for Reader<'a> {
fn set_pointer_builder<'b>(
mut pointer: PointerBuilder<'b>,
value: Reader<'a>,
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/data_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<'a> Builder<'a> {
}
}

impl<'a> crate::traits::SetPointerBuilder for Reader<'a> {
impl<'a> crate::traits::SetPointerBuilder<Owned> for Reader<'a> {
fn set_pointer_builder<'b>(
mut pointer: crate::private::layout::PointerBuilder<'b>,
value: Reader<'a>,
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/dynamic_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl<'a> Builder<'a> {
}
}

impl<'a> crate::traits::SetPointerBuilder for Reader<'a> {
impl<'a> crate::traits::SetPointerBuilder<crate::any_pointer::Owned> for Reader<'a> {
fn set_pointer_builder<'b>(
mut pointer: crate::private::layout::PointerBuilder<'b>,
value: Reader<'a>,
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/dynamic_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ impl<'a> Builder<'a> {
}
}

impl<'a> crate::traits::SetPointerBuilder for Reader<'a> {
impl<'a> crate::traits::SetPointerBuilder<crate::any_pointer::Owned> for Reader<'a> {
fn set_pointer_builder<'b>(
mut pointer: crate::private::layout::PointerBuilder<'b>,
value: Reader<'a>,
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/enum_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<'a, T: Into<u16> + TryFrom<u16, Error = NotInSchema>> Builder<'a, T> {
}
}

impl<'a, T> crate::traits::SetPointerBuilder for Reader<'a, T> {
impl<'a, T> crate::traits::SetPointerBuilder<Owned<T>> for Reader<'a, T> {
fn set_pointer_builder<'b>(
mut pointer: crate::private::layout::PointerBuilder<'b>,
value: Reader<'a, T>,
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/list_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ where
}
}

impl<'a, T> crate::traits::SetPointerBuilder for Reader<'a, T>
impl<'a, T> crate::traits::SetPointerBuilder<Owned<T>> for Reader<'a, T>
where
T: crate::traits::Owned,
{
Expand Down
7 changes: 5 additions & 2 deletions capnp/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,18 @@ where
}

/// Sets the root to a deep copy of the given value.
pub fn set_root<From: SetPointerBuilder>(&mut self, value: From) -> Result<()> {
pub fn set_root<From: SetPointerBuilder<impl Owned>>(&mut self, value: From) -> Result<()> {
let mut root = self.get_root_internal();
root.set_as(value)
}

/// 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<From: SetPointerBuilder>(&mut self, value: From) -> Result<()> {
pub fn set_root_canonical<From: SetPointerBuilder<impl Owned>>(
&mut self,
value: From,
) -> Result<()> {
if self.arena.is_empty() {
self.arena
.allocate_segment(1)
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/primitive_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Owned<T>> for Reader<'a, T>
where
T: PrimitiveElement,
{
Expand Down
Loading

0 comments on commit 240ad91

Please sign in to comment.