Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove 'FromStructReader' trait #337

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
284 changes: 142 additions & 142 deletions capnp-rpc/src/rpc_capnp.rs

Large diffs are not rendered by default.

84 changes: 42 additions & 42 deletions capnp-rpc/src/rpc_twoparty_capnp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ pub mod vat_id {
impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> {
const TYPE_ID: u64 = _private::TYPE_ID;
}
impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> {
fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Self {
Self { reader, }
impl<'a,> From<::capnp::private::layout::StructReader<'a>> for Reader<'a,> {
fn from(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> {
Reader { reader, }
}
}

impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> {
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Self> {
::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?))
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Reader<'a,>> {
::core::result::Result::Ok(reader.get_struct(default)?.into())
}
}

Expand Down Expand Up @@ -112,13 +112,13 @@ pub mod vat_id {

impl <'a,> Builder<'a,> {
pub fn into_reader(self) -> Reader<'a,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}
pub fn reborrow(&mut self) -> Builder<'_,> {
Builder { .. *self }
}
pub fn reborrow_as_reader(&self) -> Reader<'_,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}

pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> {
Expand Down Expand Up @@ -160,15 +160,15 @@ pub mod provision_id {
impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> {
const TYPE_ID: u64 = _private::TYPE_ID;
}
impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> {
fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Self {
Self { reader, }
impl<'a,> From<::capnp::private::layout::StructReader<'a>> for Reader<'a,> {
fn from(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> {
Reader { reader, }
}
}

impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> {
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Self> {
::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?))
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Reader<'a,>> {
::core::result::Result::Ok(reader.get_struct(default)?.into())
}
}

Expand Down Expand Up @@ -232,13 +232,13 @@ pub mod provision_id {

impl <'a,> Builder<'a,> {
pub fn into_reader(self) -> Reader<'a,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}
pub fn reborrow(&mut self) -> Builder<'_,> {
Builder { .. *self }
}
pub fn reborrow_as_reader(&self) -> Reader<'_,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}

pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> {
Expand Down Expand Up @@ -280,15 +280,15 @@ pub mod recipient_id {
impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> {
const TYPE_ID: u64 = _private::TYPE_ID;
}
impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> {
fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Self {
Self { reader, }
impl<'a,> From<::capnp::private::layout::StructReader<'a>> for Reader<'a,> {
fn from(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> {
Reader { reader, }
}
}

impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> {
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Self> {
::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?))
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Reader<'a,>> {
::core::result::Result::Ok(reader.get_struct(default)?.into())
}
}

Expand Down Expand Up @@ -348,13 +348,13 @@ pub mod recipient_id {

impl <'a,> Builder<'a,> {
pub fn into_reader(self) -> Reader<'a,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}
pub fn reborrow(&mut self) -> Builder<'_,> {
Builder { .. *self }
}
pub fn reborrow_as_reader(&self) -> Reader<'_,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}

pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> {
Expand Down Expand Up @@ -388,15 +388,15 @@ pub mod third_party_cap_id {
impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> {
const TYPE_ID: u64 = _private::TYPE_ID;
}
impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> {
fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Self {
Self { reader, }
impl<'a,> From<::capnp::private::layout::StructReader<'a>> for Reader<'a,> {
fn from(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> {
Reader { reader, }
}
}

impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> {
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Self> {
::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?))
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Reader<'a,>> {
::core::result::Result::Ok(reader.get_struct(default)?.into())
}
}

Expand Down Expand Up @@ -456,13 +456,13 @@ pub mod third_party_cap_id {

impl <'a,> Builder<'a,> {
pub fn into_reader(self) -> Reader<'a,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}
pub fn reborrow(&mut self) -> Builder<'_,> {
Builder { .. *self }
}
pub fn reborrow_as_reader(&self) -> Reader<'_,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}

pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> {
Expand Down Expand Up @@ -496,15 +496,15 @@ pub mod join_key_part {
impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> {
const TYPE_ID: u64 = _private::TYPE_ID;
}
impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> {
fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Self {
Self { reader, }
impl<'a,> From<::capnp::private::layout::StructReader<'a>> for Reader<'a,> {
fn from(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> {
Reader { reader, }
}
}

impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> {
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Self> {
::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?))
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Reader<'a,>> {
::core::result::Result::Ok(reader.get_struct(default)?.into())
}
}

Expand Down Expand Up @@ -576,13 +576,13 @@ pub mod join_key_part {

impl <'a,> Builder<'a,> {
pub fn into_reader(self) -> Reader<'a,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}
pub fn reborrow(&mut self) -> Builder<'_,> {
Builder { .. *self }
}
pub fn reborrow_as_reader(&self) -> Reader<'_,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}

pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> {
Expand Down Expand Up @@ -640,15 +640,15 @@ pub mod join_result {
impl <'a,> ::capnp::traits::HasTypeId for Reader<'a,> {
const TYPE_ID: u64 = _private::TYPE_ID;
}
impl <'a,> ::capnp::traits::FromStructReader<'a> for Reader<'a,> {
fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Self {
Self { reader, }
impl<'a,> From<::capnp::private::layout::StructReader<'a>> for Reader<'a,> {
fn from(reader: ::capnp::private::layout::StructReader<'a>) -> Reader<'a,> {
Reader { reader, }
}
}

impl <'a,> ::capnp::traits::FromPointerReader<'a> for Reader<'a,> {
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Self> {
::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?))
fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Reader<'a,>> {
::core::result::Result::Ok(reader.get_struct(default)?.into())
}
}

Expand Down Expand Up @@ -724,13 +724,13 @@ pub mod join_result {

impl <'a,> Builder<'a,> {
pub fn into_reader(self) -> Reader<'a,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}
pub fn reborrow(&mut self) -> Builder<'_,> {
Builder { .. *self }
}
pub fn reborrow_as_reader(&self) -> Reader<'_,> {
::capnp::traits::FromStructReader::new(self.builder.into_reader())
self.builder.into_reader().into()
}

pub fn total_size(&self) -> ::capnp::Result<::capnp::MessageSize> {
Expand Down
4 changes: 2 additions & 2 deletions capnp/src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<T, E> Future for Promise<T, E> {

#[cfg(feature = "rpc_try")]
impl<T> std::ops::Try for Promise<T, crate::Error> {
type Output = Promise<T, crate::Error>;
type Output = Self;
type Residual = Result<std::convert::Infallible, crate::Error>;

fn from_output(output: Self::Output) -> Self {
Expand All @@ -110,7 +110,7 @@ impl<T> std::ops::FromResidual for Promise<T, crate::Error> {
fn from_residual(residual: <Self as Try>::Residual) -> Self {
match residual {
Ok(_) => unimplemented!(),
Err(e) => Promise::err(e),
Err(e) => Self::err(e),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions capnp/src/private/read_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ mod sync {
}

impl ReadLimiter {
pub fn new(limit: Option<usize>) -> ReadLimiter {
pub fn new(limit: Option<usize>) -> Self {
match limit {
Some(value) => ReadLimiter {
Some(value) => Self {
limit: AtomicUsize::new(value),
error_on_limit_exceeded: true,
},
None => ReadLimiter {
None => Self {
limit: AtomicUsize::new(usize::MAX),
error_on_limit_exceeded: false,
},
Expand Down
7 changes: 3 additions & 4 deletions capnp/src/struct_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use crate::private::layout::{
InlineComposite, ListBuilder, ListReader, PointerBuilder, PointerReader,
};
use crate::traits::{
FromPointerBuilder, FromPointerReader, FromStructBuilder, FromStructReader, HasStructSize,
IndexMove, ListIter,
FromPointerBuilder, FromPointerReader, FromStructBuilder, HasStructSize, IndexMove, ListIter,
};
use crate::Result;

Expand Down Expand Up @@ -130,14 +129,14 @@ where
/// equal to `len()`.
pub fn get(self, index: u32) -> T::Reader<'a> {
assert!(index < self.len());
FromStructReader::new(self.reader.get_struct_element(index))
self.reader.get_struct_element(index).into()
}

/// Gets the element at position `index`. Returns `None` if `index`
/// is greater than or equal to `len()`.
pub fn try_get(self, index: u32) -> Option<T::Reader<'a>> {
if index < self.len() {
Some(FromStructReader::new(self.reader.get_struct_element(index)))
Some(self.reader.get_struct_element(index).into())
} else {
None
}
Expand Down
6 changes: 1 addition & 5 deletions capnp/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ use crate::Result;

use core::marker::PhantomData;

pub trait FromStructReader<'a> {
fn new(reader: StructReader<'a>) -> Self;
}

pub trait HasStructSize {
const STRUCT_SIZE: StructSize;
}
Expand Down Expand Up @@ -69,7 +65,7 @@ pub trait Owned {
}

pub trait OwnedStruct {
type Reader<'a>: FromStructReader<'a> + SetPointerBuilder + IntoInternalStructReader<'a>;
type Reader<'a>: From<StructReader<'a>> + SetPointerBuilder + IntoInternalStructReader<'a>;
type Builder<'a>: FromStructBuilder<'a> + HasStructSize;
}

Expand Down
14 changes: 7 additions & 7 deletions capnpc/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ pub fn getter_text(
}

let getter_code = if is_reader {
Line("::capnp::traits::FromStructReader::new(self.reader)".to_string())
Line("self.reader.into()".to_string())
} else {
Line("::capnp::traits::FromStructBuilder::new(self.builder)".to_string())
};
Expand Down Expand Up @@ -1773,12 +1773,12 @@ fn generate_node(
params.params, params.where_clause)),
Indent(Box::new(Branch(vec!(Line("const TYPE_ID: u64 = _private::TYPE_ID;".to_string()))))),
Line("}".to_string()))),
Line(format!("impl <'a,{0}> ::capnp::traits::FromStructReader<'a> for Reader<'a,{0}> {1} {{",
Line(format!("impl <'a,{0}> From<::capnp::private::layout::StructReader<'a>> for Reader<'a,{0}> {1} {{",
params.params, params.where_clause)),
Indent(
Box::new(Branch(vec!(
Line("fn new(reader: ::capnp::private::layout::StructReader<'a>) -> Self {".to_string()),
Indent(Box::new(Line(format!("Self {{ reader, {} }}", params.phantom_data_value)))),
Line("fn from(reader: ::capnp::private::layout::StructReader<'a>) -> Self {".to_string()),
Indent(Box::new(Line(format!("Reader {{ reader, {} }}", params.phantom_data_value)))),
Line("}".to_string()))))),
Line("}".to_string()),
BlankLine,
Expand All @@ -1787,7 +1787,7 @@ fn generate_node(
Indent(
Box::new(Branch(vec!(
Line("fn get_from_pointer(reader: &::capnp::private::layout::PointerReader<'a>, default: ::core::option::Option<&'a [capnp::Word]>) -> ::capnp::Result<Self> {".to_string()),
Indent(Box::new(Line("::core::result::Result::Ok(::capnp::traits::FromStructReader::new(reader.get_struct(default)?))".to_string()))),
Indent(Box::new(Line("::core::result::Result::Ok(reader.get_struct(default)?.into())".to_string()))),
Line("}".to_string()))))),
Line("}".to_string()),
BlankLine,
Expand Down Expand Up @@ -1873,13 +1873,13 @@ fn generate_node(
Indent(
Box::new(Branch(vec![
Line(format!("pub fn into_reader(self) -> Reader<'a,{}> {{", params.params)),
Indent(Box::new(Line("::capnp::traits::FromStructReader::new(self.builder.into_reader())".to_string()))),
Indent(Box::new(Line("self.builder.into_reader().into()".to_string()))),
Line("}".to_string()),
Line(format!("pub fn reborrow(&mut self) -> Builder<'_,{}> {{", params.params)),
Indent(Box::new(Line("Builder { .. *self }".to_string()))),
Line("}".to_string()),
Line(format!("pub fn reborrow_as_reader(&self) -> Reader<'_,{}> {{", params.params)),
Indent(Box::new(Line("::capnp::traits::FromStructReader::new(self.builder.into_reader())".to_string()))),
Indent(Box::new(Line("self.builder.into_reader().into()".to_string()))),
Line("}".to_string()),

BlankLine,
Expand Down
Loading