diff --git a/capnp/src/any_pointer_list.rs b/capnp/src/any_pointer_list.rs index 3df257f7e..d1bf29da6 100644 --- a/capnp/src/any_pointer_list.rs +++ b/capnp/src/any_pointer_list.rs @@ -95,9 +95,9 @@ impl<'a> FromPointerReader<'a> for Reader<'a> { } } -impl<'a> crate::traits::IntoInternalListReader<'a> for Reader<'a> { - fn into_internal_list_reader(self) -> ListReader<'a> { - self.reader +impl<'a> From> for ListReader<'a> { + fn from(value: Reader<'a>) -> Self { + value.reader } } diff --git a/capnp/src/data_list.rs b/capnp/src/data_list.rs index 58e90c738..a717c6fcb 100644 --- a/capnp/src/data_list.rs +++ b/capnp/src/data_list.rs @@ -93,9 +93,9 @@ impl<'a> Reader<'a> { } } -impl<'a> crate::traits::IntoInternalListReader<'a> for Reader<'a> { - fn into_internal_list_reader(self) -> ListReader<'a> { - self.reader +impl<'a> From> for ListReader<'a> { + fn from(value: Reader<'a>) -> Self { + value.reader } } diff --git a/capnp/src/enum_list.rs b/capnp/src/enum_list.rs index 1927b7913..19fded169 100644 --- a/capnp/src/enum_list.rs +++ b/capnp/src/enum_list.rs @@ -102,12 +102,12 @@ impl<'a, T: FromU16> Reader<'a, T> { } } -impl<'a, T> crate::traits::IntoInternalListReader<'a> for Reader<'a, T> +impl<'a, T> From> for ListReader<'a> where T: PrimitiveElement, { - fn into_internal_list_reader(self) -> ListReader<'a> { - self.reader + fn from(value: Reader<'a, T>) -> Self { + value.reader } } diff --git a/capnp/src/list_list.rs b/capnp/src/list_list.rs index c07a7e70c..25b1534a2 100644 --- a/capnp/src/list_list.rs +++ b/capnp/src/list_list.rs @@ -129,12 +129,12 @@ where } } -impl<'a, T> crate::traits::IntoInternalListReader<'a> for Reader<'a, T> +impl<'a, T> From> for ListReader<'a> where T: crate::traits::Owned, { - fn into_internal_list_reader(self) -> ListReader<'a> { - self.reader + fn from(value: Reader<'a, T>) -> Self { + value.reader } } @@ -234,13 +234,12 @@ where pub fn set<'b>(&self, index: u32, value: T::Reader<'a>) -> Result<()> where - T::Reader<'a>: crate::traits::IntoInternalListReader<'b>, + T::Reader<'a>: Into>, { - use crate::traits::IntoInternalListReader; assert!(index < self.len()); self.builder .get_pointer_element(index) - .set_list(&value.into_internal_list_reader(), false) + .set_list(&value.into(), false) } } diff --git a/capnp/src/primitive_list.rs b/capnp/src/primitive_list.rs index 2ffce2597..9a838e8d7 100644 --- a/capnp/src/primitive_list.rs +++ b/capnp/src/primitive_list.rs @@ -120,12 +120,12 @@ impl<'a, T: PrimitiveElement> Reader<'a, T> { } } -impl<'a, T> crate::traits::IntoInternalListReader<'a> for Reader<'a, T> +impl<'a, T> From> for ListReader<'a> where T: PrimitiveElement, { - fn into_internal_list_reader(self) -> ListReader<'a> { - self.reader + fn from(value: Reader<'a, T>) -> Self { + value.reader } } diff --git a/capnp/src/raw.rs b/capnp/src/raw.rs index 5883b1207..1e3c2b691 100644 --- a/capnp/src/raw.rs +++ b/capnp/src/raw.rs @@ -20,7 +20,7 @@ //! Functions providing low level access to encoded data. -use crate::traits::{IntoInternalListReader, IntoInternalStructReader}; +use crate::{private::layout::ListReader, traits::IntoInternalStructReader}; /// Gets a slice view of the data section of a struct. pub fn get_struct_data_section<'a, T>(value: T) -> &'a [u8] @@ -47,23 +47,23 @@ where /// Gets the size of the elements in a list. pub fn get_list_element_size<'a, T>(value: T) -> crate::private::layout::ElementSize where - T: IntoInternalListReader<'a>, + T: Into>, { - value.into_internal_list_reader().get_element_size() + value.into().get_element_size() } /// Gets the number of bits between successive elements in a list. pub fn get_list_step_size_in_bits<'a, T>(value: T) -> u32 where - T: IntoInternalListReader<'a>, + T: Into>, { - value.into_internal_list_reader().get_step_size_in_bits() + value.into().get_step_size_in_bits() } /// Gets a slice view of a list, excluding any tag word. pub fn get_list_bytes<'a, T>(value: T) -> &'a [u8] where - T: IntoInternalListReader<'a>, + T: Into>, { - value.into_internal_list_reader().into_raw_bytes() + value.into().into_raw_bytes() } diff --git a/capnp/src/struct_list.rs b/capnp/src/struct_list.rs index f421f98c2..667161198 100644 --- a/capnp/src/struct_list.rs +++ b/capnp/src/struct_list.rs @@ -144,12 +144,12 @@ where } } -impl<'a, T> crate::traits::IntoInternalListReader<'a> for Reader<'a, T> +impl<'a, T> From> for ListReader<'a> where T: crate::traits::OwnedStruct, { - fn into_internal_list_reader(self) -> ListReader<'a> { - self.reader + fn from(value: Reader<'a, T>) -> Self { + value.reader } } diff --git a/capnp/src/text_list.rs b/capnp/src/text_list.rs index 78a52e814..658400750 100644 --- a/capnp/src/text_list.rs +++ b/capnp/src/text_list.rs @@ -93,9 +93,9 @@ impl<'a> Reader<'a> { } } -impl<'a> crate::traits::IntoInternalListReader<'a> for Reader<'a> { - fn into_internal_list_reader(self) -> ListReader<'a> { - self.reader +impl<'a> From> for ListReader<'a> { + fn from(value: Reader<'a>) -> Self { + value.reader } } diff --git a/capnp/src/traits.rs b/capnp/src/traits.rs index 7ce0ef33e..69fbc616d 100644 --- a/capnp/src/traits.rs +++ b/capnp/src/traits.rs @@ -20,7 +20,7 @@ // THE SOFTWARE. use crate::private::layout::{ - CapTable, ListReader, PointerBuilder, PointerReader, StructBuilder, StructReader, StructSize, + CapTable, PointerBuilder, PointerReader, StructBuilder, StructReader, StructSize, }; use crate::Result; @@ -42,10 +42,6 @@ pub trait FromStructBuilder<'a> { fn new(struct_builder: StructBuilder<'a>) -> Self; } -pub trait IntoInternalListReader<'a> { - fn into_internal_list_reader(self) -> ListReader<'a>; -} - pub trait FromPointerReader<'a>: Sized { fn get_from_pointer( reader: &PointerReader<'a>,