From b393cae7cd7a756257ad4b68a13518a0f3504786 Mon Sep 17 00:00:00 2001 From: Sydney Acksman Date: Tue, 16 Jul 2024 22:38:30 -0500 Subject: [PATCH] WIP Refactor library to use type kinds for non-overlapping traits --- recapn-rpc/src/connection.rs | 15 +- recapn-rpc/src/gen/capnp/rpc.capnp.rs | 1119 ++++++++---------- recapn/src/any.rs | 40 - recapn/src/data.rs | 6 - recapn/src/field.rs | 1272 +++++++++++---------- recapn/src/lib.rs | 2 +- recapn/src/list.rs | 747 ++++++------ recapn/src/message.rs | 7 +- recapn/src/orphan.rs | 5 +- recapn/src/ptr.rs | 67 +- recapn/src/text.rs | 6 - recapn/src/ty.rs | 115 +- recapnc/src/bin/capnpc-rust.rs | 2 +- recapnc/src/gen/capnp/schema.capnp.rs | 175 +-- recapnc/src/generator.rs | 28 +- recapnc/src/lib.rs | 14 +- recapnc/src/quotes.rs | 11 +- tests/src/gen/capnp/test-import.capnp.rs | 45 +- tests/src/gen/capnp/test-import2.capnp.rs | 94 +- tests/src/gen/capnp/test.capnp.rs | 144 ++- 20 files changed, 1894 insertions(+), 2020 deletions(-) diff --git a/recapn-rpc/src/connection.rs b/recapn-rpc/src/connection.rs index 088b099..1bb6397 100644 --- a/recapn-rpc/src/connection.rs +++ b/recapn-rpc/src/connection.rs @@ -7,7 +7,6 @@ use recapn::arena::ReadArena; use recapn::orphan::Orphan; use recapn::rpc::Capable; use recapn::{any, list, message, BuilderOf, NotInSchema, ReaderOf}; -use recapn::field::{Struct, Enum}; use recapn::message::{BuilderParts, Message, ReaderOptions}; use recapn::ptr::{ElementCount, ElementSize, ObjectLen, ReturnErrors}; use tokio::select; @@ -33,8 +32,8 @@ use crate::gen::capnp_rpc_capnp as rpc_capnp; use rpc_capnp::CapDescriptor; use rpc_capnp::promised_answer::Op; -const MAX_OPS: usize = ElementSize::size_of::>().max_elements().get() as usize; -const MAX_CAPS: usize = ElementSize::size_of::>().max_elements().get() as usize; +const MAX_OPS: usize = ElementSize::size_of::().max_elements().get() as usize; +const MAX_CAPS: usize = ElementSize::size_of::().max_elements().get() as usize; type RpcSender = mpsc::Sender; type RpcReceiver = mpsc::Receiver; @@ -69,7 +68,7 @@ fn exception_to_error(ex: &ReaderOf) -> Error { Error::new(kind, Cow::Owned(msg)) } -type OpsList<'a> = list::StructListReader<'a, rpc_capnp::promised_answer::Op>; +type OpsList<'a> = list::Reader<'a, rpc_capnp::promised_answer::Op>; fn to_pipeline_ops(list: OpsList) -> Result, Error> { list.into_iter().filter_map(|op| { use rpc_capnp::promised_answer::op::Which; @@ -755,7 +754,7 @@ impl Connection { pub fn try_handle_message(&mut self, incoming: impl IncomingMessage) -> Result<(), Error> { let message = incoming.message(); let reader = recapn::message::Reader::new(message, self.options.reader_options.clone()); - let reader = reader.read_as_struct::(); + let reader = reader.read_as::(); use rpc_capnp::message::Which; match reader.which() { @@ -826,7 +825,7 @@ impl Connection { fn handle_call(&mut self, message: ExternalMessage) -> Result<(), Error> { let reader = recapn::message::Reader::new(&*message, self.options.reader_options.clone()); - let message = reader.read_as_struct::(); + let message = reader.read_as::(); let call = message.call().field().unwrap().try_get()?; let target = self.read_message_target(&call.target().try_get()?)?; @@ -849,7 +848,7 @@ impl Connection { fn handle_return(&mut self, message: ExternalMessage) -> Result<(), Error> { let reader = recapn::message::Reader::new(&*message, self.options.reader_options.clone()); - let message = reader.read_as_struct::(); + let message = reader.read_as::(); let ret: ReaderOf = message.r#return().field().unwrap().try_get()?; let question_id = ret.answer_id(); @@ -970,7 +969,7 @@ impl Connection { } } - fn read_cap_descriptors(&mut self, table: list::StructListReader) -> Result>, Error> { + fn read_cap_descriptors(&mut self, table: list::Reader) -> Result>, Error> { let mut descriptors = Vec::with_capacity(table.len() as usize); for d in table { let client = self.read_cap_descriptor(&d)?; diff --git a/recapn-rpc/src/gen/capnp/rpc.capnp.rs b/recapn-rpc/src/gen/capnp/rpc.capnp.rs index e87832e..13ba819 100644 --- a/recapn-rpc/src/gen/capnp/rpc.capnp.rs +++ b/recapn-rpc/src/gen/capnp/rpc.capnp.rs @@ -89,6 +89,9 @@ impl _p::StructView for Message { type Reader<'a, T: _p::rpc::Table> = message::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = message::Builder<'a, T>; } +impl _p::ty::TypeKind for Message { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Message { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -96,88 +99,76 @@ impl _p::ty::Struct for Message { }; } impl Message { - const UNIMPLEMENTED: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, + const UNIMPLEMENTED: _p::VariantDescriptor = _p::VariantDescriptor::< + Message, > { variant: _p::VariantInfo { slot: 0u32, case: 0u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const ABORT: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const ABORT: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 0u32, case: 1u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const CALL: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const CALL: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 0u32, case: 2u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const RETURN: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const RETURN: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 0u32, case: 3u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const FINISH: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const FINISH: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 0u32, case: 4u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const RESOLVE: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const RESOLVE: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 0u32, case: 5u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const RELEASE: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const RELEASE: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 0u32, case: 6u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const OBSOLETE_SAVE: _p::VariantDescriptor<_p::AnyPtr> = _p::VariantDescriptor::< @@ -189,19 +180,19 @@ impl Message { }, field: _p::Descriptor::<_p::AnyPtr> { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }, }; - const BOOTSTRAP: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, + const BOOTSTRAP: _p::VariantDescriptor = _p::VariantDescriptor::< + Bootstrap, > { variant: _p::VariantInfo { slot: 0u32, case: 8u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const OBSOLETE_DELETE: _p::VariantDescriptor<_p::AnyPtr> = _p::VariantDescriptor::< @@ -213,112 +204,82 @@ impl Message { }, field: _p::Descriptor::<_p::AnyPtr> { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }, }; - const PROVIDE: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const PROVIDE: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 0u32, case: 10u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const ACCEPT: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const ACCEPT: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 0u32, case: 11u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const JOIN: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const JOIN: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 0u32, case: 12u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const DISEMBARGO: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, + const DISEMBARGO: _p::VariantDescriptor = _p::VariantDescriptor::< + Disembargo, > { variant: _p::VariantInfo { slot: 0u32, case: 13u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; } impl<'p, T: _p::rpc::Table + 'p> message::Reader<'p, T> { #[inline] - pub fn unimplemented(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { + pub fn unimplemented(&self) -> _p::Variant<'_, 'p, T, Message> { unsafe { - <_p::Struct< - Message, - > as _p::field::FieldType>::variant(&self.0, &Message::UNIMPLEMENTED) + ::variant(&self.0, &Message::UNIMPLEMENTED) } } #[inline] - pub fn abort(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Exception, - > as _p::field::FieldType>::variant(&self.0, &Message::ABORT) - } + pub fn abort(&self) -> _p::Variant<'_, 'p, T, Exception> { + unsafe { ::variant(&self.0, &Message::ABORT) } } #[inline] - pub fn call(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct as _p::field::FieldType>::variant(&self.0, &Message::CALL) - } + pub fn call(&self) -> _p::Variant<'_, 'p, T, Call> { + unsafe { ::variant(&self.0, &Message::CALL) } } #[inline] - pub fn r#return(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Return, - > as _p::field::FieldType>::variant(&self.0, &Message::RETURN) - } + pub fn r#return(&self) -> _p::Variant<'_, 'p, T, Return> { + unsafe { ::variant(&self.0, &Message::RETURN) } } #[inline] - pub fn finish(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Finish, - > as _p::field::FieldType>::variant(&self.0, &Message::FINISH) - } + pub fn finish(&self) -> _p::Variant<'_, 'p, T, Finish> { + unsafe { ::variant(&self.0, &Message::FINISH) } } #[inline] - pub fn resolve(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Resolve, - > as _p::field::FieldType>::variant(&self.0, &Message::RESOLVE) - } + pub fn resolve(&self) -> _p::Variant<'_, 'p, T, Resolve> { + unsafe { ::variant(&self.0, &Message::RESOLVE) } } #[inline] - pub fn release(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Release, - > as _p::field::FieldType>::variant(&self.0, &Message::RELEASE) - } + pub fn release(&self) -> _p::Variant<'_, 'p, T, Release> { + unsafe { ::variant(&self.0, &Message::RELEASE) } } #[inline] pub fn obsolete_save(&self) -> _p::Variant<'_, 'p, T, _p::AnyPtr> { @@ -330,11 +291,9 @@ impl<'p, T: _p::rpc::Table + 'p> message::Reader<'p, T> { } } #[inline] - pub fn bootstrap(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { + pub fn bootstrap(&self) -> _p::Variant<'_, 'p, T, Bootstrap> { unsafe { - <_p::Struct< - Bootstrap, - > as _p::field::FieldType>::variant(&self.0, &Message::BOOTSTRAP) + ::variant(&self.0, &Message::BOOTSTRAP) } } #[inline] @@ -347,33 +306,21 @@ impl<'p, T: _p::rpc::Table + 'p> message::Reader<'p, T> { } } #[inline] - pub fn provide(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Provide, - > as _p::field::FieldType>::variant(&self.0, &Message::PROVIDE) - } + pub fn provide(&self) -> _p::Variant<'_, 'p, T, Provide> { + unsafe { ::variant(&self.0, &Message::PROVIDE) } } #[inline] - pub fn accept(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Accept, - > as _p::field::FieldType>::variant(&self.0, &Message::ACCEPT) - } + pub fn accept(&self) -> _p::Variant<'_, 'p, T, Accept> { + unsafe { ::variant(&self.0, &Message::ACCEPT) } } #[inline] - pub fn join(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct as _p::field::FieldType>::variant(&self.0, &Message::JOIN) - } + pub fn join(&self) -> _p::Variant<'_, 'p, T, Join> { + unsafe { ::variant(&self.0, &Message::JOIN) } } #[inline] - pub fn disembargo(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { + pub fn disembargo(&self) -> _p::Variant<'_, 'p, T, Disembargo> { unsafe { - <_p::Struct< - Disembargo, - > as _p::field::FieldType>::variant(&self.0, &Message::DISEMBARGO) + ::variant(&self.0, &Message::DISEMBARGO) } } #[inline] @@ -383,59 +330,46 @@ impl<'p, T: _p::rpc::Table + 'p> message::Reader<'p, T> { } impl<'p, T: _p::rpc::Table + 'p> message::Builder<'p, T> { #[inline] - pub fn unimplemented(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn unimplemented(&mut self) -> _p::VariantMut<'_, 'p, T, Message> { unsafe { - <_p::Struct< - Message, - > as _p::field::FieldType>::variant(&mut self.0, &Message::UNIMPLEMENTED) + ::variant( + &mut self.0, + &Message::UNIMPLEMENTED, + ) } } #[inline] - pub fn abort(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn abort(&mut self) -> _p::VariantMut<'_, 'p, T, Exception> { unsafe { - <_p::Struct< - Exception, - > as _p::field::FieldType>::variant(&mut self.0, &Message::ABORT) + ::variant(&mut self.0, &Message::ABORT) } } #[inline] - pub fn call(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Call, - > as _p::field::FieldType>::variant(&mut self.0, &Message::CALL) - } + pub fn call(&mut self) -> _p::VariantMut<'_, 'p, T, Call> { + unsafe { ::variant(&mut self.0, &Message::CALL) } } #[inline] - pub fn r#return(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn r#return(&mut self) -> _p::VariantMut<'_, 'p, T, Return> { unsafe { - <_p::Struct< - Return, - > as _p::field::FieldType>::variant(&mut self.0, &Message::RETURN) + ::variant(&mut self.0, &Message::RETURN) } } #[inline] - pub fn finish(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn finish(&mut self) -> _p::VariantMut<'_, 'p, T, Finish> { unsafe { - <_p::Struct< - Finish, - > as _p::field::FieldType>::variant(&mut self.0, &Message::FINISH) + ::variant(&mut self.0, &Message::FINISH) } } #[inline] - pub fn resolve(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn resolve(&mut self) -> _p::VariantMut<'_, 'p, T, Resolve> { unsafe { - <_p::Struct< - Resolve, - > as _p::field::FieldType>::variant(&mut self.0, &Message::RESOLVE) + ::variant(&mut self.0, &Message::RESOLVE) } } #[inline] - pub fn release(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn release(&mut self) -> _p::VariantMut<'_, 'p, T, Release> { unsafe { - <_p::Struct< - Release, - > as _p::field::FieldType>::variant(&mut self.0, &Message::RELEASE) + ::variant(&mut self.0, &Message::RELEASE) } } #[inline] @@ -448,11 +382,12 @@ impl<'p, T: _p::rpc::Table + 'p> message::Builder<'p, T> { } } #[inline] - pub fn bootstrap(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn bootstrap(&mut self) -> _p::VariantMut<'_, 'p, T, Bootstrap> { unsafe { - <_p::Struct< - Bootstrap, - > as _p::field::FieldType>::variant(&mut self.0, &Message::BOOTSTRAP) + ::variant( + &mut self.0, + &Message::BOOTSTRAP, + ) } } #[inline] @@ -465,90 +400,59 @@ impl<'p, T: _p::rpc::Table + 'p> message::Builder<'p, T> { } } #[inline] - pub fn provide(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn provide(&mut self) -> _p::VariantMut<'_, 'p, T, Provide> { unsafe { - <_p::Struct< - Provide, - > as _p::field::FieldType>::variant(&mut self.0, &Message::PROVIDE) + ::variant(&mut self.0, &Message::PROVIDE) } } #[inline] - pub fn accept(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn accept(&mut self) -> _p::VariantMut<'_, 'p, T, Accept> { unsafe { - <_p::Struct< - Accept, - > as _p::field::FieldType>::variant(&mut self.0, &Message::ACCEPT) + ::variant(&mut self.0, &Message::ACCEPT) } } #[inline] - pub fn join(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Join, - > as _p::field::FieldType>::variant(&mut self.0, &Message::JOIN) - } + pub fn join(&mut self) -> _p::VariantMut<'_, 'p, T, Join> { + unsafe { ::variant(&mut self.0, &Message::JOIN) } } #[inline] - pub fn disembargo(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn disembargo(&mut self) -> _p::VariantMut<'_, 'p, T, Disembargo> { unsafe { - <_p::Struct< - Disembargo, - > as _p::field::FieldType>::variant(&mut self.0, &Message::DISEMBARGO) + ::variant( + &mut self.0, + &Message::DISEMBARGO, + ) } } #[inline] - pub fn into_unimplemented(self) -> _p::VariantOwned<'p, T, _p::Struct> { + pub fn into_unimplemented(self) -> _p::VariantOwned<'p, T, Message> { unsafe { - <_p::Struct< - Message, - > as _p::field::FieldType>::variant(self.0, &Message::UNIMPLEMENTED) + ::variant(self.0, &Message::UNIMPLEMENTED) } } #[inline] - pub fn into_abort(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Exception, - > as _p::field::FieldType>::variant(self.0, &Message::ABORT) - } + pub fn into_abort(self) -> _p::VariantOwned<'p, T, Exception> { + unsafe { ::variant(self.0, &Message::ABORT) } } #[inline] - pub fn into_call(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct as _p::field::FieldType>::variant(self.0, &Message::CALL) - } + pub fn into_call(self) -> _p::VariantOwned<'p, T, Call> { + unsafe { ::variant(self.0, &Message::CALL) } } #[inline] - pub fn into_return(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Return, - > as _p::field::FieldType>::variant(self.0, &Message::RETURN) - } + pub fn into_return(self) -> _p::VariantOwned<'p, T, Return> { + unsafe { ::variant(self.0, &Message::RETURN) } } #[inline] - pub fn into_finish(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Finish, - > as _p::field::FieldType>::variant(self.0, &Message::FINISH) - } + pub fn into_finish(self) -> _p::VariantOwned<'p, T, Finish> { + unsafe { ::variant(self.0, &Message::FINISH) } } #[inline] - pub fn into_resolve(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Resolve, - > as _p::field::FieldType>::variant(self.0, &Message::RESOLVE) - } + pub fn into_resolve(self) -> _p::VariantOwned<'p, T, Resolve> { + unsafe { ::variant(self.0, &Message::RESOLVE) } } #[inline] - pub fn into_release(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Release, - > as _p::field::FieldType>::variant(self.0, &Message::RELEASE) - } + pub fn into_release(self) -> _p::VariantOwned<'p, T, Release> { + unsafe { ::variant(self.0, &Message::RELEASE) } } #[inline] pub fn into_obsolete_save(self) -> _p::VariantOwned<'p, T, _p::AnyPtr> { @@ -560,11 +464,9 @@ impl<'p, T: _p::rpc::Table + 'p> message::Builder<'p, T> { } } #[inline] - pub fn into_bootstrap(self) -> _p::VariantOwned<'p, T, _p::Struct> { + pub fn into_bootstrap(self) -> _p::VariantOwned<'p, T, Bootstrap> { unsafe { - <_p::Struct< - Bootstrap, - > as _p::field::FieldType>::variant(self.0, &Message::BOOTSTRAP) + ::variant(self.0, &Message::BOOTSTRAP) } } #[inline] @@ -577,33 +479,21 @@ impl<'p, T: _p::rpc::Table + 'p> message::Builder<'p, T> { } } #[inline] - pub fn into_provide(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Provide, - > as _p::field::FieldType>::variant(self.0, &Message::PROVIDE) - } + pub fn into_provide(self) -> _p::VariantOwned<'p, T, Provide> { + unsafe { ::variant(self.0, &Message::PROVIDE) } } #[inline] - pub fn into_accept(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Accept, - > as _p::field::FieldType>::variant(self.0, &Message::ACCEPT) - } + pub fn into_accept(self) -> _p::VariantOwned<'p, T, Accept> { + unsafe { ::variant(self.0, &Message::ACCEPT) } } #[inline] - pub fn into_join(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct as _p::field::FieldType>::variant(self.0, &Message::JOIN) - } + pub fn into_join(self) -> _p::VariantOwned<'p, T, Join> { + unsafe { ::variant(self.0, &Message::JOIN) } } #[inline] - pub fn into_disembargo(self) -> _p::VariantOwned<'p, T, _p::Struct> { + pub fn into_disembargo(self) -> _p::VariantOwned<'p, T, Disembargo> { unsafe { - <_p::Struct< - Disembargo, - > as _p::field::FieldType>::variant(self.0, &Message::DISEMBARGO) + ::variant(self.0, &Message::DISEMBARGO) } } #[inline] @@ -616,20 +506,20 @@ pub mod message { pub type Reader<'a, T = _p::rpc::Empty> = super::Message<_p::StructReader<'a, T>>; pub type Builder<'a, T = _p::rpc::Empty> = super::Message<_p::StructBuilder<'a, T>>; pub enum Which { - Unimplemented(_p::ViewOf>), - Abort(_p::ViewOf>), - Call(_p::ViewOf>), - Return(_p::ViewOf>), - Finish(_p::ViewOf>), - Resolve(_p::ViewOf>), - Release(_p::ViewOf>), + Unimplemented(_p::ViewOf), + Abort(_p::ViewOf), + Call(_p::ViewOf), + Return(_p::ViewOf), + Finish(_p::ViewOf), + Resolve(_p::ViewOf), + Release(_p::ViewOf), ObsoleteSave(_p::ViewOf), - Bootstrap(_p::ViewOf>), + Bootstrap(_p::ViewOf), ObsoleteDelete(_p::ViewOf), - Provide(_p::ViewOf>), - Accept(_p::ViewOf>), - Join(_p::ViewOf>), - Disembargo(_p::ViewOf>), + Provide(_p::ViewOf), + Accept(_p::ViewOf), + Join(_p::ViewOf), + Disembargo(_p::ViewOf), } impl<'b, 'p: 'b, T: _p::Table + 'p> _p::UnionViewer<&'b Reader<'p, T>> for Which { type View = Which<&'b Reader<'p, T>>; @@ -639,9 +529,7 @@ pub mod message { 0u16 => { Ok( Which::Unimplemented( - <_p::Struct< - super::Message, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::UNIMPLEMENTED.field, ), @@ -651,9 +539,7 @@ pub mod message { 1u16 => { Ok( Which::Abort( - <_p::Struct< - super::Exception, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::ABORT.field, ), @@ -663,9 +549,7 @@ pub mod message { 2u16 => { Ok( Which::Call( - <_p::Struct< - super::Call, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::CALL.field, ), @@ -675,9 +559,7 @@ pub mod message { 3u16 => { Ok( Which::Return( - <_p::Struct< - super::Return, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::RETURN.field, ), @@ -687,9 +569,7 @@ pub mod message { 4u16 => { Ok( Which::Finish( - <_p::Struct< - super::Finish, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::FINISH.field, ), @@ -699,9 +579,7 @@ pub mod message { 5u16 => { Ok( Which::Resolve( - <_p::Struct< - super::Resolve, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::RESOLVE.field, ), @@ -711,9 +589,7 @@ pub mod message { 6u16 => { Ok( Which::Release( - <_p::Struct< - super::Release, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::RELEASE.field, ), @@ -733,9 +609,7 @@ pub mod message { 8u16 => { Ok( Which::Bootstrap( - <_p::Struct< - super::Bootstrap, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::BOOTSTRAP.field, ), @@ -755,9 +629,7 @@ pub mod message { 10u16 => { Ok( Which::Provide( - <_p::Struct< - super::Provide, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::PROVIDE.field, ), @@ -767,9 +639,7 @@ pub mod message { 11u16 => { Ok( Which::Accept( - <_p::Struct< - super::Accept, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::ACCEPT.field, ), @@ -779,9 +649,7 @@ pub mod message { 12u16 => { Ok( Which::Join( - <_p::Struct< - super::Join, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::JOIN.field, ), @@ -791,9 +659,7 @@ pub mod message { 13u16 => { Ok( Which::Disembargo( - <_p::Struct< - super::Disembargo, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Message::DISEMBARGO.field, ), @@ -815,9 +681,7 @@ pub mod message { 0u16 => { Ok( Which::Unimplemented( - <_p::Struct< - super::Message, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::UNIMPLEMENTED.field, ), @@ -827,9 +691,7 @@ pub mod message { 1u16 => { Ok( Which::Abort( - <_p::Struct< - super::Exception, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::ABORT.field, ), @@ -839,9 +701,7 @@ pub mod message { 2u16 => { Ok( Which::Call( - <_p::Struct< - super::Call, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::CALL.field, ), @@ -851,9 +711,7 @@ pub mod message { 3u16 => { Ok( Which::Return( - <_p::Struct< - super::Return, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::RETURN.field, ), @@ -863,9 +721,7 @@ pub mod message { 4u16 => { Ok( Which::Finish( - <_p::Struct< - super::Finish, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::FINISH.field, ), @@ -875,9 +731,7 @@ pub mod message { 5u16 => { Ok( Which::Resolve( - <_p::Struct< - super::Resolve, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::RESOLVE.field, ), @@ -887,9 +741,7 @@ pub mod message { 6u16 => { Ok( Which::Release( - <_p::Struct< - super::Release, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::RELEASE.field, ), @@ -909,9 +761,7 @@ pub mod message { 8u16 => { Ok( Which::Bootstrap( - <_p::Struct< - super::Bootstrap, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::BOOTSTRAP.field, ), @@ -931,9 +781,7 @@ pub mod message { 10u16 => { Ok( Which::Provide( - <_p::Struct< - super::Provide, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::PROVIDE.field, ), @@ -943,9 +791,7 @@ pub mod message { 11u16 => { Ok( Which::Accept( - <_p::Struct< - super::Accept, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::ACCEPT.field, ), @@ -955,9 +801,7 @@ pub mod message { 12u16 => { Ok( Which::Join( - <_p::Struct< - super::Join, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::JOIN.field, ), @@ -967,9 +811,7 @@ pub mod message { 13u16 => { Ok( Which::Disembargo( - <_p::Struct< - super::Disembargo, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Message::DISEMBARGO.field, ), @@ -1069,6 +911,9 @@ impl _p::StructView for Bootstrap { type Reader<'a, T: _p::rpc::Table> = bootstrap::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = bootstrap::Builder<'a, T>; } +impl _p::ty::TypeKind for Bootstrap { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Bootstrap { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -1084,7 +929,7 @@ impl Bootstrap { _p::AnyPtr, > { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> bootstrap::Reader<'p, T> { @@ -1225,6 +1070,9 @@ impl _p::StructView for Call { type Reader<'a, T: _p::rpc::Table> = call::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = call::Builder<'a, T>; } +impl _p::ty::TypeKind for Call { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Call { const SIZE: _p::StructSize = _p::StructSize { data: 3u16, @@ -1236,11 +1084,9 @@ impl Call { slot: 0u32, default: 0u32, }; - const TARGET: _p::Descriptor<_p::Struct> = _p::Descriptor::< - _p::Struct, - > { + const TARGET: _p::Descriptor = _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }; const INTERFACE_ID: _p::Descriptor = _p::Descriptor:: { slot: 1u32, @@ -1250,13 +1096,11 @@ impl Call { slot: 2u32, default: 0u16, }; - const PARAMS: _p::Descriptor<_p::Struct> = _p::Descriptor::< - _p::Struct, - > { + const PARAMS: _p::Descriptor = _p::Descriptor:: { slot: 1u32, - default: _p::StructReader::empty(), + default: None, }; - const SEND_RESULTS_TO: _p::Descriptor<_p::Group> = (); + const SEND_RESULTS_TO: _p::Descriptor = (); const ALLOW_THIRD_PARTY_TAIL_CALL: _p::Descriptor = _p::Descriptor:: { slot: 128u32, default: false, @@ -1276,11 +1120,9 @@ impl<'p, T: _p::rpc::Table + 'p> call::Reader<'p, T> { unsafe { ::accessor(&self.0, &Call::QUESTION_ID) } } #[inline] - pub fn target(&self) -> _p::Accessor<'_, 'p, T, _p::Struct> { + pub fn target(&self) -> _p::Accessor<'_, 'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(&self.0, &Call::TARGET) + ::accessor(&self.0, &Call::TARGET) } } #[inline] @@ -1292,21 +1134,16 @@ impl<'p, T: _p::rpc::Table + 'p> call::Reader<'p, T> { unsafe { ::accessor(&self.0, &Call::METHOD_ID) } } #[inline] - pub fn params(&self) -> _p::Accessor<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Payload, - > as _p::field::FieldType>::accessor(&self.0, &Call::PARAMS) - } + pub fn params(&self) -> _p::Accessor<'_, 'p, T, Payload> { + unsafe { ::accessor(&self.0, &Call::PARAMS) } } #[inline] - pub fn send_results_to( - &self, - ) -> _p::Accessor<'_, 'p, T, _p::Group> { + pub fn send_results_to(&self) -> _p::Accessor<'_, 'p, T, call::SendResultsTo> { unsafe { - <_p::Group< - call::SendResultsTo, - > as _p::field::FieldType>::accessor(&self.0, &Call::SEND_RESULTS_TO) + ::accessor( + &self.0, + &Call::SEND_RESULTS_TO, + ) } } #[inline] @@ -1345,11 +1182,9 @@ impl<'p, T: _p::rpc::Table + 'p> call::Builder<'p, T> { } } #[inline] - pub fn target(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::Struct> { + pub fn target(&mut self) -> _p::AccessorMut<'_, 'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(&mut self.0, &Call::TARGET) + ::accessor(&mut self.0, &Call::TARGET) } } #[inline] @@ -1363,21 +1198,20 @@ impl<'p, T: _p::rpc::Table + 'p> call::Builder<'p, T> { unsafe { ::accessor(&mut self.0, &Call::METHOD_ID) } } #[inline] - pub fn params(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::Struct> { + pub fn params(&mut self) -> _p::AccessorMut<'_, 'p, T, Payload> { unsafe { - <_p::Struct< - Payload, - > as _p::field::FieldType>::accessor(&mut self.0, &Call::PARAMS) + ::accessor(&mut self.0, &Call::PARAMS) } } #[inline] pub fn send_results_to( &mut self, - ) -> _p::AccessorMut<'_, 'p, T, _p::Group> { + ) -> _p::AccessorMut<'_, 'p, T, call::SendResultsTo> { unsafe { - <_p::Group< - call::SendResultsTo, - > as _p::field::FieldType>::accessor(&mut self.0, &Call::SEND_RESULTS_TO) + ::accessor( + &mut self.0, + &Call::SEND_RESULTS_TO, + ) } } #[inline] @@ -1408,29 +1242,22 @@ impl<'p, T: _p::rpc::Table + 'p> call::Builder<'p, T> { } } #[inline] - pub fn into_target(self) -> _p::AccessorOwned<'p, T, _p::Struct> { + pub fn into_target(self) -> _p::AccessorOwned<'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(self.0, &Call::TARGET) + ::accessor(self.0, &Call::TARGET) } } #[inline] - pub fn into_params(self) -> _p::AccessorOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Payload, - > as _p::field::FieldType>::accessor(self.0, &Call::PARAMS) - } + pub fn into_params(self) -> _p::AccessorOwned<'p, T, Payload> { + unsafe { ::accessor(self.0, &Call::PARAMS) } } #[inline] - pub fn into_send_results_to( - self, - ) -> _p::AccessorOwned<'p, T, _p::Group> { + pub fn into_send_results_to(self) -> _p::AccessorOwned<'p, T, call::SendResultsTo> { unsafe { - <_p::Group< - call::SendResultsTo, - > as _p::field::FieldType>::accessor(self.0, &Call::SEND_RESULTS_TO) + ::accessor( + self.0, + &Call::SEND_RESULTS_TO, + ) } } } @@ -1530,7 +1357,10 @@ pub mod call { type Reader<'a, T: _p::rpc::Table> = send_results_to::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = send_results_to::Builder<'a, T>; } - impl _p::FieldGroup for SendResultsTo { + impl _p::ty::TypeKind for SendResultsTo { + type Kind = _p::ty::kind::Group; + } + impl _p::Group for SendResultsTo { unsafe fn clear<'a, 'b, T: _p::rpc::Table>(s: &'a mut _p::StructBuilder<'b, T>) { s.set_field_unchecked(3usize, 0); <() as _p::field::FieldType>::clear(s, &SendResultsTo::CALLER.field); @@ -1560,7 +1390,7 @@ pub mod call { }, field: _p::Descriptor::<_p::AnyPtr> { slot: 2u32, - default: _p::ptr::PtrReader::null(), + default: None, }, }; } @@ -1822,6 +1652,9 @@ impl _p::StructView for Return { type Reader<'a, T: _p::rpc::Table> = r#return::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = r#return::Builder<'a, T>; } +impl _p::ty::TypeKind for Return { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Return { const SIZE: _p::StructSize = _p::StructSize { data: 2u16, @@ -1841,28 +1674,26 @@ impl Return { slot: 33u32, default: false, }; - const RESULTS: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, - > { + const RESULTS: _p::VariantDescriptor = _p::VariantDescriptor:: { variant: _p::VariantInfo { slot: 3u32, case: 0u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const EXCEPTION: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, + const EXCEPTION: _p::VariantDescriptor = _p::VariantDescriptor::< + Exception, > { variant: _p::VariantInfo { slot: 3u32, case: 1u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const CANCELED: _p::VariantDescriptor<()> = _p::VariantDescriptor::<()> { @@ -1902,7 +1733,7 @@ impl Return { }, field: _p::Descriptor::<_p::AnyPtr> { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }, }; } @@ -1927,19 +1758,13 @@ impl<'p, T: _p::rpc::Table + 'p> r#return::Reader<'p, T> { } } #[inline] - pub fn results(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Payload, - > as _p::field::FieldType>::variant(&self.0, &Return::RESULTS) - } + pub fn results(&self) -> _p::Variant<'_, 'p, T, Payload> { + unsafe { ::variant(&self.0, &Return::RESULTS) } } #[inline] - pub fn exception(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { + pub fn exception(&self) -> _p::Variant<'_, 'p, T, Exception> { unsafe { - <_p::Struct< - Exception, - > as _p::field::FieldType>::variant(&self.0, &Return::EXCEPTION) + ::variant(&self.0, &Return::EXCEPTION) } } #[inline] @@ -2004,19 +1829,15 @@ impl<'p, T: _p::rpc::Table + 'p> r#return::Builder<'p, T> { } } #[inline] - pub fn results(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn results(&mut self) -> _p::VariantMut<'_, 'p, T, Payload> { unsafe { - <_p::Struct< - Payload, - > as _p::field::FieldType>::variant(&mut self.0, &Return::RESULTS) + ::variant(&mut self.0, &Return::RESULTS) } } #[inline] - pub fn exception(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn exception(&mut self) -> _p::VariantMut<'_, 'p, T, Exception> { unsafe { - <_p::Struct< - Exception, - > as _p::field::FieldType>::variant(&mut self.0, &Return::EXCEPTION) + ::variant(&mut self.0, &Return::EXCEPTION) } } #[inline] @@ -2051,19 +1872,13 @@ impl<'p, T: _p::rpc::Table + 'p> r#return::Builder<'p, T> { } } #[inline] - pub fn into_results(self) -> _p::VariantOwned<'p, T, _p::Struct> { - unsafe { - <_p::Struct< - Payload, - > as _p::field::FieldType>::variant(self.0, &Return::RESULTS) - } + pub fn into_results(self) -> _p::VariantOwned<'p, T, Payload> { + unsafe { ::variant(self.0, &Return::RESULTS) } } #[inline] - pub fn into_exception(self) -> _p::VariantOwned<'p, T, _p::Struct> { + pub fn into_exception(self) -> _p::VariantOwned<'p, T, Exception> { unsafe { - <_p::Struct< - Exception, - > as _p::field::FieldType>::variant(self.0, &Return::EXCEPTION) + ::variant(self.0, &Return::EXCEPTION) } } #[inline] @@ -2085,8 +1900,8 @@ pub mod r#return { pub type Reader<'a, T = _p::rpc::Empty> = super::Return<_p::StructReader<'a, T>>; pub type Builder<'a, T = _p::rpc::Empty> = super::Return<_p::StructBuilder<'a, T>>; pub enum Which { - Results(_p::ViewOf>), - Exception(_p::ViewOf>), + Results(_p::ViewOf), + Exception(_p::ViewOf), Canceled(_p::ViewOf), ResultsSentElsewhere(_p::ViewOf), TakeFromOtherQuestion(_p::ViewOf), @@ -2100,9 +1915,7 @@ pub mod r#return { 0u16 => { Ok( Which::Results( - <_p::Struct< - super::Payload, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Return::RESULTS.field, ), @@ -2112,9 +1925,7 @@ pub mod r#return { 1u16 => { Ok( Which::Exception( - <_p::Struct< - super::Exception, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Return::EXCEPTION.field, ), @@ -2176,9 +1987,7 @@ pub mod r#return { 0u16 => { Ok( Which::Results( - <_p::Struct< - super::Payload, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Return::RESULTS.field, ), @@ -2188,9 +1997,7 @@ pub mod r#return { 1u16 => { Ok( Which::Exception( - <_p::Struct< - super::Exception, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Return::EXCEPTION.field, ), @@ -2330,6 +2137,9 @@ impl _p::StructView for Finish { type Reader<'a, T: _p::rpc::Table> = finish::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = finish::Builder<'a, T>; } +impl _p::ty::TypeKind for Finish { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Finish { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -2471,6 +2281,9 @@ impl _p::StructView for Resolve { type Reader<'a, T: _p::rpc::Table> = resolve::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = resolve::Builder<'a, T>; } +impl _p::ty::TypeKind for Resolve { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Resolve { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -2482,28 +2295,28 @@ impl Resolve { slot: 0u32, default: 0u32, }; - const CAP: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, + const CAP: _p::VariantDescriptor = _p::VariantDescriptor::< + CapDescriptor, > { variant: _p::VariantInfo { slot: 2u32, case: 0u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const EXCEPTION: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, + const EXCEPTION: _p::VariantDescriptor = _p::VariantDescriptor::< + Exception, > { variant: _p::VariantInfo { slot: 2u32, case: 1u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; } @@ -2513,19 +2326,15 @@ impl<'p, T: _p::rpc::Table + 'p> resolve::Reader<'p, T> { unsafe { ::accessor(&self.0, &Resolve::PROMISE_ID) } } #[inline] - pub fn cap(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { + pub fn cap(&self) -> _p::Variant<'_, 'p, T, CapDescriptor> { unsafe { - <_p::Struct< - CapDescriptor, - > as _p::field::FieldType>::variant(&self.0, &Resolve::CAP) + ::variant(&self.0, &Resolve::CAP) } } #[inline] - pub fn exception(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { + pub fn exception(&self) -> _p::Variant<'_, 'p, T, Exception> { unsafe { - <_p::Struct< - Exception, - > as _p::field::FieldType>::variant(&self.0, &Resolve::EXCEPTION) + ::variant(&self.0, &Resolve::EXCEPTION) } } #[inline] @@ -2541,35 +2350,30 @@ impl<'p, T: _p::rpc::Table + 'p> resolve::Builder<'p, T> { } } #[inline] - pub fn cap(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn cap(&mut self) -> _p::VariantMut<'_, 'p, T, CapDescriptor> { unsafe { - <_p::Struct< - CapDescriptor, - > as _p::field::FieldType>::variant(&mut self.0, &Resolve::CAP) + ::variant(&mut self.0, &Resolve::CAP) } } #[inline] - pub fn exception(&mut self) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn exception(&mut self) -> _p::VariantMut<'_, 'p, T, Exception> { unsafe { - <_p::Struct< - Exception, - > as _p::field::FieldType>::variant(&mut self.0, &Resolve::EXCEPTION) + ::variant( + &mut self.0, + &Resolve::EXCEPTION, + ) } } #[inline] - pub fn into_cap(self) -> _p::VariantOwned<'p, T, _p::Struct> { + pub fn into_cap(self) -> _p::VariantOwned<'p, T, CapDescriptor> { unsafe { - <_p::Struct< - CapDescriptor, - > as _p::field::FieldType>::variant(self.0, &Resolve::CAP) + ::variant(self.0, &Resolve::CAP) } } #[inline] - pub fn into_exception(self) -> _p::VariantOwned<'p, T, _p::Struct> { + pub fn into_exception(self) -> _p::VariantOwned<'p, T, Exception> { unsafe { - <_p::Struct< - Exception, - > as _p::field::FieldType>::variant(self.0, &Resolve::EXCEPTION) + ::variant(self.0, &Resolve::EXCEPTION) } } #[inline] @@ -2582,8 +2386,8 @@ pub mod resolve { pub type Reader<'a, T = _p::rpc::Empty> = super::Resolve<_p::StructReader<'a, T>>; pub type Builder<'a, T = _p::rpc::Empty> = super::Resolve<_p::StructBuilder<'a, T>>; pub enum Which { - Cap(_p::ViewOf>), - Exception(_p::ViewOf>), + Cap(_p::ViewOf), + Exception(_p::ViewOf), } impl<'b, 'p: 'b, T: _p::Table + 'p> _p::UnionViewer<&'b Reader<'p, T>> for Which { type View = Which<&'b Reader<'p, T>>; @@ -2593,9 +2397,7 @@ pub mod resolve { 0u16 => { Ok( Which::Cap( - <_p::Struct< - super::CapDescriptor, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Resolve::CAP.field, ), @@ -2605,9 +2407,7 @@ pub mod resolve { 1u16 => { Ok( Which::Exception( - <_p::Struct< - super::Exception, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::Resolve::EXCEPTION.field, ), @@ -2629,9 +2429,7 @@ pub mod resolve { 0u16 => { Ok( Which::Cap( - <_p::Struct< - super::CapDescriptor, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Resolve::CAP.field, ), @@ -2641,9 +2439,7 @@ pub mod resolve { 1u16 => { Ok( Which::Exception( - <_p::Struct< - super::Exception, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::Resolve::EXCEPTION.field, ), @@ -2743,6 +2539,9 @@ impl _p::StructView for Release { type Reader<'a, T: _p::rpc::Table> = release::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = release::Builder<'a, T>; } +impl _p::ty::TypeKind for Release { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Release { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -2879,6 +2678,9 @@ impl _p::StructView for Disembargo { type Reader<'a, T: _p::rpc::Table> = disembargo::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = disembargo::Builder<'a, T>; } +impl _p::ty::TypeKind for Disembargo { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Disembargo { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -2886,67 +2688,67 @@ impl _p::ty::Struct for Disembargo { }; } impl Disembargo { - const TARGET: _p::Descriptor<_p::Struct> = _p::Descriptor::< - _p::Struct, - > { + const TARGET: _p::Descriptor = _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }; - const CONTEXT: _p::Descriptor<_p::Group> = (); + const CONTEXT: _p::Descriptor = (); } impl<'p, T: _p::rpc::Table + 'p> disembargo::Reader<'p, T> { #[inline] - pub fn target(&self) -> _p::Accessor<'_, 'p, T, _p::Struct> { + pub fn target(&self) -> _p::Accessor<'_, 'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(&self.0, &Disembargo::TARGET) + ::accessor( + &self.0, + &Disembargo::TARGET, + ) } } #[inline] - pub fn context(&self) -> _p::Accessor<'_, 'p, T, _p::Group> { + pub fn context(&self) -> _p::Accessor<'_, 'p, T, disembargo::Context> { unsafe { - <_p::Group< - disembargo::Context, - > as _p::field::FieldType>::accessor(&self.0, &Disembargo::CONTEXT) + ::accessor( + &self.0, + &Disembargo::CONTEXT, + ) } } } impl<'p, T: _p::rpc::Table + 'p> disembargo::Builder<'p, T> { #[inline] - pub fn target(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::Struct> { + pub fn target(&mut self) -> _p::AccessorMut<'_, 'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(&mut self.0, &Disembargo::TARGET) + ::accessor( + &mut self.0, + &Disembargo::TARGET, + ) } } #[inline] - pub fn context( - &mut self, - ) -> _p::AccessorMut<'_, 'p, T, _p::Group> { + pub fn context(&mut self) -> _p::AccessorMut<'_, 'p, T, disembargo::Context> { unsafe { - <_p::Group< - disembargo::Context, - > as _p::field::FieldType>::accessor(&mut self.0, &Disembargo::CONTEXT) + ::accessor( + &mut self.0, + &Disembargo::CONTEXT, + ) } } #[inline] - pub fn into_target(self) -> _p::AccessorOwned<'p, T, _p::Struct> { + pub fn into_target(self) -> _p::AccessorOwned<'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(self.0, &Disembargo::TARGET) + ::accessor( + self.0, + &Disembargo::TARGET, + ) } } #[inline] - pub fn into_context( - self, - ) -> _p::AccessorOwned<'p, T, _p::Group> { + pub fn into_context(self) -> _p::AccessorOwned<'p, T, disembargo::Context> { unsafe { - <_p::Group< - disembargo::Context, - > as _p::field::FieldType>::accessor(self.0, &Disembargo::CONTEXT) + ::accessor( + self.0, + &Disembargo::CONTEXT, + ) } } } @@ -3047,7 +2849,10 @@ pub mod disembargo { type Reader<'a, T: _p::rpc::Table> = context::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = context::Builder<'a, T>; } - impl _p::FieldGroup for Context { + impl _p::ty::TypeKind for Context { + type Kind = _p::ty::kind::Group; + } + impl _p::Group for Context { unsafe fn clear<'a, 'b, T: _p::rpc::Table>(s: &'a mut _p::StructBuilder<'b, T>) { s.set_field_unchecked(2usize, 0); ::clear(s, &Context::SENDER_LOOPBACK.field); @@ -3372,6 +3177,9 @@ impl _p::StructView for Provide { type Reader<'a, T: _p::rpc::Table> = provide::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = provide::Builder<'a, T>; } +impl _p::ty::TypeKind for Provide { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Provide { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -3383,15 +3191,13 @@ impl Provide { slot: 0u32, default: 0u32, }; - const TARGET: _p::Descriptor<_p::Struct> = _p::Descriptor::< - _p::Struct, - > { + const TARGET: _p::Descriptor = _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }; const RECIPIENT: _p::Descriptor<_p::AnyPtr> = _p::Descriptor::<_p::AnyPtr> { slot: 1u32, - default: _p::ptr::PtrReader::null(), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> provide::Reader<'p, T> { @@ -3402,11 +3208,9 @@ impl<'p, T: _p::rpc::Table + 'p> provide::Reader<'p, T> { } } #[inline] - pub fn target(&self) -> _p::Accessor<'_, 'p, T, _p::Struct> { + pub fn target(&self) -> _p::Accessor<'_, 'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(&self.0, &Provide::TARGET) + ::accessor(&self.0, &Provide::TARGET) } } #[inline] @@ -3424,11 +3228,12 @@ impl<'p, T: _p::rpc::Table + 'p> provide::Builder<'p, T> { } } #[inline] - pub fn target(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::Struct> { + pub fn target(&mut self) -> _p::AccessorMut<'_, 'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(&mut self.0, &Provide::TARGET) + ::accessor( + &mut self.0, + &Provide::TARGET, + ) } } #[inline] @@ -3441,11 +3246,9 @@ impl<'p, T: _p::rpc::Table + 'p> provide::Builder<'p, T> { } } #[inline] - pub fn into_target(self) -> _p::AccessorOwned<'p, T, _p::Struct> { + pub fn into_target(self) -> _p::AccessorOwned<'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(self.0, &Provide::TARGET) + ::accessor(self.0, &Provide::TARGET) } } #[inline] @@ -3548,6 +3351,9 @@ impl _p::StructView for Accept { type Reader<'a, T: _p::rpc::Table> = accept::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = accept::Builder<'a, T>; } +impl _p::ty::TypeKind for Accept { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Accept { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -3561,7 +3367,7 @@ impl Accept { }; const PROVISION: _p::Descriptor<_p::AnyPtr> = _p::Descriptor::<_p::AnyPtr> { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }; const EMBARGO: _p::Descriptor = _p::Descriptor:: { slot: 32u32, @@ -3706,6 +3512,9 @@ impl _p::StructView for Join { type Reader<'a, T: _p::rpc::Table> = join::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = join::Builder<'a, T>; } +impl _p::ty::TypeKind for Join { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Join { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -3717,15 +3526,13 @@ impl Join { slot: 0u32, default: 0u32, }; - const TARGET: _p::Descriptor<_p::Struct> = _p::Descriptor::< - _p::Struct, - > { + const TARGET: _p::Descriptor = _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }; const KEY_PART: _p::Descriptor<_p::AnyPtr> = _p::Descriptor::<_p::AnyPtr> { slot: 1u32, - default: _p::ptr::PtrReader::null(), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> join::Reader<'p, T> { @@ -3734,11 +3541,9 @@ impl<'p, T: _p::rpc::Table + 'p> join::Reader<'p, T> { unsafe { ::accessor(&self.0, &Join::QUESTION_ID) } } #[inline] - pub fn target(&self) -> _p::Accessor<'_, 'p, T, _p::Struct> { + pub fn target(&self) -> _p::Accessor<'_, 'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(&self.0, &Join::TARGET) + ::accessor(&self.0, &Join::TARGET) } } #[inline] @@ -3756,11 +3561,9 @@ impl<'p, T: _p::rpc::Table + 'p> join::Builder<'p, T> { } } #[inline] - pub fn target(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::Struct> { + pub fn target(&mut self) -> _p::AccessorMut<'_, 'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(&mut self.0, &Join::TARGET) + ::accessor(&mut self.0, &Join::TARGET) } } #[inline] @@ -3770,11 +3573,9 @@ impl<'p, T: _p::rpc::Table + 'p> join::Builder<'p, T> { } } #[inline] - pub fn into_target(self) -> _p::AccessorOwned<'p, T, _p::Struct> { + pub fn into_target(self) -> _p::AccessorOwned<'p, T, MessageTarget> { unsafe { - <_p::Struct< - MessageTarget, - > as _p::field::FieldType>::accessor(self.0, &Join::TARGET) + ::accessor(self.0, &Join::TARGET) } } #[inline] @@ -3877,6 +3678,9 @@ impl _p::StructView for MessageTarget { type Reader<'a, T: _p::rpc::Table> = message_target::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = message_target::Builder<'a, T>; } +impl _p::ty::TypeKind for MessageTarget { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for MessageTarget { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -3894,16 +3698,16 @@ impl MessageTarget { default: 0u32, }, }; - const PROMISED_ANSWER: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, + const PROMISED_ANSWER: _p::VariantDescriptor = _p::VariantDescriptor::< + PromisedAnswer, > { variant: _p::VariantInfo { slot: 2u32, case: 1u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; } @@ -3915,11 +3719,12 @@ impl<'p, T: _p::rpc::Table + 'p> message_target::Reader<'p, T> { } } #[inline] - pub fn promised_answer(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { + pub fn promised_answer(&self) -> _p::Variant<'_, 'p, T, PromisedAnswer> { unsafe { - <_p::Struct< - PromisedAnswer, - > as _p::field::FieldType>::variant(&self.0, &MessageTarget::PROMISED_ANSWER) + ::variant( + &self.0, + &MessageTarget::PROMISED_ANSWER, + ) } } #[inline] @@ -3938,26 +3743,21 @@ impl<'p, T: _p::rpc::Table + 'p> message_target::Builder<'p, T> { } } #[inline] - pub fn promised_answer( - &mut self, - ) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn promised_answer(&mut self) -> _p::VariantMut<'_, 'p, T, PromisedAnswer> { unsafe { - <_p::Struct< - PromisedAnswer, - > as _p::field::FieldType>::variant( + ::variant( &mut self.0, &MessageTarget::PROMISED_ANSWER, ) } } #[inline] - pub fn into_promised_answer( - self, - ) -> _p::VariantOwned<'p, T, _p::Struct> { + pub fn into_promised_answer(self) -> _p::VariantOwned<'p, T, PromisedAnswer> { unsafe { - <_p::Struct< - PromisedAnswer, - > as _p::field::FieldType>::variant(self.0, &MessageTarget::PROMISED_ANSWER) + ::variant( + self.0, + &MessageTarget::PROMISED_ANSWER, + ) } } #[inline] @@ -3977,7 +3777,7 @@ pub mod message_target { >; pub enum Which { ImportedCap(_p::ViewOf), - PromisedAnswer(_p::ViewOf>), + PromisedAnswer(_p::ViewOf), } impl<'b, 'p: 'b, T: _p::Table + 'p> _p::UnionViewer<&'b Reader<'p, T>> for Which { type View = Which<&'b Reader<'p, T>>; @@ -3997,9 +3797,7 @@ pub mod message_target { 1u16 => { Ok( Which::PromisedAnswer( - <_p::Struct< - super::PromisedAnswer, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::MessageTarget::PROMISED_ANSWER.field, ), @@ -4031,9 +3829,7 @@ pub mod message_target { 1u16 => { Ok( Which::PromisedAnswer( - <_p::Struct< - super::PromisedAnswer, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::MessageTarget::PROMISED_ANSWER.field, ), @@ -4133,6 +3929,9 @@ impl _p::StructView for Payload { type Reader<'a, T: _p::rpc::Table> = payload::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = payload::Builder<'a, T>; } +impl _p::ty::TypeKind for Payload { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Payload { const SIZE: _p::StructSize = _p::StructSize { data: 0u16, @@ -4142,15 +3941,13 @@ impl _p::ty::Struct for Payload { impl Payload { const CONTENT: _p::Descriptor<_p::AnyPtr> = _p::Descriptor::<_p::AnyPtr> { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }; - const CAP_TABLE: _p::Descriptor<_p::List<_p::Struct>> = _p::Descriptor::< - _p::List<_p::Struct>, + const CAP_TABLE: _p::Descriptor<_p::List> = _p::Descriptor::< + _p::List, > { slot: 1u32, - default: _p::ListReader::empty( - _p::ElementSize::size_of::<_p::Struct>(), - ), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> payload::Reader<'p, T> { @@ -4161,12 +3958,10 @@ impl<'p, T: _p::rpc::Table + 'p> payload::Reader<'p, T> { } } #[inline] - pub fn cap_table( - &self, - ) -> _p::Accessor<'_, 'p, T, _p::List<_p::Struct>> { + pub fn cap_table(&self) -> _p::Accessor<'_, 'p, T, _p::List> { unsafe { <_p::List< - _p::Struct, + CapDescriptor, > as _p::field::FieldType>::accessor(&self.0, &Payload::CAP_TABLE) } } @@ -4182,12 +3977,10 @@ impl<'p, T: _p::rpc::Table + 'p> payload::Builder<'p, T> { } } #[inline] - pub fn cap_table( - &mut self, - ) -> _p::AccessorMut<'_, 'p, T, _p::List<_p::Struct>> { + pub fn cap_table(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::List> { unsafe { <_p::List< - _p::Struct, + CapDescriptor, > as _p::field::FieldType>::accessor(&mut self.0, &Payload::CAP_TABLE) } } @@ -4198,12 +3991,10 @@ impl<'p, T: _p::rpc::Table + 'p> payload::Builder<'p, T> { } } #[inline] - pub fn into_cap_table( - self, - ) -> _p::AccessorOwned<'p, T, _p::List<_p::Struct>> { + pub fn into_cap_table(self) -> _p::AccessorOwned<'p, T, _p::List> { unsafe { <_p::List< - _p::Struct, + CapDescriptor, > as _p::field::FieldType>::accessor(self.0, &Payload::CAP_TABLE) } } @@ -4301,6 +4092,9 @@ impl _p::StructView for CapDescriptor { type Reader<'a, T: _p::rpc::Table> = cap_descriptor::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = cap_descriptor::Builder<'a, T>; } +impl _p::ty::TypeKind for CapDescriptor { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for CapDescriptor { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -4349,28 +4143,28 @@ impl CapDescriptor { default: 0u32, }, }; - const RECEIVER_ANSWER: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< - _p::Struct, + const RECEIVER_ANSWER: _p::VariantDescriptor = _p::VariantDescriptor::< + PromisedAnswer, > { variant: _p::VariantInfo { slot: 0u32, case: 4u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; - const THIRD_PARTY_HOSTED: _p::VariantDescriptor< - _p::Struct, - > = _p::VariantDescriptor::<_p::Struct> { + const THIRD_PARTY_HOSTED: _p::VariantDescriptor = _p::VariantDescriptor::< + ThirdPartyCapDescriptor, + > { variant: _p::VariantInfo { slot: 0u32, case: 5u16, }, - field: _p::Descriptor::<_p::Struct> { + field: _p::Descriptor:: { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; } @@ -4413,21 +4207,18 @@ impl<'p, T: _p::rpc::Table + 'p> cap_descriptor::Reader<'p, T> { } } #[inline] - pub fn receiver_answer(&self) -> _p::Variant<'_, 'p, T, _p::Struct> { + pub fn receiver_answer(&self) -> _p::Variant<'_, 'p, T, PromisedAnswer> { unsafe { - <_p::Struct< - PromisedAnswer, - > as _p::field::FieldType>::variant(&self.0, &CapDescriptor::RECEIVER_ANSWER) + ::variant( + &self.0, + &CapDescriptor::RECEIVER_ANSWER, + ) } } #[inline] - pub fn third_party_hosted( - &self, - ) -> _p::Variant<'_, 'p, T, _p::Struct> { + pub fn third_party_hosted(&self) -> _p::Variant<'_, 'p, T, ThirdPartyCapDescriptor> { unsafe { - <_p::Struct< - ThirdPartyCapDescriptor, - > as _p::field::FieldType>::variant( + ::variant( &self.0, &CapDescriptor::THIRD_PARTY_HOSTED, ) @@ -4482,13 +4273,9 @@ impl<'p, T: _p::rpc::Table + 'p> cap_descriptor::Builder<'p, T> { } } #[inline] - pub fn receiver_answer( - &mut self, - ) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + pub fn receiver_answer(&mut self) -> _p::VariantMut<'_, 'p, T, PromisedAnswer> { unsafe { - <_p::Struct< - PromisedAnswer, - > as _p::field::FieldType>::variant( + ::variant( &mut self.0, &CapDescriptor::RECEIVER_ANSWER, ) @@ -4497,34 +4284,29 @@ impl<'p, T: _p::rpc::Table + 'p> cap_descriptor::Builder<'p, T> { #[inline] pub fn third_party_hosted( &mut self, - ) -> _p::VariantMut<'_, 'p, T, _p::Struct> { + ) -> _p::VariantMut<'_, 'p, T, ThirdPartyCapDescriptor> { unsafe { - <_p::Struct< - ThirdPartyCapDescriptor, - > as _p::field::FieldType>::variant( + ::variant( &mut self.0, &CapDescriptor::THIRD_PARTY_HOSTED, ) } } #[inline] - pub fn into_receiver_answer( - self, - ) -> _p::VariantOwned<'p, T, _p::Struct> { + pub fn into_receiver_answer(self) -> _p::VariantOwned<'p, T, PromisedAnswer> { unsafe { - <_p::Struct< - PromisedAnswer, - > as _p::field::FieldType>::variant(self.0, &CapDescriptor::RECEIVER_ANSWER) + ::variant( + self.0, + &CapDescriptor::RECEIVER_ANSWER, + ) } } #[inline] pub fn into_third_party_hosted( self, - ) -> _p::VariantOwned<'p, T, _p::Struct> { + ) -> _p::VariantOwned<'p, T, ThirdPartyCapDescriptor> { unsafe { - <_p::Struct< - ThirdPartyCapDescriptor, - > as _p::field::FieldType>::variant( + ::variant( self.0, &CapDescriptor::THIRD_PARTY_HOSTED, ) @@ -4550,8 +4332,8 @@ pub mod cap_descriptor { SenderHosted(_p::ViewOf), SenderPromise(_p::ViewOf), ReceiverHosted(_p::ViewOf), - ReceiverAnswer(_p::ViewOf>), - ThirdPartyHosted(_p::ViewOf>), + ReceiverAnswer(_p::ViewOf), + ThirdPartyHosted(_p::ViewOf), } impl<'b, 'p: 'b, T: _p::Table + 'p> _p::UnionViewer<&'b Reader<'p, T>> for Which { type View = Which<&'b Reader<'p, T>>; @@ -4601,9 +4383,7 @@ pub mod cap_descriptor { 4u16 => { Ok( Which::ReceiverAnswer( - <_p::Struct< - super::PromisedAnswer, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::CapDescriptor::RECEIVER_ANSWER.field, ), @@ -4613,9 +4393,7 @@ pub mod cap_descriptor { 5u16 => { Ok( Which::ThirdPartyHosted( - <_p::Struct< - super::ThirdPartyCapDescriptor, - > as _p::field::FieldType>::accessor( + ::accessor( &repr.0, &super::CapDescriptor::THIRD_PARTY_HOSTED.field, ), @@ -4677,9 +4455,7 @@ pub mod cap_descriptor { 4u16 => { Ok( Which::ReceiverAnswer( - <_p::Struct< - super::PromisedAnswer, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::CapDescriptor::RECEIVER_ANSWER.field, ), @@ -4689,9 +4465,7 @@ pub mod cap_descriptor { 5u16 => { Ok( Which::ThirdPartyHosted( - <_p::Struct< - super::ThirdPartyCapDescriptor, - > as _p::field::FieldType>::accessor( + ::accessor( &mut repr.0, &super::CapDescriptor::THIRD_PARTY_HOSTED.field, ), @@ -4791,6 +4565,9 @@ impl _p::StructView for PromisedAnswer { type Reader<'a, T: _p::rpc::Table> = promised_answer::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = promised_answer::Builder<'a, T>; } +impl _p::ty::TypeKind for PromisedAnswer { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for PromisedAnswer { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -4802,13 +4579,11 @@ impl PromisedAnswer { slot: 0u32, default: 0u32, }; - const TRANSFORM: _p::Descriptor<_p::List<_p::Struct>> = _p::Descriptor::< - _p::List<_p::Struct>, + const TRANSFORM: _p::Descriptor<_p::List> = _p::Descriptor::< + _p::List, > { slot: 0u32, - default: _p::ListReader::empty( - _p::ElementSize::size_of::<_p::Struct>(), - ), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> promised_answer::Reader<'p, T> { @@ -4822,12 +4597,10 @@ impl<'p, T: _p::rpc::Table + 'p> promised_answer::Reader<'p, T> { } } #[inline] - pub fn transform( - &self, - ) -> _p::Accessor<'_, 'p, T, _p::List<_p::Struct>> { + pub fn transform(&self) -> _p::Accessor<'_, 'p, T, _p::List> { unsafe { <_p::List< - _p::Struct, + promised_answer::Op, > as _p::field::FieldType>::accessor(&self.0, &PromisedAnswer::TRANSFORM) } } @@ -4845,20 +4618,20 @@ impl<'p, T: _p::rpc::Table + 'p> promised_answer::Builder<'p, T> { #[inline] pub fn transform( &mut self, - ) -> _p::AccessorMut<'_, 'p, T, _p::List<_p::Struct>> { + ) -> _p::AccessorMut<'_, 'p, T, _p::List> { unsafe { <_p::List< - _p::Struct, + promised_answer::Op, > as _p::field::FieldType>::accessor(&mut self.0, &PromisedAnswer::TRANSFORM) } } #[inline] pub fn into_transform( self, - ) -> _p::AccessorOwned<'p, T, _p::List<_p::Struct>> { + ) -> _p::AccessorOwned<'p, T, _p::List> { unsafe { <_p::List< - _p::Struct, + promised_answer::Op, > as _p::field::FieldType>::accessor(self.0, &PromisedAnswer::TRANSFORM) } } @@ -4962,6 +4735,9 @@ pub mod promised_answer { type Reader<'a, T: _p::rpc::Table> = op::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = op::Builder<'a, T>; } + impl _p::ty::TypeKind for Op { + type Kind = _p::ty::kind::Struct; + } impl _p::ty::Struct for Op { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -5196,6 +4972,9 @@ impl _p::StructView for ThirdPartyCapDescriptor { type Reader<'a, T: _p::rpc::Table> = third_party_cap_descriptor::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = third_party_cap_descriptor::Builder<'a, T>; } +impl _p::ty::TypeKind for ThirdPartyCapDescriptor { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for ThirdPartyCapDescriptor { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -5205,7 +4984,7 @@ impl _p::ty::Struct for ThirdPartyCapDescriptor { impl ThirdPartyCapDescriptor { const ID: _p::Descriptor<_p::AnyPtr> = _p::Descriptor::<_p::AnyPtr> { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }; const VINE_ID: _p::Descriptor = _p::Descriptor:: { slot: 0u32, @@ -5358,6 +5137,9 @@ impl _p::StructView for Exception { type Reader<'a, T: _p::rpc::Table> = exception::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = exception::Builder<'a, T>; } +impl _p::ty::TypeKind for Exception { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for Exception { const SIZE: _p::StructSize = _p::StructSize { data: 1u16, @@ -5367,7 +5149,7 @@ impl _p::ty::Struct for Exception { impl Exception { const REASON: _p::Descriptor<_p::Text> = _p::Descriptor::<_p::Text> { slot: 0u32, - default: _p::text::Reader::empty(), + default: None, }; const OBSOLETE_IS_CALLERS_FAULT: _p::Descriptor = _p::Descriptor:: { slot: 0u32, @@ -5377,15 +5159,13 @@ impl Exception { slot: 1u32, default: 0u16, }; - const TYPE: _p::Descriptor<_p::Enum> = _p::Descriptor::< - _p::Enum, - > { + const TYPE: _p::Descriptor = _p::Descriptor:: { slot: 2u32, default: exception::Type::Failed, }; const TRACE: _p::Descriptor<_p::Text> = _p::Descriptor::<_p::Text> { slot: 1u32, - default: _p::text::Reader::empty(), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> exception::Reader<'p, T> { @@ -5414,11 +5194,12 @@ impl<'p, T: _p::rpc::Table + 'p> exception::Reader<'p, T> { } } #[inline] - pub fn r#type(&self) -> _p::Accessor<'_, 'p, T, _p::Enum> { + pub fn r#type(&self) -> _p::Accessor<'_, 'p, T, exception::Type> { unsafe { - <_p::Enum< - exception::Type, - > as _p::field::FieldType>::accessor(&self.0, &Exception::TYPE) + ::accessor( + &self.0, + &Exception::TYPE, + ) } } #[inline] @@ -5454,11 +5235,12 @@ impl<'p, T: _p::rpc::Table + 'p> exception::Builder<'p, T> { } } #[inline] - pub fn r#type(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::Enum> { + pub fn r#type(&mut self) -> _p::AccessorMut<'_, 'p, T, exception::Type> { unsafe { - <_p::Enum< - exception::Type, - > as _p::field::FieldType>::accessor(&mut self.0, &Exception::TYPE) + ::accessor( + &mut self.0, + &Exception::TYPE, + ) } } #[inline] @@ -5513,5 +5295,8 @@ pub mod exception { value as u16 } } + impl _p::ty::TypeKind for Type { + type Kind = _p::ty::kind::Enum; + } impl _p::ty::Enum for Type {} } diff --git a/recapn/src/any.rs b/recapn/src/any.rs index d3d5c17..14ce6ec 100644 --- a/recapn/src/any.rs +++ b/recapn/src/any.rs @@ -27,7 +27,6 @@ // * Default // * PartialEq (readers + builders) -use crate::field::Struct; use crate::internal::Sealed; use crate::list::{self, List, ElementSize}; use crate::orphan::{Orphan, Orphanage}; @@ -92,14 +91,6 @@ impl IntoFamily for AnyPtr { type Family = AnyPtr; } -impl ty::Value for AnyPtr { - type Default = ptr::PtrReader<'static, Empty>; -} - -impl ty::ListValue for AnyPtr { - const ELEMENT_SIZE: list::ElementSize = list::ElementSize::Pointer; -} - // PtrReader impls impl<'a, T: Table> AsRef> for PtrReader<'a, T> { @@ -187,16 +178,6 @@ impl<'a, T: Table> PtrReader<'a, T> { pub fn try_read_option_as>(self) -> Result> { U::try_get_option(self) } - - #[inline] - pub fn read_as_struct(self) -> as FromPtr>::Output { - self.read_as::>() - } - - #[inline] - pub fn read_as_list_of(self) -> as FromPtr>::Output { - self.read_as::>() - } } impl<'a, T: CapTable> PtrReader<'a, T> { @@ -366,16 +347,6 @@ impl<'a, T: Table> PtrBuilder<'a, T> { U::try_get_option(self.as_reader()) } - #[inline] - pub fn read_as_struct<'b, S: ty::Struct>(&'b self) -> as FromPtr>>::Output { - self.read_as::>() - } - - #[inline] - pub fn read_as_list_of<'b, V: ty::DynListValue>(&'b self) -> as FromPtr>>::Output { - self.read_as::>() - } - #[inline] pub fn init_struct(self) -> S::Builder<'a, T> { let ptr = self.0.init_struct(S::SIZE); @@ -583,10 +554,6 @@ impl IntoFamily for AnyStruct { type Family = AnyStruct; } -impl ty::Value for AnyStruct { - type Default = ptr::StructReader<'static, Empty>; -} - impl ty::DynListValue for AnyStruct { const PTR_ELEMENT_SIZE: crate::ptr::PtrElementSize = crate::ptr::PtrElementSize::InlineComposite; } @@ -900,13 +867,6 @@ impl IntoFamily for AnyList { type Family = AnyList; } -impl ty::Value for AnyList { - type Default = ptr::ListReader<'static, Empty>; -} -impl ty::ListValue for AnyList { - const ELEMENT_SIZE: list::ElementSize = list::ElementSize::Pointer; -} - // ListReader impls impl<'a, T: Table> AsRef> for ListReader<'a, T> { diff --git a/recapn/src/data.rs b/recapn/src/data.rs index 076d03c..d8194af 100644 --- a/recapn/src/data.rs +++ b/recapn/src/data.rs @@ -22,12 +22,6 @@ impl Sealed for Data {} impl IntoFamily for Data { type Family = Data; } -impl ty::Value for Data { - type Default = Reader<'static>; -} -impl ty::ListValue for Data { - const ELEMENT_SIZE: ElementSize = ElementSize::Pointer; -} pub type Reader<'a> = Data>; diff --git a/recapn/src/field.rs b/recapn/src/field.rs index c8c9d1a..f62f1bb 100644 --- a/recapn/src/field.rs +++ b/recapn/src/field.rs @@ -37,36 +37,34 @@ //! lifetimes respectively. So `&'b ptr::StructReader<'p, T>` could be extended to //! `&'borrow ptr::StructReader<'pointer, T>`. -use core::convert::TryFrom; -use core::marker::PhantomData; +use core::convert::{TryFrom, Infallible as Never}; use core::str::Utf8Error; use crate::any::{AnyList, AnyPtr, AnyStruct}; -use crate::internal::Sealed; use crate::list::{self, ElementSize, InfalliblePtrs, List, TooManyElementsError}; use crate::orphan::{Orphan, Orphanage}; use crate::ptr::{self, Data, ElementCount, ErrorHandler, CopySize, IgnoreErrors, StructSize, UnwrapErrors}; use crate::rpc::{Capable, Empty, InsertableInto, Table}; -use crate::ty::{self, EnumResult, ListValue, StructReader as _}; +use crate::ty::{self, kind, EnumResult, StructReader as _}; use crate::{any, data, text, Error, ErrorKind, Family, NotInSchema, Result}; mod internal { use super::*; pub trait Accessable { - type Group; - unsafe fn group(self) -> Self::Group; + type Group; + unsafe fn group(self) -> Self::Group; type Data; unsafe fn data(self, info: &'static FieldInfo) -> Self::Data; type Enum; - unsafe fn enum_value(self, info: &'static FieldInfo>) -> Self::Enum; + unsafe fn enum_value(self, info: &'static FieldInfo) -> Self::Enum; } impl<'b, 'p, T: Table> Accessable for StructReader<'b, 'p, T> { - type Group = G::Reader<'p, T>; - unsafe fn group(self) -> Self::Group { + type Group = G::Reader<'p, T>; + unsafe fn group(self) -> Self::Group { ty::StructReader::from_ptr(self.clone()) } type Data = D; @@ -74,7 +72,7 @@ mod internal { self.data_field_with_default(info.slot as usize, info.default) } type Enum = EnumResult; - unsafe fn enum_value(self, info: &'static FieldInfo>) -> Self::Enum { + unsafe fn enum_value(self, info: &'static FieldInfo) -> Self::Enum { let &FieldInfo { slot, default } = info; let default: u16 = default.into(); let value = self.data_field_with_default::(slot as usize, default); @@ -83,32 +81,32 @@ mod internal { } impl<'b, 'p, T: Table> Accessable for StructBuilder<'b, 'p, T> { - type Group = G::Builder<'b, T>; - unsafe fn group(self) -> Self::Group { + type Group = G::Builder<'b, T>; + unsafe fn group(self) -> Self::Group { ty::StructBuilder::from_ptr(self.by_ref()) } type Data = DataField; unsafe fn data(self, info: &'static FieldInfo) -> Self::Data { DataField { descriptor: info, repr: self } } - type Enum = DataField, Self>; - unsafe fn enum_value(self, info: &'static FieldInfo>) -> Self::Enum { - DataField { descriptor: info, repr: self } + type Enum = EnumField; + unsafe fn enum_value(self, info: &'static FieldInfo) -> Self::Enum { + EnumField { descriptor: info, repr: self } } } impl<'p, T: Table> Accessable for OwnedStructBuilder<'p, T> { - type Group = G::Builder<'p, T>; - unsafe fn group(self) -> Self::Group { + type Group = G::Builder<'p, T>; + unsafe fn group(self) -> Self::Group { ty::StructBuilder::from_ptr(self) } type Data = DataField; unsafe fn data(self, info: &'static FieldInfo) -> Self::Data { DataField { descriptor: info, repr: self } } - type Enum = DataField, Self>; - unsafe fn enum_value(self, info: &'static FieldInfo>) -> Self::Enum { - DataField { descriptor: info, repr: self } + type Enum = EnumField; + unsafe fn enum_value(self, info: &'static FieldInfo) -> Self::Enum { + EnumField { descriptor: info, repr: self } } } } @@ -119,8 +117,20 @@ pub type StructReader<'b, 'p, T> = &'b ptr::StructReader<'p, T>; pub type StructBuilder<'b, 'p, T> = &'b mut ptr::StructBuilder<'p, T>; use ptr::StructBuilder as OwnedStructBuilder; +/// A "type kind" constraining trait with specializations for field types. +pub trait TypeKind { + type Kind; +} + +impl TypeKind for T +where + T: ty::TypeKind, +{ + type Kind = T::Kind; +} + /// Describes a group of fields. This is primarily used for clearing unions and groups of fields within a struct. -pub trait FieldGroup: ty::StructView { +pub trait Group: ty::TypeKind> + ty::StructView { unsafe fn clear<'b, 'p, T: Table>(a: StructBuilder<'b, 'p, T>); } @@ -140,22 +150,76 @@ pub trait FieldType: Sized + 'static { unsafe fn clear<'a, 'b, T: Table>(a: StructBuilder<'b, 'a, T>, descriptor: &'static Self::Descriptor); } +impl FieldType for T +where + T: TypeKind + 'static, + T::Kind: FieldType, +{ + type Descriptor = ::Descriptor; + + type Accessor = ::Accessor; + #[inline] + unsafe fn accessor(a: A, descriptor: &'static Self::Descriptor) -> Self::Accessor { + ::accessor(a, descriptor) + } + + type VariantAccessor = ::VariantAccessor; + #[inline] + unsafe fn variant(a: A, descriptor: &'static VariantDescriptor) -> Self::VariantAccessor { + ::variant(a, descriptor) + } + + #[inline] + unsafe fn clear<'a, 'b, T2: Table>(a: StructBuilder<'b, 'a, T2>, descriptor: &'static Self::Descriptor) { + ::clear(a, descriptor) + } +} + +/// A marker trait for pointer types. This allows us to generalize pointers for generic pointer +/// fields. +pub trait Ptr: TypeKind> + 'static { + type Default; +} + +impl FieldType for kind::PtrField { + type Descriptor = FieldInfo>; + + type Accessor = PtrField; + #[inline] + unsafe fn accessor(a: A, descriptor: &'static Self::Descriptor) -> Self::Accessor { + PtrField { repr: a, descriptor } + } + + type VariantAccessor = PtrVariant; + #[inline] + unsafe fn variant(a: A, descriptor: &'static VariantDescriptor) -> Self::VariantAccessor { + PtrVariant { repr: a, descriptor } + } + + #[inline] + unsafe fn clear(a: StructBuilder, descriptor: &'static Self::Descriptor) { + a.ptr_field_mut_unchecked(descriptor.slot as u16).clear() + } +} + impl FieldType for () { type Descriptor = (); + type Accessor = (); #[inline] unsafe fn accessor(_: A, _: &'static Self::Descriptor) -> Self::Accessor { () } - type VariantAccessor = VoidVariant; + + type VariantAccessor = VoidVariant; #[inline] unsafe fn variant(a: A, descriptor: &'static VariantDescriptor) -> Self::VariantAccessor { - VoidVariant { t: PhantomData, variant: &descriptor.variant, repr: a } + VariantAccessor { repr: a, descriptor } } #[inline] unsafe fn clear<'b, 'p, T: Table>(_: StructBuilder<'b, 'p, T>, _: &'static Self::Descriptor) {} } -impl FieldType for D { +impl FieldType for kind::Data { type Descriptor = FieldInfo; type Accessor = A::Data; #[inline] @@ -165,7 +229,7 @@ impl FieldType for D { type VariantAccessor = DataVariant; #[inline] unsafe fn variant(a: A, descriptor: &'static VariantDescriptor) -> Self::VariantAccessor { - DataVariant { repr: a, descriptor: &descriptor.field, variant: &descriptor.variant } + VariantAccessor { repr: a, descriptor } } #[inline] unsafe fn clear<'a, 'b, T: Table>(a: StructBuilder<'b, 'a, T>, descriptor: &'static Self::Descriptor) { @@ -176,6 +240,22 @@ impl FieldType for D { /// An alias that makes it easier to name the descriptor type for a given type. pub type Descriptor = ::Descriptor; +/// Describes a variant in a union in a struct. Because this is not attached to a value, it can +/// also be used as group info, as groups aren't values. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct VariantInfo { + pub slot: u32, + pub case: u16, +} + +/// Variant info paired with a field descriptor type. +pub struct VariantField { + pub variant: VariantInfo, + pub field: D, +} + +pub type VariantDescriptor = VariantField>; + /// A trait used to abstract away how a field type is viewed. This is primarily used for unions, /// where we want one type to represent the union in generated code which would be generic over /// T where T is either a reference to an Accessable type or a mutable reference to an @@ -273,22 +353,9 @@ pub type VariantOwned<'p, T, V> = ::VariantAccessor { - pub slot: u32, - pub default: V::Default, -} - -/// Describes a variant in a union in a struct. Because this is not attached to a value, it can -/// also be used as group info, as groups aren't values. -pub struct VariantInfo { +pub struct FieldInfo { pub slot: u32, - pub case: u16, -} - -/// Describes a value in a union variant in a struct. -pub struct VariantDescriptor { - pub variant: VariantInfo, - pub field: Descriptor, + pub default: T, } pub trait UnionViewer { @@ -297,140 +364,181 @@ pub trait UnionViewer { unsafe fn get(accessable: A) -> Result; } -/// A wrapper type used to implement methods for struct fields. -pub struct Struct { - s: PhantomData S>, +pub struct FieldAccessor { + descriptor: &'static Descriptor, + repr: Repr, } -impl Sealed for Struct {} -impl ty::Value for Struct { - type Default = ptr::StructReader<'static>; +pub type FieldReader<'b, 'p, T, V> = FieldAccessor>; +pub type FieldBuilder<'b, 'p, T, V> = FieldAccessor>; +pub type FieldOwner<'p, T, V> = FieldAccessor>; + +impl<'b, 'p, T: Table, V: FieldType> FieldBuilder<'b, 'p, T, V> { + /// Create a new field builder "by reference". This allows a field builder to be reused + /// as many builder functions consume the builder. + #[inline] + pub fn by_ref<'c>(&'c mut self) -> FieldBuilder<'c, 'p, T, V> { + FieldBuilder { + descriptor: self.descriptor, + repr: &mut *self.repr, + } + } } -impl ListValue for Struct { - const ELEMENT_SIZE: ElementSize = ElementSize::InlineComposite(S::SIZE); + +impl<'p, T: Table, V: FieldType> FieldOwner<'p, T, V> { + /// Create a new field builder "by reference". This allows a field builder to be reused + /// as many builder functions consume the builder. + #[inline] + pub fn by_ref<'c>(&'c mut self) -> FieldOwner<'c, T, V> { + FieldOwner { + descriptor: self.descriptor, + repr: self.repr.by_ref(), + } + } } -/// Represents a group of fields in a Cap'n Proto struct. -pub struct Group { - v: PhantomData G>, +pub struct VariantAccessor { + descriptor: &'static VariantDescriptor, + repr: Repr, } -impl FieldType for Group { - type Descriptor = (); - type Accessor = A::Group; +pub type VariantReader<'b, 'p, T, V> = VariantAccessor>; + +impl<'b, 'p, T: Table, V: FieldType> VariantReader<'b, 'p, T, V> { + /// Returns a bool indicating whether or not this field is set in the union #[inline] - unsafe fn accessor(a: A, _: &'static Self::Descriptor) -> Self::Accessor { - unsafe { a.group::() } + pub fn is_set(&self) -> bool { + let VariantInfo { slot, case } = self.descriptor.variant; + self.repr.data_field::(slot as usize) == case } - type VariantAccessor = VoidVariant; + + /// Gets the generic field accessor for this type if the field is set. #[inline] - unsafe fn variant(a: A, descriptor: &'static VariantDescriptor) -> Self::VariantAccessor { - VoidVariant { t: PhantomData, variant: &descriptor.variant, repr: a } + pub fn field(&self) -> Option> { + if self.is_set() { + Some(unsafe { self.field_unchecked() }) + } else { + None + } } + + /// Gets the generic field accessor for this type without checking if the field is set. #[inline] - unsafe fn clear<'a, 'b, T: Table>(a: StructBuilder<'b, 'a, T>, _: &'static Self::Descriptor) { - G::clear(a) + pub unsafe fn field_unchecked(&self) -> Accessor<'b, 'p, T, V> { + V::accessor(self.repr, &self.descriptor.field) } } -pub struct Capability { - c: PhantomData C>, -} - -impl Sealed for Capability {} -impl ty::Value for Capability { - /// Capabilities don't have defaults - type Default = (); -} -impl ListValue for Capability { - const ELEMENT_SIZE: ElementSize = ElementSize::Pointer; -} - -/// A wrapper type used to implement methods for enum fields. -pub struct Enum { - e: PhantomData E>, -} - -impl Sealed for Enum {} -impl ty::Value for Enum { - type Default = E; -} -impl ListValue for Enum { - const ELEMENT_SIZE: ElementSize = ElementSize::TwoBytes; -} +pub type VariantBuilder<'b, 'p, T, V> = VariantAccessor>; -/// A variant accessor type for "void" types (`Void` and groups). -/// -/// This includes not just the Void primitive, but also groups, which are kinda like voids in -/// the sense that they aren't actual "things" on the wire. Void fields take up no encoding space -/// and groups don't take up any encoding space either. They also have no associated data, so they -/// don't have an associated descriptor, just variant info. -pub struct VoidVariant { - t: PhantomData T>, - variant: &'static VariantInfo, - repr: Repr, -} +impl<'b, 'p, T: Table, V: FieldType> VariantBuilder<'b, 'p, T, V> { + /// Create a new field builder "by reference". This allows a field builder to be reused + /// as many builder functions consume the builder. + #[inline] + pub fn by_ref<'c>(&'c mut self) -> VariantBuilder<'c, 'p, T, V> { + VariantBuilder { + descriptor: self.descriptor, + repr: &mut *self.repr, + } + } -impl<'b, 'p, T: Table, U> VoidVariant> { /// Returns a bool indicating whether or not this field is set in the union #[inline] pub fn is_set(&self) -> bool { - let &VariantInfo { slot, case } = self.variant; + let VariantInfo { slot, case } = self.descriptor.variant; self.repr.data_field::(slot as usize) == case } -} -impl<'b, 'p, T: Table, G: FieldGroup> VoidVariant, StructReader<'b, 'p, T>> { + /// Gets the generic field accessor for this type if the field is set. #[inline] - pub fn get(&self) -> Option> { + pub fn field(self) -> Option> { if self.is_set() { - Some(ty::StructReader::from_ptr(self.repr.clone())) + Some(unsafe { self.field_unchecked() }) } else { None } } + /// Gets the generic field accessor for this type without checking if the field is set. #[inline] - pub unsafe fn get_unchecked(&self) -> G::Reader<'p, T> { - ty::StructReader::from_ptr(self.repr.clone()) + pub unsafe fn field_unchecked(self) -> AccessorMut<'b, 'p, T, V> { + V::accessor(self.repr, &self.descriptor.field) } -} -impl<'b, 'p, T: Table, U> VoidVariant> { - /// Returns a bool indicating whether or not this field is set in the union #[inline] - pub fn is_set(&self) -> bool { - let &VariantInfo { slot, case } = self.variant; - unsafe { self.repr.data_field_unchecked::(slot as usize) == case } + pub fn init_field(self) -> AccessorMut<'b, 'p, T, V> { + if !self.is_set() { + let VariantInfo { slot, case } = self.descriptor.variant; + unsafe { + self.repr.set_field_unchecked::(slot as usize, case); + V::clear(self.repr, &self.descriptor.field); + } + } + unsafe { V::accessor(self.repr, &self.descriptor.field) } } #[inline] fn set_variant(&mut self) { - let &VariantInfo { slot, case } = self.variant; + let VariantInfo { slot, case } = self.descriptor.variant; unsafe { self.repr.set_field_unchecked(slot as usize, case) } } } -impl<'b, 'p, T: Table> VoidVariant<(), StructBuilder<'b, 'p, T>> { +pub type VoidVariant = VariantAccessor<(), Repr>; +pub type VoidVariantBuilder<'b, 'p, T> = VariantBuilder<'b, 'p, T, ()>; + +impl<'b, 'p, T: Table> VoidVariantBuilder<'b, 'p, T> { #[inline] pub fn set(&mut self) { self.set_variant(); } } -impl<'b, 'p, T: Table, G: FieldGroup> VoidVariant, StructBuilder<'b, 'p, T>> { +impl FieldType for kind::Group { + type Descriptor = (); + type Accessor = A::Group; + #[inline] + unsafe fn accessor(a: A, _: &'static Self::Descriptor) -> Self::Accessor { + unsafe { a.group::() } + } + type VariantAccessor = VariantAccessor; + #[inline] + unsafe fn variant(a: A, descriptor: &'static VariantDescriptor) -> Self::VariantAccessor { + VariantAccessor { repr: a, descriptor } + } + #[inline] + unsafe fn clear<'a, 'b, T: Table>(a: StructBuilder<'b, 'a, T>, _: &'static Self::Descriptor) { + G::clear(a) + } +} + +pub type GroupVariant = VariantAccessor, Repr>; + +pub type GroupVariantReader<'b, 'p, T, G> = VariantReader<'b, 'p, T, kind::Group>; + +impl<'b, 'p, T: Table, G: Group> GroupVariantReader<'b, 'p, T, G> { + #[inline] + pub fn get(&self) -> Option> { + self.field() + } + + #[inline] + pub unsafe fn get_unchecked(&self) -> G::Reader<'p, T> { + self.field_unchecked() + } +} + +pub type GroupVariantBuilder<'b, 'p, T, G> = VariantBuilder<'b, 'p, T, kind::Group>; + +impl<'b, 'p, T: Table, G: Group> GroupVariantBuilder<'b, 'p, T, G> { #[inline] pub fn get(self) -> Option> { - if self.is_set() { - unsafe { Some(ty::StructBuilder::from_ptr(self.repr.by_ref())) } - } else { - None - } + self.field() } #[inline] pub unsafe fn get_unchecked(self) -> G::Builder<'b, T> { - ty::StructBuilder::from_ptr(self.repr.by_ref()) + self.field_unchecked() } #[inline] @@ -443,64 +551,43 @@ impl<'b, 'p, T: Table, G: FieldGroup> VoidVariant, StructBuilder<'b, 'p } } -pub struct DataField { - descriptor: &'static FieldInfo, - repr: Repr, -} +pub type DataField = FieldAccessor, Repr>; -impl<'b, 'p, T: Table, D: Data> DataField> { +pub type DataFieldBuilder<'b, 'p, T, D> = FieldBuilder<'b, 'p, T, kind::Data>; + +impl<'b, 'p, T: Table, D: Data> DataFieldBuilder<'b, 'p, T, D> { #[inline] pub fn get(&self) -> D { unsafe { self.repr.data_field_with_default_unchecked(self.descriptor.slot as usize, self.descriptor.default) } } - #[inline] pub fn set(&mut self, value: D) { unsafe { self.repr.set_field_with_default_unchecked(self.descriptor.slot as usize, value, self.descriptor.default) } } } -pub struct DataVariant { - descriptor: &'static FieldInfo, - variant: &'static VariantInfo, - repr: Repr, -} +pub type DataVariant = VariantAccessor, Repr>; -impl<'b, 'p, T: Table, D: Data> DataVariant> { - /// Returns a bool indicating whether or not this field is set in the union - #[inline] - pub fn is_set(&self) -> bool { - let &VariantInfo { slot, case } = self.variant; - self.repr.data_field::(slot as usize) == case - } +pub type DataVariantReader<'b, 'p, T, D> = DataVariant>; +impl<'b, 'p, T: Table, D: Data> DataVariantReader<'b, 'p, T, D> { #[inline] pub fn get(&self) -> Option { - let &FieldInfo { slot, default } = self.descriptor; - if self.is_set() { - Some(self.repr.data_field_with_default(slot as usize, default)) - } else { - None - } + self.field() } #[inline] pub fn get_or_default(&self) -> D { - self.get().unwrap_or(self.descriptor.default) + self.get().unwrap_or(self.descriptor.field.default) } } -impl<'b, 'p, T: Table, D: Data> DataVariant> { - /// Returns a bool indicating whether or not this field is set in the union - #[inline] - pub fn is_set(&self) -> bool { - let &VariantInfo { slot, case } = self.variant; - self.repr.data_field::(slot as usize) == case - } +pub type DataVariantBuilder<'b, 'p, T, D> = DataVariant>; +impl<'b, 'p, T: Table, D: Data> DataVariantBuilder<'b, 'p, T, D> { #[inline] pub fn get(&self) -> Option { - let &FieldInfo { slot, default } = self.descriptor; + let FieldInfo { slot, default } = self.descriptor.field; if self.is_set() { Some(unsafe { self.repr.data_field_with_default_unchecked(slot as usize, default) }) } else { @@ -510,13 +597,13 @@ impl<'b, 'p, T: Table, D: Data> DataVariant> { #[inline] pub fn get_or_default(&self) -> D { - self.get().unwrap_or(self.descriptor.default) + self.get().unwrap_or(self.descriptor.field.default) } #[inline] pub fn set(&mut self, value: D) { - let &VariantInfo { slot: variant_slot, case } = self.variant; - let &FieldInfo { slot, default } = self.descriptor; + let VariantInfo { slot: variant_slot, case } = self.descriptor.variant; + let FieldInfo { slot, default } = self.descriptor.field; unsafe { self.repr.set_field_unchecked(variant_slot as usize, case); self.repr.set_field_with_default_unchecked(slot as usize, value, default); @@ -524,17 +611,19 @@ impl<'b, 'p, T: Table, D: Data> DataVariant> { } } -impl FieldType for Enum { - type Descriptor = FieldInfo; +impl FieldType for kind::Enum { + type Descriptor = FieldInfo; type Accessor = A::Enum; + #[inline] unsafe fn accessor(a: A, descriptor: &'static Self::Descriptor) -> Self::Accessor { a.enum_value(descriptor) } - type VariantAccessor = DataVariant; + type VariantAccessor = EnumVariant; + #[inline] unsafe fn variant(a: A, descriptor: &'static VariantDescriptor) -> Self::VariantAccessor { - DataVariant { descriptor: &descriptor.field, variant: &descriptor.variant, repr: a } + EnumVariant { repr: a, descriptor } } #[inline] @@ -543,7 +632,9 @@ impl FieldType for Enum { } } -impl<'b, 'p, T: Table, E: ty::Enum> DataField, StructBuilder<'b, 'p, T>> { +pub type EnumField = FieldAccessor, Repr>; + +impl<'b, 'p, T: Table, E: ty::Enum> EnumField> { #[inline] pub fn get(&self) -> EnumResult { let &FieldInfo { slot, default } = self.descriptor; @@ -566,44 +657,29 @@ impl<'b, 'p, T: Table, E: ty::Enum> DataField, StructBuilder<'b, 'p, T>> } } -impl<'b, 'p, T: Table, E: ty::Enum> DataVariant, StructReader<'b, 'p, T>> { - /// Returns a bool indicating whether or not this field is set in the union - #[inline] - pub fn is_set(&self) -> bool { - let &VariantInfo { slot, case } = self.variant; - self.repr.data_field::(slot as usize) == case - } +pub type EnumVariant = VariantAccessor, Repr>; +pub type EnumVariantReader<'b, 'p, T, E> = EnumVariant>; + +impl<'b, 'p, T: Table, E: ty::Enum> EnumVariantReader<'b, 'p, T, E> { #[inline] pub fn get(&self) -> Option> { - if self.is_set() { - let &FieldInfo { slot, default } = self.descriptor; - let default: u16 = default.into(); - let value = self.repr.data_field_with_default::(slot as usize, default); - Some(E::try_from(value)) - } else { - None - } + self.field() } #[inline] pub fn get_or_default(&self) -> EnumResult { - self.get().unwrap_or(Ok(self.descriptor.default)) + self.get().unwrap_or(Ok(self.descriptor.field.default)) } } -impl<'b, 'p, T: Table, E: ty::Enum> DataVariant, StructBuilder<'b, 'p, T>> { - /// Returns a bool indicating whether or not this field is set in the union - #[inline] - pub fn is_set(&self) -> bool { - let &VariantInfo { slot, case } = self.variant; - unsafe { self.repr.data_field_unchecked::(slot as usize) == case } - } +pub type EnumVariantBuilder<'b, 'p, T, E> = EnumVariant>; +impl<'b, 'p, T: Table, E: ty::Enum> EnumVariantBuilder<'b, 'p, T, E> { #[inline] pub fn get(&self) -> Option> { if self.is_set() { - let &FieldInfo { slot, default } = self.descriptor; + let FieldInfo { slot, default } = self.descriptor.field; let default: u16 = default.into(); let value = unsafe { self.repr.data_field_with_default_unchecked(slot as usize, default) }; Some(E::try_from(value)) @@ -614,13 +690,13 @@ impl<'b, 'p, T: Table, E: ty::Enum> DataVariant, StructBuilder<'b, 'p, T #[inline] pub fn get_or_default(&self) -> EnumResult { - self.get().unwrap_or(Ok(self.descriptor.default)) + self.get().unwrap_or(Ok(self.descriptor.field.default)) } #[inline] pub fn set(&mut self, value: E) { - let &VariantInfo { slot: variant_slot, case } = self.variant; - let &FieldInfo { slot, default } = self.descriptor; + let VariantInfo { slot: variant_slot, case } = self.descriptor.variant; + let FieldInfo { slot, default } = self.descriptor.field; let value: u16 = value.into(); let default: u16 = default.into(); unsafe { @@ -630,16 +706,13 @@ impl<'b, 'p, T: Table, E: ty::Enum> DataVariant, StructBuilder<'b, 'p, T } } -pub struct PtrField { - descriptor: &'static FieldInfo, - repr: Repr, -} +pub type PtrField = FieldAccessor, Repr>; -pub type PtrFieldReader<'b, 'p, T, V> = PtrField>; -pub type PtrFieldBuilder<'b, 'p, T, V> = PtrField>; -pub type PtrFieldOwner<'p, T, V> = PtrField>; +pub type PtrFieldReader<'b, 'p, T, P> = PtrField>; +pub type PtrFieldBuilder<'b, 'p, T, P> = PtrField>; +pub type PtrFieldOwner<'p, T, P> = PtrField>; -impl<'b, 'p, T: Table, V: ty::Value> PtrFieldReader<'b, 'p, T, V> { +impl<'b, 'p, T: Table, P: Ptr> PtrFieldReader<'b, 'p, T, P> { #[inline] fn raw_ptr(&self) -> ptr::PtrReader<'p, T> { self.repr.ptr_field(self.descriptor.slot as u16) @@ -656,17 +729,7 @@ impl<'b, 'p, T: Table, V: ty::Value> PtrFieldReader<'b, 'p, T, V> { } } -impl<'b, 'p, T: Table, V: ty::Value> PtrFieldBuilder<'b, 'p, T, V> { - /// Create a new field builder "by reference". This allows a field builder to be reused - /// as many builder functions consume the builder. - #[inline] - pub fn by_ref<'c>(&'c mut self) -> PtrFieldBuilder<'c, 'p, T, V> { - PtrField { - descriptor: self.descriptor, - repr: &mut *self.repr, - } - } - +impl<'b, 'p, T: Table, P: Ptr> PtrFieldBuilder<'b, 'p, T, P> { #[inline] fn raw_read_ptr(&self) -> ptr::PtrReader { unsafe { self.repr.ptr_field_unchecked(self.descriptor.slot as u16) } @@ -694,12 +757,12 @@ impl<'b, 'p, T: Table, V: ty::Value> PtrFieldBuilder<'b, 'p, T, V> { } #[inline] - pub fn adopt(&mut self, orphan: Orphan) { + pub fn adopt(&mut self, orphan: Orphan) { self.raw_build_ptr().adopt(orphan.into_inner()); } #[inline] - pub fn disown_into<'c>(&mut self, orphanage: &Orphanage<'c, T>) -> Orphan<'c, V, T> { + pub fn disown_into<'c>(&mut self, orphanage: &Orphanage<'c, T>) -> Orphan<'c, P, T> { Orphan::new(self.raw_build_ptr().disown_into(orphanage)) } @@ -714,17 +777,7 @@ impl<'b, 'p, T: Table, V: ty::Value> PtrFieldBuilder<'b, 'p, T, V> { } } -impl<'p, T: Table, V: ty::Value> PtrFieldOwner<'p, T, V> { - /// Create a new field builder "by reference". This allows a field builder to be reused - /// as many builder functions consume the builder. - #[inline] - pub fn by_ref<'c>(&'c mut self) -> PtrFieldOwner<'c, T, V> { - PtrField { - descriptor: self.descriptor, - repr: self.repr.by_ref(), - } - } - +impl<'p, T: Table, P: Ptr> PtrFieldOwner<'p, T, P> { #[inline] fn raw_read_ptr(&self) -> ptr::PtrReader { unsafe { self.repr.ptr_field_unchecked(self.descriptor.slot as u16) } @@ -752,12 +805,12 @@ impl<'p, T: Table, V: ty::Value> PtrFieldOwner<'p, T, V> { } #[inline] - pub fn adopt(&mut self, orphan: Orphan) { + pub fn adopt(&mut self, orphan: Orphan) { self.raw_build_ptr().adopt(orphan.into_inner()); } #[inline] - pub fn disown_into<'c>(&mut self, orphanage: &Orphanage<'c, T>) -> Orphan<'c, V, T> { + pub fn disown_into<'c>(&mut self, orphanage: &Orphanage<'c, T>) -> Orphan<'c, P, T> { Orphan::new(self.raw_build_ptr().disown_into(orphanage)) } @@ -772,33 +825,24 @@ impl<'p, T: Table, V: ty::Value> PtrFieldOwner<'p, T, V> { } } -/// A base type for accessing union variant fields. -pub struct PtrVariant { - descriptor: &'static FieldInfo, - variant: &'static VariantInfo, - repr: Repr, -} +pub type PtrVariant = VariantAccessor, Repr>; pub type PtrVariantReader<'b, 'p, T, V> = PtrVariant>; pub type PtrVariantBuilder<'b, 'p, T, V> = PtrVariant>; pub type PtrVariantOwner<'p, T, V> = PtrVariant>; -impl<'b, 'p, T: Table, V: ty::Value> PtrVariantReader<'b, 'p, T, V> { - /// Returns a bool indicating whether or not this field is set in the union - #[inline] - pub fn is_set(&self) -> bool { - let &VariantInfo { slot, case } = self.variant; - self.repr.data_field::(slot as usize) == case - } - +impl<'b, 'p, T: Table, P: Ptr> PtrVariantReader<'b, 'p, T, P> { #[inline] fn raw_ptr(&self) -> Option> { - self.is_set().then(|| self.repr.ptr_field(self.descriptor.slot as u16)) + self.is_set().then(|| self.repr.ptr_field(self.descriptor.field.slot as u16)) } #[inline] - pub fn field(&self) -> Option> { - self.is_set().then(|| PtrField { descriptor: self.descriptor, repr: self.repr }) + fn raw_ptr_or_null(&self) -> ptr::PtrReader<'b, T> { + match self.raw_ptr() { + Some(ptr) => ptr, + None => ptr::PtrReader::null().imbue_from(self.repr), + } } #[inline] @@ -811,55 +855,20 @@ impl<'b, 'p, T: Table, V: ty::Value> PtrVariantReader<'b, 'p, T, V> { } } -impl<'b, 'p, T: Table, V: ty::Value> PtrVariantBuilder<'b, 'p, T, V> { - /// Returns a bool indicating whether or not this field is set in the union - #[inline] - pub fn is_set(&self) -> bool { - let &VariantInfo { slot, case } = self.variant; - unsafe { self.repr.data_field_unchecked::(slot as usize) == case } - } - - /// Create a new field builder "by reference". This allows a field builder to be reused - /// as many builder functions consume the builder. - #[inline] - pub fn by_ref<'c>(&'c mut self) -> PtrVariantBuilder<'c, 'p, T, V> { - PtrVariant { - descriptor: self.descriptor, - variant: self.variant, - repr: &mut *self.repr, - } - } - +impl<'b, 'p, T: Table, P: Ptr> PtrVariantBuilder<'b, 'p, T, P> { #[inline] fn raw_read_ptr(&self) -> Option> { - self.is_set().then(|| unsafe { self.repr.ptr_field_unchecked(self.descriptor.slot as u16) }) + self.is_set().then(|| unsafe { self.repr.ptr_field_unchecked(self.descriptor.field.slot as u16) }) } #[inline] fn raw_build_ptr(&mut self) -> Option> { - self.is_set().then(|| unsafe { self.repr.ptr_field_mut_unchecked(self.descriptor.slot as u16) }) + self.is_set().then(|| unsafe { self.repr.ptr_field_mut_unchecked(self.descriptor.field.slot as u16) }) } #[inline] fn into_raw_build_ptr(self) -> Option> { - self.is_set().then(|| unsafe { self.repr.ptr_field_mut_unchecked(self.descriptor.slot as u16) }) - } - - #[inline] - pub fn init_field(self) -> PtrFieldBuilder<'b, 'p, T, V> { - if !self.is_set() { - let &VariantInfo { slot, case } = self.variant; - unsafe { - self.repr.set_field_unchecked::(slot as usize, case); - self.repr.ptr_field_mut_unchecked(self.descriptor.slot as u16).clear(); - } - } - PtrField { descriptor: self.descriptor, repr: self.repr } - } - - #[inline] - pub fn field(self) -> Option> { - self.is_set().then(|| PtrField { descriptor: self.descriptor, repr: self.repr }) + self.is_set().then(|| unsafe { self.repr.ptr_field_mut_unchecked(self.descriptor.field.slot as u16) }) } #[inline] @@ -872,19 +881,19 @@ impl<'b, 'p, T: Table, V: ty::Value> PtrVariantBuilder<'b, 'p, T, V> { } #[inline] - pub fn adopt(&mut self, orphan: Orphan) { + pub fn adopt(&mut self, orphan: Orphan) { if !self.is_set() { - let &VariantInfo { slot, case } = self.variant; + let VariantInfo { slot, case } = self.descriptor.variant; unsafe { self.repr.set_field_unchecked::(slot as usize, case); } } - let mut ptr = unsafe { self.repr.ptr_field_mut_unchecked(self.descriptor.slot as u16) }; + let mut ptr = unsafe { self.repr.ptr_field_mut_unchecked(self.descriptor.field.slot as u16) }; ptr.adopt(orphan.into_inner()); } #[inline] - pub fn disown_into<'c>(&mut self, orphanage: &Orphanage<'c, T>) -> Option> { + pub fn disown_into<'c>(&mut self, orphanage: &Orphanage<'c, T>) -> Option> { self.raw_build_ptr().map(|mut p| Orphan::new(p.disown_into(orphanage))) } @@ -901,60 +910,278 @@ impl<'b, 'p, T: Table, V: ty::Value> PtrVariantBuilder<'b, 'p, T, V> { } } -impl<'p, T: Table, V: ty::Value> PtrVariantOwner<'p, T, V> { - /// Returns a bool indicating whether or not this field is set in the union +impl<'p, T: Table, P: Ptr> PtrVariantOwner<'p, T, P> { +} + +impl TypeKind for kind::Struct { + type Kind = kind::PtrField; +} +impl Ptr for kind::Struct { + type Default = ptr::StructReader<'static>; +} + +pub type StructField = PtrField, Repr>; + +pub type StructFieldReader<'b, 'p, T, S> = StructField>; +pub type StructFieldBuilder<'b, 'p, T, S> = StructField>; +pub type StructFieldOwner<'p, T, S> = StructField>; + +impl StructField { #[inline] - pub fn is_set(&self) -> bool { - let &VariantInfo { slot, case } = self.variant; - unsafe { self.repr.data_field_unchecked::(slot as usize) == case } + fn default_ptr(&self) -> ptr::StructReader<'static> { + self.descriptor.default.clone().unwrap_or(ptr::StructReader::empty()) + } + + /// Returns the default value of the field + #[inline] + pub fn default(&self) -> S::Reader<'static, Empty> { + ty::StructReader::from_ptr(self.default_ptr()) } } -/// A macro to make implementing FieldType and AccessableField for non-generic ptr types easy -macro_rules! field_type_items { - () => { - type Descriptor = FieldInfo; +impl<'b, 'p, T: Table, S: ty::Struct> StructFieldReader<'b, 'p, T, S> { + #[inline] + fn default_imbued_ptr(&self) -> ptr::StructReader<'static, T> { + self.default_ptr().imbue_from(self.repr) + } - type Accessor = PtrField; - #[inline] - unsafe fn accessor(a: A, descriptor: &'static Self::Descriptor) -> Self::Accessor { - PtrField { descriptor, repr: a } + #[inline] + fn get_ptr(&self) -> ptr::StructReader<'b, T> { + match self.raw_ptr().to_struct() { + Ok(Some(ptr)) => ptr, + _ => self.default_imbued_ptr(), } + } - type VariantAccessor = PtrVariant; - #[inline] - unsafe fn variant(a: A, descriptor: &'static VariantDescriptor) -> Self::VariantAccessor { - PtrVariant { descriptor: &descriptor.field, variant: &descriptor.variant, repr: a } + #[inline] + pub fn get(&self) -> S::Reader<'b, T> { + ty::StructReader::from_ptr(self.get_ptr()) + } + + #[inline] + pub fn get_option(&self) -> Option> { + self.try_get_option().ok().flatten() + } + + #[inline] + fn try_get_ptr(&self) -> Result> { + match self.raw_ptr().to_struct() { + Ok(Some(ptr)) => Ok(ptr), + Ok(None) => Ok(self.default_imbued_ptr()), + Err(err) => Err(err), } + } + + #[inline] + pub fn try_get(&self) -> Result> { + self.try_get_ptr().map(ty::StructReader::from_ptr) + } - #[inline] - unsafe fn clear<'a, 'b, T: Table>(a: StructBuilder<'b, 'a, T>, descriptor: &'static Self::Descriptor) { - a.ptr_field_mut_unchecked(descriptor.slot as u16).clear(); + #[inline] + pub fn try_get_option(&self) -> Result>> { + match self.raw_ptr().to_struct() { + Ok(Some(ptr)) => Ok(Some(ty::StructReader::from_ptr(ptr))), + Ok(None) => Ok(None), + Err(err) => Err(err), } - }; + } } -// impls for list +impl<'b, 'p, T: Table, S: ty::Struct> StructFieldBuilder<'b, 'p, T, S> { + /// Returns a builder for the field. If it's not set or a error occurs while reading the + /// existing value, the field default is set in its place instead. + #[inline] + pub fn get(self) -> S::Builder<'b, T> { + let default = self.default_ptr(); + let ptr = match self.into_raw_build_ptr().to_struct_mut(Some(S::SIZE)) { + Ok(ptr) => ptr, + Err((_, ptr)) => { + let mut builder = ptr.init_struct(S::SIZE); + builder.copy_with_caveats(&default, false); + builder + } + }; + unsafe { ty::StructBuilder::from_ptr(ptr) } + } + + #[inline] + pub fn init(self) -> S::Builder<'b, T> { + unsafe { ty::StructBuilder::from_ptr(self.into_raw_build_ptr().init_struct(S::SIZE)) } + } -impl FieldType for List { - field_type_items!{} + /// Returns a builder for the field. If it's not set or a error occurs while reading the + /// existing value, the struct default is set instead. + #[inline] + pub fn get_or_init(self) -> S::Builder<'b, T> { + let ptr = self.into_raw_build_ptr().to_struct_mut_or_init(S::SIZE); + unsafe { ty::StructBuilder::from_ptr(ptr) } + } + + /// Try to set this field to a copy of the given value. + /// + /// If an error occurs while reading the input value, it's passed to the error handler, which + /// can choose to write null instead or return an error. + #[inline] + pub fn try_set( + self, + value: &S::Reader<'_, T2>, + err_handler: E, + ) -> Result<(), E::Error> + where + T2: InsertableInto, + E: ErrorHandler, + { + self.into_raw_build_ptr().try_set_struct(value.as_ptr(), ptr::CopySize::Minimum(S::SIZE), err_handler) + } + + #[inline] + pub fn set(self, value: &S::Reader<'_, T2>) + where + T2: InsertableInto, + { + self.try_set(value, IgnoreErrors).unwrap() + } } -impl<'b, 'p, T: Table, V> PtrFieldReader<'b, 'p, T, List> -where - V: ty::DynListValue, -{ +pub type StructVariant = PtrVariant, Repr>; + +pub type StructVariantReader<'b, 'p, T, S> = StructVariant>; +pub type StructVariantBuilder<'b, 'p, T, S> = StructVariant>; +pub type StructVariantOwner<'p, T, S> = StructVariant>; + +impl StructVariant { #[inline] - fn default(&self) -> list::Reader<'static, V, T> { - let default = &self.descriptor.default; - assert!(default.element_size().upgradable_to(V::PTR_ELEMENT_SIZE)); + fn default_ptr(&self) -> ptr::StructReader<'static> { + self.descriptor.field.default.clone().unwrap_or(ptr::StructReader::empty()) + } + + /// Returns the default value of the field + #[inline] + pub fn default(&self) -> S::Reader<'static, Empty> { + ty::StructReader::from_ptr(self.default_ptr()) + } +} + +impl<'b, 'p, T: Table, S: ty::Struct> StructVariantReader<'b, 'p, T, S> { + #[inline] + fn default_imbued_ptr(&self) -> ptr::StructReader<'static, T> { + self.default_ptr().imbue_from(self.repr) + } + + #[inline] + fn default_imbued(&self) -> S::Reader<'static, T> { + ty::StructReader::from_ptr(self.default_imbued_ptr()) + } + + #[inline] + pub fn get_or_default(&self) -> S::Reader<'b, T> { + let ptr = match self.raw_ptr_or_null().to_struct() { + Ok(Some(ptr)) => ptr, + _ => self.default_imbued_ptr(), + }; + + ty::StructReader::from_ptr(ptr) + } + + #[inline] + pub fn get_option(&self) -> Option> { + self.try_get_option().ok().flatten() + } + + #[inline] + pub fn try_get(&self) -> Result> { + let ptr = match self.raw_ptr_or_null().to_struct() { + Ok(Some(ptr)) => ptr, + Ok(None) => self.default_imbued_ptr(), + Err(err) => return Err(err), + }; + + Ok(ty::StructReader::from_ptr(ptr)) + } + + #[inline] + pub fn try_get_option(&self) -> Result>> { + self.field() + .map(|r| r.try_get_option()) + .transpose() + .map(Option::flatten) + } +} + +impl<'b, 'p, T: Table, S: ty::Struct> StructVariantBuilder<'b, 'p, T, S> { + /// Returns a builder for the field. If it's not set or a error occurs while reading the + /// existing value, the field default is set in its place instead. + #[inline] + pub fn get(self) -> S::Builder<'b, T> { + self.init_field().get() + } - List::new(default.clone().imbue_from(self.repr)) + #[inline] + pub fn init(self) -> S::Builder<'b, T> { + self.init_field().init() + } + + /// Returns a builder for the field. If it's not set or a error occurs while reading the + /// existing value, the struct default is set instead. + #[inline] + pub fn get_or_init(self) -> S::Builder<'b, T> { + self.init_field().get_or_init() + } + + #[inline] + pub fn try_set( + self, + value: &S::Reader<'_, impl InsertableInto>, + err_handler: E, + ) -> Result<(), E::Error> + where + E: ErrorHandler, + { + self.init_field().try_set(value, err_handler) + } + + #[inline] + pub fn set(self, value: &S::Reader<'_, impl InsertableInto>) { + self.init_field().set(value) + } +} + +impl TypeKind for List { + type Kind = kind::PtrField; +} +impl Ptr for List { + type Default = ptr::ListReader<'static>; +} + +pub type ListField = PtrField, Repr>; + +pub type ListFieldReader<'b, 'p, T, V> = ListField>; +pub type ListFieldBuilder<'b, 'p, T, V> = ListField>; +pub type ListFieldOwner<'p, T, V> = ListField>; + +impl ListField { + #[inline] + fn default_ptr(&self) -> ptr::ListReader<'static> { + self.descriptor.default.clone() + .unwrap_or_else(|| ptr::ListReader::empty(V::PTR_ELEMENT_SIZE.to_element_size())) + } + + /// Returns the default value of the field + #[inline] + pub fn default(&self) -> list::Reader<'static, V, Empty> { + List::new(self.default_ptr()) + } +} + +impl<'b, 'p, T: Table, V: ty::DynListValue> ListFieldReader<'b, 'p, T, V> { + #[inline] + fn default_imbued(&self) -> list::Reader<'static, V, T> { + self.default().imbue_from(self.repr) } #[inline] pub fn get(&self) -> list::Reader<'p, V, T> { - self.get_option().unwrap_or_else(|| self.default()) + self.get_option().unwrap_or_else(|| self.default_imbued()) } #[inline] @@ -965,7 +1192,7 @@ where #[inline] pub fn try_get(&self) -> Result> { self.try_get_option() - .map(|op| op.unwrap_or_else(|| self.default())) + .map(|op| op.unwrap_or_else(|| self.default_imbued())) } #[inline] @@ -981,23 +1208,25 @@ where } } -impl<'b, 'p, T: Table, V> PtrFieldReader<'b, 'p, T, List> +impl<'b, 'p, T: Table, V: ty::DynListValue> ListFieldReader<'b, 'p, T, V> where - V: ty::DynListValue + for<'lb> list::ListAccessable<&'lb list::Reader<'p, V, T>>, + V: list::IterKind, + V::Iter: for<'lb> list::ListAccessable<&'lb list::ptr::Reader<'p, T>>, { #[inline] pub fn iter_by(&self, strat: S) -> list::Iter<'p, V, S, T> where - S: for<'lb> list::IterStrategy>, + S: for<'lb> list::IterStrategy<&'lb list::ptr::Reader<'p, T>, V>, { self.get().into_iter_by(strat) } } -impl<'b, 'p, T: Table, V, Item> IntoIterator for PtrFieldReader<'b, 'p, T, List> +impl<'b, 'p, T: Table, V: ty::DynListValue, Item> IntoIterator for ListFieldReader<'b, 'p, T, V> where - V: ty::DynListValue + for<'lb> list::ListAccessable<&'lb list::Reader<'p, V, T>>, - InfalliblePtrs: for<'lb> list::IterStrategy, Item = Item>, + V: list::IterKind, + V::Iter: for<'lb> list::ListAccessable<&'lb list::ptr::Reader<'p, T>>, + InfalliblePtrs: for<'lb> list::IterStrategy<&'lb list::ptr::Reader<'p, T>, V::Iter, Item = Item>, { type IntoIter = list::Iter<'p, V, InfalliblePtrs, T>; type Item = Item; @@ -1008,44 +1237,7 @@ where } } -impl<'b, 'p, T: Table, V: ty::DynListValue> PtrVariantReader<'b, 'p, T, List> { - #[inline] - fn default(&self) -> list::Reader<'static, V, T> { - let default = &self.descriptor.default; - assert!(default.element_size().upgradable_to(V::PTR_ELEMENT_SIZE)); - - List::new(default.clone().imbue_from(self.repr)) - } - - #[inline] - pub fn get_or_default(&self) -> list::Reader<'p, V, T> { - self.try_get_option() - .ok() - .flatten() - .unwrap_or_else(|| self.default()) - } - - #[inline] - pub fn get_option(&self) -> Option> { - self.try_get_option().ok().flatten() - } - - #[inline] - pub fn try_get(&self) -> Result> { - self.try_get_option() - .map(|op| op.unwrap_or_else(|| self.default())) - } - - #[inline] - pub fn try_get_option(&self) -> Result>> { - self.field() - .map(|r| r.try_get_option()) - .transpose() - .map(Option::flatten) - } -} - -impl<'b, 'p, T: Table, V: ty::ListValue> PtrFieldBuilder<'b, 'p, T, List> { +impl<'b, 'p, T: Table, V: ty::ListValue> ListFieldBuilder<'b, 'p, T, V> { /// Returns a builder for the field. If it's not set or a error occurs while reading the /// existing value, the default is set instead. #[inline] @@ -1054,9 +1246,13 @@ impl<'b, 'p, T: Table, V: ty::ListValue> PtrFieldBuilder<'b, 'p, T, List> { match self.into_raw_build_ptr().to_list_mut(Some(V::ELEMENT_SIZE)) { Ok(ptr) => List::new(ptr), Err((_, ptr)) => { - assert_eq!(default.element_size(), V::ELEMENT_SIZE); - let mut new_list = ptr.init_list(V::ELEMENT_SIZE, default.len()); - new_list.try_copy_from(default, UnwrapErrors).unwrap(); + let new_list = if let Some(default) = default { + let mut new_list = ptr.init_list(V::ELEMENT_SIZE, default.len()); + new_list.try_copy_from(default, UnwrapErrors).unwrap(); + new_list + } else { + ptr.into_empty_list(V::ELEMENT_SIZE) + }; List::new(new_list) } } @@ -1107,7 +1303,7 @@ impl<'b, 'p, T: Table, V: ty::ListValue> PtrFieldBuilder<'b, 'p, T, List> { } } -impl<'b, 'p, T: Table> PtrFieldBuilder<'b, 'p, T, List> { +impl<'b, 'p, T: Table> ListFieldBuilder<'b, 'p, T, AnyStruct> { /// Returns a builder for the field. If it's not set or a error occurs while reading the /// existing value, the default is set instead. #[inline] @@ -1118,20 +1314,22 @@ impl<'b, 'p, T: Table> PtrFieldBuilder<'b, 'p, T, List> { .to_list_mut(expected_size.map(ElementSize::InlineComposite)) { Ok(ptr) => ptr, - Err((_, ptr)) => { - let default_size = default.element_size(); - let size = match expected_size { - Some(e) => { - let expected = ElementSize::InlineComposite(e); - default_size.upgrade_to(expected) - .expect("default value can't be upgraded to struct list!") - }, - None => default_size, - }; - let mut builder = ptr.init_list(size, default.len()); - builder.try_copy_from(default, UnwrapErrors).unwrap(); - builder - } + Err((_, ptr)) => if let Some(default) = default { + let default_size = default.element_size(); + let size = match expected_size { + Some(e) => { + let expected = ElementSize::InlineComposite(e); + default_size.upgrade_to(expected) + .expect("default value can't be upgraded to struct list!") + }, + None => default_size, + }; + let mut builder = ptr.init_list(size, default.len()); + builder.try_copy_from(default, UnwrapErrors).unwrap(); + builder + } else { + ptr.into_empty_list(ElementSize::InlineComposite(StructSize::EMPTY)) + } }; List::new(ptr) } @@ -1148,157 +1346,53 @@ impl<'b, 'p, T: Table> PtrFieldBuilder<'b, 'p, T, List> { // TODO the rest of the accessors } -impl<'b, 'p, T: Table, V: ty::DynListValue> PtrVariantBuilder<'b, 'p, T, List> { - // TODO acceessors -} +pub type ListVariant = PtrVariant, Repr>; -impl FieldType for Struct { - field_type_items!{} -} +pub type ListVariantReader<'b, 'p, T, V> = ListVariant>; +pub type ListVariantBuilder<'b, 'p, T, V> = ListVariant>; +pub type ListVariantOwner<'p, T, V> = ListVariant>; -impl PtrField, Repr> { +impl ListVariant { #[inline] - fn default_ptr(&self) -> ptr::StructReader<'static> { - self.descriptor.default.clone() + fn default_ptr(&self) -> ptr::ListReader<'static> { + self.descriptor.field.default.clone() + .unwrap_or_else(|| ptr::ListReader::empty(V::PTR_ELEMENT_SIZE.to_element_size())) } /// Returns the default value of the field #[inline] - pub fn default(&self) -> S::Reader<'static, Empty> { - ty::StructReader::from_ptr(self.default_ptr()) - } -} - -impl<'b, 'p, T: Table, S> PtrFieldReader<'b, 'p, T, Struct> -where - S: ty::Struct, -{ - #[inline] - fn default_imbued_ptr(&self) -> ptr::StructReader<'static, T> { - self.default_ptr().imbue_from(self.repr) - } - - #[inline] - pub fn get(&self) -> S::Reader<'b, T> { - ty::StructReader::from_ptr(match self.raw_ptr().to_struct() { - Ok(Some(ptr)) => ptr, - _ => self.default_imbued_ptr(), - }) - } - - #[inline] - pub fn get_option(&self) -> Option> { - self.try_get_option().ok().flatten() - } - - #[inline] - pub fn try_get(&self) -> Result> { - Ok(ty::StructReader::from_ptr(match self.raw_ptr().to_struct() { - Ok(Some(ptr)) => ptr, - Ok(None) => self.default_imbued_ptr(), - Err(err) => return Err(err), - })) - } - - #[inline] - pub fn try_get_option(&self) -> Result>> { - match self.raw_ptr().to_struct() { - Ok(Some(ptr)) => Ok(Some(ty::StructReader::from_ptr(ptr))), - Ok(None) => Ok(None), - Err(err) => Err(err), - } + pub fn default(&self) -> list::Reader<'static, V, Empty> { + List::new(self.default_ptr()) } } -impl<'b, 'p: 'b, T: Table + 'p, S> PtrFieldBuilder<'b, 'p, T, Struct> -where - S: ty::Struct, -{ - /// Returns a builder for the field. If it's not set or a error occurs while reading the - /// existing value, the field default is set in its place instead. - #[inline] - pub fn get(self) -> S::Builder<'b, T> { - let default = &self.descriptor.default; - let ptr = match self.into_raw_build_ptr().to_struct_mut(Some(S::SIZE)) { - Ok(ptr) => ptr, - Err((_, ptr)) => { - let mut builder = ptr.init_struct(S::SIZE); - builder.copy_with_caveats(default, false); - builder - } - }; - unsafe { ty::StructBuilder::from_ptr(ptr) } - } - +impl<'b, 'p, T: Table, V: ty::DynListValue> ListVariantReader<'b, 'p, T, V> { #[inline] - pub fn init(self) -> S::Builder<'b, T> { - unsafe { ty::StructBuilder::from_ptr(self.into_raw_build_ptr().init_struct(S::SIZE)) } - } - - /// Returns a builder for the field. If it's not set or a error occurs while reading the - /// existing value, the struct default is set instead. - #[inline] - pub fn get_or_init(self) -> S::Builder<'b, T> { - let ptr = self.into_raw_build_ptr().to_struct_mut_or_init(S::SIZE); - unsafe { ty::StructBuilder::from_ptr(ptr) } - } - - /// Try to set this field to a copy of the given value. - /// - /// If an error occurs while reading the input value, it's passed to the error handler, which - /// can choose to write null instead or return an error. - #[inline] - pub fn try_set( - self, - value: &S::Reader<'_, T2>, - err_handler: E, - ) -> Result<(), E::Error> - where - T2: InsertableInto, - E: ErrorHandler, - { - self.into_raw_build_ptr().try_set_struct(value.as_ptr(), ptr::CopySize::Minimum(S::SIZE), err_handler) - } - - #[inline] - pub fn set(self, value: &S::Reader<'_, T2>) - where - T2: InsertableInto, - { - self.try_set(value, IgnoreErrors).unwrap() - } -} - -impl<'b, 'p: 'b, T: Table + 'p, S> PtrVariantReader<'b, 'p, T, Struct> -where - S: ty::Struct, -{ - #[inline] - fn default(&self) -> S::Reader<'b, T> { - self.descriptor.default.clone().imbue_from(self.repr).into() + fn default_imbued(&self) -> list::Reader<'static, V, T> { + self.default().imbue_from(self.repr) } #[inline] - pub fn get_or_default(&self) -> S::Reader<'b, T> { + pub fn get_or_default(&self) -> list::Reader<'p, V, T> { self.try_get_option() .ok() .flatten() - .unwrap_or_else(|| self.default()) + .unwrap_or_else(|| self.default_imbued()) } #[inline] - pub fn get_option(&self) -> Option> { + pub fn get_option(&self) -> Option> { self.try_get_option().ok().flatten() } #[inline] - pub fn try_get(&self) -> Result> { + pub fn try_get(&self) -> Result> { self.try_get_option() - .map(|op| op.unwrap_or_else(|| self.default())) + .map(|op| op.unwrap_or_else(|| self.default_imbued())) } #[inline] - pub fn try_get_option(&self) -> Result>> { + pub fn try_get_option(&self) -> Result>> { self.field() .map(|r| r.try_get_option()) .transpose() @@ -1306,60 +1400,32 @@ where } } -impl<'b, 'p: 'b, T: Table + 'p, S> PtrVariantBuilder<'b, 'p, T, Struct> -where - S: ty::Struct, -{ - /// Returns a builder for the field. If it's not set or a error occurs while reading the - /// existing value, the field default is set in its place instead. - #[inline] - pub fn get(self) -> S::Builder<'b, T> { - self.init_field().get() - } - - #[inline] - pub fn init(self) -> S::Builder<'b, T> { - self.init_field().init() - } - - /// Returns a builder for the field. If it's not set or a error occurs while reading the - /// existing value, the struct default is set instead. - #[inline] - pub fn get_or_init(self) -> S::Builder<'b, T> { - self.init_field().get_or_init() - } - - #[inline] - pub fn try_set( - self, - value: &S::Reader<'_, impl InsertableInto>, - err_handler: E, - ) -> Result<(), E::Error> - where - E: ErrorHandler, - { - self.init_field().try_set(value, err_handler) - } - - #[inline] - pub fn set(self, value: &S::Reader<'_, impl InsertableInto>) { - self.init_field().set(value) - } +impl<'b, 'p, T: Table, V: ty::DynListValue> ListVariantBuilder<'b, 'p, T, V> { + // TODO acceessors } -impl FieldType for text::Text { - field_type_items!{} +impl TypeKind for text::Text { + type Kind = kind::PtrField; +} +impl Ptr for text::Text { + type Default = text::Reader<'static>; } -impl PtrField { +pub type TextField = PtrField; + +pub type TextFieldReader<'b, 'p, T> = TextField>; +pub type TextFieldBuilder<'b, 'p, T> = TextField>; +pub type TextFieldOwner<'p, T> = TextField>; + +impl TextField { /// Returns the default value of the field #[inline] pub fn default(&self) -> text::Reader<'static> { - self.descriptor.default + self.descriptor.default.clone().unwrap_or(text::Reader::empty()) } } -impl<'b, 'p: 'b, T: Table + 'p> PtrFieldReader<'b, 'p, T, text::Text> { +impl<'b, 'p, T: Table> TextFieldReader<'b, 'p, T> { #[inline] pub fn get(&self) -> text::Reader<'b> { self.get_option().unwrap_or_else(|| self.default()) @@ -1401,12 +1467,12 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrFieldReader<'b, 'p, T, text::Text> { } } -impl<'b, 'p: 'b, T: Table + 'p> PtrFieldBuilder<'b, 'p, T, text::Text> { +impl<'b, 'p, T: Table> TextFieldBuilder<'b, 'p, T> { /// Returns a builder for the field. If it's not set or a error occurs while reading the /// existing value, the default is set instead. #[inline] pub fn get(self) -> text::Builder<'b> { - let default = self.descriptor.default; + let default = self.default(); let blob = match self.into_raw_build_ptr().to_blob_mut() { Ok(b) => b, Err((_, ptr)) => ptr.set_blob(default.into()), @@ -1461,27 +1527,36 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrFieldBuilder<'b, 'p, T, text::Text> { } } -impl<'b, 'p: 'b, T: Table + 'p> PtrVariantReader<'b, 'p, T, text::Text> { +impl<'b, 'p, T: Table> PtrVariantReader<'b, 'p, T, text::Text> { } -impl<'b, 'p: 'b, T: Table + 'p> PtrVariantBuilder<'b, 'p, T, text::Text> { +impl<'b, 'p, T: Table> PtrVariantBuilder<'b, 'p, T, text::Text> { } -impl FieldType for data::Data { - field_type_items!{} +impl TypeKind for data::Data { + type Kind = kind::PtrField; } +impl Ptr for data::Data { + type Default = data::Reader<'static>; +} + +pub type DataBlobField = PtrField; + +pub type DataBlobFieldReader<'b, 'p, T> = DataBlobField>; +pub type DataBlobFieldBuilder<'b, 'p, T> = DataBlobField>; +pub type DataBlobFieldOwner<'p, T> = DataBlobField>; -impl PtrField { +impl DataBlobField { /// Returns the default value of the field #[inline] pub fn default(&self) -> data::Reader<'static> { - self.descriptor.default.clone().into() + self.descriptor.default.clone().unwrap_or(data::Reader::empty()) } } -impl<'b, 'p, T: Table + 'p> PtrFieldReader<'b, 'p, T, data::Data> { +impl<'b, 'p, T: Table> DataBlobFieldReader<'b, 'p, T> { #[inline] pub fn get(&self) -> data::Reader<'b> { self.get_option().unwrap_or_else(|| self.default()) @@ -1508,12 +1583,12 @@ impl<'b, 'p, T: Table + 'p> PtrFieldReader<'b, 'p, T, data::Data> { } } -impl<'b, 'p: 'b, T: Table + 'p> PtrFieldBuilder<'b, 'p, T, data::Data> { +impl<'b, 'p, T: Table> DataBlobFieldBuilder<'b, 'p, T> { /// Returns a builder for the field. If it's not set or a error occurs while reading the /// existing value, the default is set instead. #[inline] pub fn get(self) -> data::Builder<'b> { - let default = self.descriptor.default; + let default = self.default(); match self.into_raw_build_ptr().to_blob_mut() { Ok(data) => data, Err((_, ptr)) => ptr.set_blob(default.into()), @@ -1564,8 +1639,11 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrVariantBuilder<'b, 'p, T, data::Data> { // TODO accessors } -impl FieldType for AnyPtr { - field_type_items!(); +impl TypeKind for AnyPtr { + type Kind = kind::PtrField; +} +impl Ptr for AnyPtr { + type Default = ptr::PtrReader<'static>; } impl<'b, 'p: 'b, T: Table + 'p> PtrVariantReader<'b, 'p, T, AnyPtr> { @@ -1576,15 +1654,24 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrVariantBuilder<'b, 'p, T, AnyPtr> { // TODO accessors } -impl FieldType for AnyStruct { - field_type_items!{} +impl TypeKind for AnyStruct { + type Kind = kind::PtrField; +} +impl Ptr for AnyStruct { + type Default = ptr::StructReader<'static>; } -impl PtrField { +pub type AnyStructField = PtrField; + +pub type AnyStructFieldReader<'b, 'p, T> = AnyStructField>; +pub type AnyStructFieldBuilder<'b, 'p, T> = AnyStructField>; +pub type AnyStructFieldOwner<'p, T> = AnyStructField>; + +impl AnyStructField { /// Returns the default value of the field #[inline] fn default_ptr(&self) -> ptr::StructReader<'static> { - self.descriptor.default.clone() + self.descriptor.default.clone().unwrap_or(ptr::StructReader::empty()) } /// Returns the default value of the field @@ -1594,7 +1681,7 @@ impl PtrField { } } -impl<'b, 'p: 'b, T: Table + 'p> PtrFieldReader<'b, 'p, T, AnyStruct> { +impl<'b, 'p, T: Table> AnyStructFieldReader<'b, 'p, T> { #[inline] fn default_imbued(&self) -> any::StructReader<'static, T> { self.default().imbue_from(self.repr) @@ -1626,27 +1713,30 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrFieldReader<'b, 'p, T, AnyStruct> { } } -impl<'b, 'p: 'b, T: Table + 'p> PtrFieldBuilder<'b, 'p, T, AnyStruct> { +impl<'b, 'p, T: Table> AnyStructFieldBuilder<'b, 'p, T> { // TODO accessors } -impl<'b, 'p: 'b, T: Table + 'p> PtrVariantReader<'b, 'p, T, AnyStruct> { +impl<'b, 'p, T: Table> PtrVariantReader<'b, 'p, T, AnyStruct> { // TODO accessors } -impl<'b, 'p: 'b, T: Table + 'p> PtrVariantBuilder<'b, 'p, T, AnyStruct> { +impl<'b, 'p, T: Table> PtrVariantBuilder<'b, 'p, T, AnyStruct> { // TODO accessors } -impl FieldType for AnyList { - field_type_items!{} +impl TypeKind for AnyList { + type Kind = kind::PtrField; +} +impl Ptr for AnyList { + type Default = ptr::ListReader<'static>; } impl PtrField { /// Returns the default value of the field #[inline] fn default_ptr(&self) -> ptr::ListReader<'static> { - self.descriptor.default.clone() + self.descriptor.default.clone().unwrap_or(ptr::ListReader::empty(ElementSize::InlineComposite(StructSize::EMPTY))) } /// Returns the default value of the field @@ -1656,7 +1746,7 @@ impl PtrField { } } -impl<'b, 'p: 'b, T: Table + 'p> PtrFieldReader<'b, 'p, T, AnyList> { +impl<'b, 'p, T: Table> PtrFieldReader<'b, 'p, T, AnyList> { #[inline] fn default_imbued(&self) -> any::ListReader<'static, T> { self.default().imbue_from(self.repr) @@ -1688,42 +1778,48 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrFieldReader<'b, 'p, T, AnyList> { } } -impl<'b, 'p: 'b, T: Table + 'p> PtrFieldBuilder<'b, 'p, T, AnyList> { +impl<'b, 'p, T: Table> PtrFieldBuilder<'b, 'p, T, AnyList> { // TODO accessors } -impl<'b, 'p: 'b, T: Table + 'p> PtrVariantReader<'b, 'p, T, AnyList> { +impl<'b, 'p, T: Table> PtrVariantReader<'b, 'p, T, AnyList> { // TODO accessors } -impl<'b, 'p: 'b, T: Table + 'p> PtrVariantBuilder<'b, 'p, T, AnyList> { +impl<'b, 'p, T: Table> PtrVariantBuilder<'b, 'p, T, AnyList> { // TODO accessors } -impl FieldType for Capability { - field_type_items!{} +impl TypeKind for kind::Capability { + type Kind = kind::PtrField; +} +impl Ptr for kind::Capability { + /// Capabilities don't have defaults + type Default = Never; } -impl<'b, 'p, T, C> PtrFieldReader<'b, 'p, T, Capability> -where - T: Table, - C: ty::Capability, -{ +pub type CapabilityField = PtrField, Repr>; + +pub type CapabilityFieldReader<'b, 'p, T, C> = CapabilityField>; +pub type CapabilityFieldBuilder<'b, 'p, T, C> = CapabilityField>; + +impl<'b, 'p, T: Table, C: ty::Capability> CapabilityFieldReader<'b, 'p, T, C> { // TODO accessors } -impl<'b, 'p, T, C> PtrFieldBuilder<'b, 'p, T, Capability> -where - T: Table, - C: ty::Capability, -{ +impl<'b, 'p, T: Table, C: ty::Capability> CapabilityFieldBuilder<'b, 'p, T, C> { // TODO accessors } -impl<'b, 'p, T: Table, C: ty::Capability> PtrVariantReader<'b, 'p, T, Capability> { +pub type CapabilityVariant = PtrVariant, Repr>; + +pub type CapabilityVariantReader<'b, 'p, T, C> = CapabilityVariant>; +pub type CapabilityVariantBuilder<'b, 'p, T, C> = CapabilityVariant>; + +impl<'b, 'p, T: Table, C: ty::Capability> CapabilityVariantReader<'b, 'p, T, C> { // TODO accessors } -impl<'b, 'p, T: Table, C: ty::Capability> PtrVariantBuilder<'b, 'p, T, Capability> { +impl<'b, 'p, T: Table, C: ty::Capability> CapabilityVariantBuilder<'b, 'p, T, C> { // TODO accessors -} +} \ No newline at end of file diff --git a/recapn/src/lib.rs b/recapn/src/lib.rs index e852ef0..a62c65a 100644 --- a/recapn/src/lib.rs +++ b/recapn/src/lib.rs @@ -61,7 +61,7 @@ pub mod prelude { pub use recapn::any::{self, AnyList, AnyPtr, AnyStruct}; pub use recapn::data::{self, Data}; pub use recapn::field::{ - self, Accessor, AccessorMut, AccessorOwned, Descriptor, Enum, FieldGroup, Group, Struct, + self, Accessor, AccessorMut, AccessorOwned, Descriptor, Group, UnionViewer, VariantInfo, VariantDescriptor, Variant, VariantMut, VariantOwned, ViewOf, Viewable, }; diff --git a/recapn/src/list.rs b/recapn/src/list.rs index 900caf0..7814e7b 100644 --- a/recapn/src/list.rs +++ b/recapn/src/list.rs @@ -6,19 +6,18 @@ //! for different types of values. For example, //! //! * A list of primitives is a `List` where V is the primitive value. -//! * A list of enums is a `List>` where T is the enum type. -//! * A list of structs is a `List>` where T is the struct type. +//! * A list of enums is a `List` where T is the enum type. +//! * A list of structs is a `List` where T is the struct type. //! * A list of lists is a `List>` where T is the inner list type. use crate::any::{self, AnyList, AnyPtr, AnyStruct}; use crate::data::{self, Data}; use crate::ptr::{CopySize, ErrorHandler, IgnoreErrors}; use crate::text::{self, Text}; -use crate::field::{Enum, Struct, Capability}; use crate::internal::Sealed; use crate::ptr::{Data as FieldData, PtrElementSize, StructSize}; use crate::rpc::{self, Capable, InsertableInto, Table}; -use crate::ty::{self, EnumResult}; +use crate::ty::{self, kind, EnumResult}; use crate::{Error, Family, IntoFamily, Result, ErrorKind}; use core::convert::TryFrom; @@ -37,17 +36,8 @@ pub mod ptr { pub struct TooManyElementsError(pub(crate) ()); -pub type Reader<'a, V, T = rpc::Empty> = List>; -pub type Builder<'a, V, T = rpc::Empty> = List>; - -pub type StructListReader<'a, S, T = rpc::Empty> = Reader<'a, Struct, T>; -pub type StructListBuilder<'a, S, T = rpc::Empty> = Builder<'a, Struct, T>; - -pub type EnumListReader<'a, E, T = rpc::Empty> = Reader<'a, Enum, T>; -pub type EnumListBuilder<'a, E, T = rpc::Empty> = Builder<'a, Enum, T>; - -pub type CapabilityListReader<'a, C, T = rpc::Empty> = Reader<'a, Capability, T>; -pub type CapabilityListBuilder<'a, C, T = rpc::Empty> = Builder<'a, Capability, T>; +pub type Reader<'p, V, T = rpc::Empty> = List>; +pub type Builder<'p, V, T = rpc::Empty> = List>; /// A Cap'n Proto list. pub struct List { @@ -177,29 +167,29 @@ impl<'a, V, T: Table> Reader<'a, V, T> { /// Get the element at the specified index, or None if the index is out of range. #[inline] - pub fn try_at<'b>(&'b self, index: u32) -> Option> + pub fn try_at<'b>(&'b self, index: u32) -> Option> where - V: ListAccessable<&'b Self> + V: ListAccessable<&'b ptr::Reader<'a, T>>, { (index < self.len()).then(|| unsafe { self.at_unchecked(index) }) } /// Get the element at the specified index, or None if the index is out of range. #[inline] - pub fn at<'b>(&'b self, index: u32) -> ElementReader<'a, 'b, V, T> + pub fn at<'b>(&'b self, index: u32) -> ElementReader<'a, 'b, T, V> where - V: ListAccessable<&'b Self> + V: ListAccessable<&'b ptr::Reader<'a, T>>, { self.try_at(index).expect("index out of bounds") } /// Get the element at the specified index without bounds checks. #[inline] - pub unsafe fn at_unchecked<'b>(&'b self, index: u32) -> ElementReader<'a, 'b, V, T> + pub unsafe fn at_unchecked<'b>(&'b self, index: u32) -> ElementReader<'a, 'b, T, V> where - V: ListAccessable<&'b Self> + V: ListAccessable<&'b ptr::Reader<'a, T>>, { - V::get(self, index) + V::get(self.as_ref(), index) } } @@ -217,7 +207,7 @@ impl<'a, V, T: Table> AsMut> for Builder<'a, V, T> { } } -impl<'a, V, T: Table> Builder<'a, V, T> { +impl<'p, V, T: Table> Builder<'p, V, T> { /// Gets the length of the list #[inline] pub fn len(&self) -> ElementCount { @@ -246,35 +236,35 @@ impl<'a, V, T: Table> Builder<'a, V, T> { /// Gets a mutable view of the element at the specified index, or None if the index is out of range. #[inline] - pub fn try_at<'b>(&'b mut self, index: u32) -> Option> + pub fn try_at<'b>(&'b mut self, index: u32) -> Option> where - V: ListAccessable<&'b mut Self>, + V: ListAccessable<&'b mut ptr::Builder<'p, T>>, { (index < self.len().get()).then(move || unsafe { self.at_unchecked(index) }) } /// Get the element at the specified index, or panics if out of range. #[inline] - pub fn at<'b>(&'b mut self, index: u32) -> ElementBuilder<'a, 'b, V, T> + pub fn at<'b>(&'b mut self, index: u32) -> ElementBuilder<'b, 'p, T, V> where - V: ListAccessable<&'b mut Self>, + V: ListAccessable<&'b mut ptr::Builder<'p, T>>, { self.try_at(index).expect("index out of bounds") } /// Gets a mutable view of the element at the specified index without bounds checks. #[inline] - pub unsafe fn at_unchecked<'b>(&'b mut self, index: u32) -> ElementBuilder<'a, 'b, V, T> + pub unsafe fn at_unchecked<'b>(&'b mut self, index: u32) -> ElementBuilder<'b, 'p, T, V> where - V: ListAccessable<&'b mut Self>, + V: ListAccessable<&'b mut ptr::Builder<'p, T>>, { - V::get(self, index) + V::get(self.as_mut(), index) } #[inline] - pub fn try_into_element(self, index: u32) -> Result, Self> + pub fn try_into_element(self, index: u32) -> Result, Self> where - V: ListAccessable, + V: ListAccessable>, { if index < self.len().get() { Ok(unsafe { self.into_element_unchecked(index) }) @@ -284,47 +274,63 @@ impl<'a, V, T: Table> Builder<'a, V, T> { } #[inline] - pub fn into_element(self, index: u32) -> ElementOwner<'a, V, T> + pub fn into_element(self, index: u32) -> ElementOwner<'p, T, V> where - V: ListAccessable, + V: ListAccessable>, { self.try_into_element(index).ok().expect("index out of bounds") } #[inline] - pub unsafe fn into_element_unchecked(self, index: u32) -> ElementOwner<'a, V, T> + pub unsafe fn into_element_unchecked(self, index: u32) -> ElementOwner<'p, T, V> where - V: ListAccessable, + V: ListAccessable>, { - V::get(self, index) + V::get(self.repr, index) } } /// An element in a list reader -pub type ElementReader<'a, 'b, V, T = rpc::Empty> = - >>::View; +pub type ElementReader<'b, 'p, T, V> = + >>::View; /// An element in a list builder with a mutable borrow -pub type ElementBuilder<'a, 'b, V, T = rpc::Empty> = - >>::View; -pub type ElementOwner<'a, V, T = rpc::Empty> = - >>::View; +pub type ElementBuilder<'b, 'p, T, V> = + >>::View; +pub type ElementOwner<'p, T, V> = + >>::View; -/// A checked index view into a List. -pub struct DataElement { - list: T, - idx: u32, +/// A "type kind" constraining trait that specializes list value type kinds. +pub trait TypeKind { + type Kind; } -pub type DataElementBuilder<'a, 'b, V, T = rpc::Empty> = DataElement<&'b mut Builder<'a, V, T>>; +impl TypeKind for T +where + T: ty::TypeKind, +{ + type Kind = T::Kind; +} -pub struct PtrElement { +/// A marker trait for generic pointer element types. Note this does *not* include `AnyPtr` since it +/// has specialized implementations of `ListAccessable` that return the `any::PtrBuilder` itself. +pub trait Ptr: TypeKind> {} + +impl ty::ListValue for kind::PtrList { + const ELEMENT_SIZE: ElementSize = ElementSize::Pointer; +} + +/// A checked index view into a List. +pub struct Element { + v: PhantomData V>, list: T, idx: u32, } -pub type PtrElementReader<'a, 'b, V, T = rpc::Empty> = PtrElement<&'b Reader<'a, V, T>>; -pub type PtrElementBuilder<'a, 'b, V, T = rpc::Empty> = PtrElement<&'b mut Builder<'a, V, T>>; -pub type PtrElementOwner<'a, V, T = rpc::Empty> = PtrElement>; +impl Element { + fn new(list: T, idx: u32) -> Self { + Self { v: PhantomData, list, idx } + } +} /// A helper used to provide element views into a list. Depending on the value type, this may simply /// return the value itself, or an element view which can be used to access one of the other getters @@ -344,163 +350,180 @@ pub trait ListAccessable { unsafe fn get(list: T, index: u32) -> Self::View; } -impl<'a, 'b, T: Table> ListAccessable<&'b Reader<'a, Self, T>> for () { +impl ListAccessable for T +where + T: TypeKind, + T::Kind: ListAccessable, +{ + type View = >::View; + + unsafe fn get(list: U, index: u32) -> Self::View { + >::get(list, index) + } +} + +impl<'b, 'p, T: Table> ListAccessable<&'b ptr::Reader<'p, T>> for () { type View = (); #[inline] - unsafe fn get(_: &'b Reader<'a, Self, T>, _: u32) -> Self::View { () } + unsafe fn get(_: &'b ptr::Reader<'p, T>, _: u32) -> Self::View { () } } -impl<'a, 'b, T: Table> ListAccessable<&'b mut Builder<'a, Self, T>> for () { +impl<'b, 'p, T: Table> ListAccessable<&'b mut ptr::Builder<'p, T>> for () { type View = (); #[inline] - unsafe fn get(_: &'b mut Builder<'a, Self, T>, _: u32) -> Self::View { () } + unsafe fn get(_: &'b mut ptr::Builder<'p, T>, _: u32) -> Self::View { () } } -impl<'a, 'b, T: Table, V: FieldData> ListAccessable<&'b Reader<'a, Self, T>> for V { - type View = V; +pub type DataElementBuilder<'b, 'p, T, D> = Element, &'b mut ptr::Builder<'p, T>>; + +impl<'b, 'p, T: Table, D: FieldData> ListAccessable<&'b ptr::Reader<'p, T>> for kind::Data { + type View = D; #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - list.as_ref().data_unchecked(idx) + unsafe fn get(list: &'b ptr::Reader<'p, T>, idx: u32) -> Self::View { + list.data_unchecked(idx) } } -impl<'a, 'b, T: Table, V: FieldData> ListAccessable<&'b mut Builder<'a, Self, T>> for V { - type View = DataElementBuilder<'a, 'b, Self, T>; +impl<'b, 'p, T: Table, D: FieldData> ListAccessable<&'b mut ptr::Builder<'p, T>> for kind::Data { + type View = DataElementBuilder<'b, 'p, T, D>; #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - DataElement { list, idx } + unsafe fn get(list: &'b mut ptr::Builder<'p, T>, idx: u32) -> Self::View { + Element::new(list, idx) } } -impl<'a, 'b, V: FieldData, T: Table> DataElementBuilder<'a, 'b, V, T> { +impl<'b, 'p, T: Table, D: FieldData> DataElementBuilder<'b, 'p, T, D> { /// A generic accessor for getting "field data", that is, primitive numeric and boolean types. #[inline] - pub fn get(&self) -> V { - unsafe { self.list.as_ref().data_unchecked(self.idx) } + pub fn get(&self) -> D { + unsafe { self.list.data_unchecked(self.idx) } } /// A generic accessor for setting "field data", that is, primitive numeric and boolean types. #[inline] - pub fn set(&mut self, value: V) { - unsafe { self.list.as_mut().set_data_unchecked(self.idx, value) } + pub fn set(&mut self, value: D) { + unsafe { self.list.set_data_unchecked(self.idx, value) } } } -impl<'a, 'b, T: Table> DataElementBuilder<'a, 'b, f32, T> { +impl<'b, 'p, T: Table> DataElementBuilder<'b, 'p, T, f32> { #[inline] /// Canonicalizes NaN values by blowing away the NaN payload. pub fn set_canonical(&mut self, value: f32) { const CANONICAL_NAN: u32 = 0x7fc00000u32; if value.is_nan() { - unsafe { self.list.as_mut().set_data_unchecked(self.idx, CANONICAL_NAN) } + unsafe { self.list.set_data_unchecked(self.idx, CANONICAL_NAN) } } else { self.set(value) } } } -impl<'a, 'b, T: Table> DataElementBuilder<'a, 'b, f64, T> { +impl<'b, 'p, T: Table> DataElementBuilder<'b, 'p, T, f64> { /// Canonicalizes NaN values by blowing away the NaN payload. #[inline] pub fn set_canonical(&mut self, value: f64) { const CANONICAL_NAN: u64 = 0x7ff8000000000000u64; if value.is_nan() { - unsafe { self.list.as_mut().set_data_unchecked(self.idx, CANONICAL_NAN) } + unsafe { self.list.set_data_unchecked(self.idx, CANONICAL_NAN) } } else { self.set(value) } } } -impl<'a, 'b, T: Table, E: ty::Enum> ListAccessable<&'b Reader<'a, Self, T>> for Enum { +impl ty::ListValue for kind::Enum { + const ELEMENT_SIZE: ElementSize = ElementSize::TwoBytes; +} + +pub type EnumElementBuilder<'b, 'p, T, E> = Element, &'b mut ptr::Builder<'p, T>>; + +impl<'b, 'p, T: Table, E: ty::Enum> ListAccessable<&'b ptr::Reader<'p, T>> for kind::Enum { type View = EnumResult; #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - let value = list.as_ref().data_unchecked(idx); + unsafe fn get(list: &'b ptr::Reader<'p, T>, idx: u32) -> Self::View { + let value = list.data_unchecked(idx); E::try_from(value) } } -impl<'a, 'b, T: Table, E: ty::Enum> ListAccessable<&'b mut Builder<'a, Self, T>> for Enum { - type View = DataElementBuilder<'a, 'b, Self, T>; +impl<'b, 'p, T: Table, E: ty::Enum> ListAccessable<&'b mut ptr::Builder<'p, T>> for kind::Enum { + type View = EnumElementBuilder<'b, 'p, T, E>; #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - DataElement { list, idx } + unsafe fn get(list: &'b mut ptr::Builder<'p, T>, idx: u32) -> Self::View { + Element::new(list, idx) } } -impl<'a, 'b, E: ty::Enum, T: Table> DataElementBuilder<'a, 'b, Enum, T> -where - T: Table, - E: ty::Enum, -{ +impl<'b, 'p, E: ty::Enum, T: Table> EnumElementBuilder<'b, 'p, T, E> { #[inline] pub fn get(&self) -> EnumResult { - let value = unsafe { self.list.as_ref().data_unchecked::(self.idx) }; + let value = unsafe { self.list.data_unchecked::(self.idx) }; E::try_from(value) } #[inline] pub fn set(&mut self, value: E) { let value = value.into(); - unsafe { self.list.as_mut().set_data_unchecked::(self.idx, value) } + self.set_value(value) + } + #[inline] + pub fn set_value(&mut self, value: u16) { + unsafe { self.list.set_data_unchecked::(self.idx, value) } } } -pub struct StructElement { - list: T, - idx: u32, +impl ty::ListValue for kind::Struct { + const ELEMENT_SIZE: ElementSize = ElementSize::InlineComposite(S::SIZE); } -pub type StructElementBuilder<'a, 'b, V, T = rpc::Empty> = StructElement<&'b mut Builder<'a, V, T>>; -pub type StructElementOwner<'a, V, T = rpc::Empty> = StructElement>; +pub type StructElement = Element, Repr>; + +pub type StructElementBuilder<'b, 'p, T, S> = StructElement>; +pub type StructElementOwner<'p, T, S> = StructElement>; -impl<'a, 'b, T: Table, S: ty::Struct> ListAccessable<&'b Reader<'a, Self, T>> for Struct { - type View = S::Reader<'a, T>; +impl<'b, 'p, T: Table, S: ty::Struct> ListAccessable<&'b ptr::Reader<'p, T>> for kind::Struct { + type View = S::Reader<'p, T>; #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - ty::StructReader::from_ptr(list.as_ref().struct_unchecked(idx)) + unsafe fn get(list: &'b ptr::Reader<'p, T>, idx: u32) -> Self::View { + ty::StructReader::from_ptr(list.struct_unchecked(idx)) } } -impl<'a, 'b, T: Table, S: ty::Struct> ListAccessable<&'b mut Builder<'a, Self, T>> for Struct { - type View = StructElementBuilder<'a, 'b, Self, T>; +impl<'b, 'p, T: Table, S: ty::Struct> ListAccessable<&'b mut ptr::Builder<'p, T>> for kind::Struct { + type View = StructElementBuilder<'b, 'p, T, S>; #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - StructElement { list, idx } + unsafe fn get(list: &'b mut ptr::Builder<'p, T>, idx: u32) -> Self::View { + Element::new(list, idx) } } -impl<'a, T: Table, S: ty::Struct> ListAccessable> for Struct { - type View = StructElementOwner<'a, Self, T>; +impl<'p, T: Table, S: ty::Struct> ListAccessable> for kind::Struct { + type View = StructElementOwner<'p, T, S>; #[inline] - unsafe fn get(list: Builder<'a, Self, T>, idx: u32) -> Self::View { - StructElement { list, idx } + unsafe fn get(list: ptr::Builder<'p, T>, idx: u32) -> Self::View { + Element::new(list, idx) } } -impl<'a, 'b, S, T> StructElementBuilder<'a, 'b, Struct, T> -where - S: ty::Struct, - T: Table, -{ +impl<'b, 'p, T: Table, S: ty::Struct> StructElementBuilder<'b, 'p, T, S> { #[inline] pub fn get(self) -> S::Builder<'b, T> { - unsafe { ty::StructBuilder::from_ptr(self.list.as_mut().struct_mut_unchecked(self.idx)) } + unsafe { ty::StructBuilder::from_ptr(self.list.struct_mut_unchecked(self.idx)) } } #[inline] pub fn reader(&self) -> S::Reader<'_, T> { - ty::StructReader::from_ptr(unsafe { self.list.as_ref().struct_unchecked(self.idx) }) + ty::StructReader::from_ptr(unsafe { self.list.struct_unchecked(self.idx) }) } /// Mostly behaves like you'd expect `set` to behave, but with a caveat originating from @@ -528,45 +551,47 @@ where } } -impl<'a, 'b, T: Table> ListAccessable<&'b Reader<'a, Self, T>> for AnyStruct { - type View = any::StructReader<'b, T>; +pub type AnyStructElement = Element; + +pub type AnyStructElementBuilder<'b, 'p, T> = AnyStructElement<&'b mut ptr::Builder<'p, T>>; +pub type AnyStructElementOwner<'p, T> = AnyStructElement>; + +impl<'b, 'p, T: Table> ListAccessable<&'b ptr::Reader<'p, T>> for AnyStruct { + type View = any::StructReader<'p, T>; #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - ty::StructReader::from_ptr(list.as_ref().struct_unchecked(idx)) + unsafe fn get(list: &'b ptr::Reader<'p, T>, idx: u32) -> Self::View { + ty::StructReader::from_ptr(list.struct_unchecked(idx)) } } -impl<'a, 'b, T: Table> ListAccessable<&'b mut Builder<'a, Self, T>> for AnyStruct { - type View = StructElementBuilder<'a, 'b, AnyStruct, T>; +impl<'b, 'p, T: Table> ListAccessable<&'b mut ptr::Builder<'p, T>> for AnyStruct { + type View = AnyStructElementBuilder<'b, 'p, T>; #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - StructElement { list, idx } + unsafe fn get(list: &'b mut ptr::Builder<'p, T>, idx: u32) -> Self::View { + Element::new(list, idx) } } -impl<'a, T: Table> ListAccessable> for AnyStruct { - type View = StructElementOwner<'a, Self, T>; +impl<'p, T: Table> ListAccessable> for AnyStruct { + type View = AnyStructElementOwner<'p, T>; #[inline] - unsafe fn get(list: Builder<'a, Self, T>, idx: u32) -> Self::View { - StructElement { list, idx } + unsafe fn get(list: ptr::Builder<'p, T>, idx: u32) -> Self::View { + Element::new(list, idx) } } -impl<'a, 'b, T> StructElementBuilder<'a, 'b, AnyStruct, T> -where - T: Table, -{ +impl<'b, 'p, T: Table> AnyStructElementBuilder<'b, 'p, T> { #[inline] pub fn get(self) -> any::StructBuilder<'b, T> { - unsafe { self.list.repr.struct_mut_unchecked(self.idx).into() } + unsafe { self.list.struct_mut_unchecked(self.idx).into() } } #[inline] pub fn reader(&self) -> any::StructReader<'_, T> { - unsafe { self.list.as_ref().struct_unchecked(self.idx).into() } + unsafe { self.list.struct_unchecked(self.idx).into() } } /// Mostly behaves like you'd expect `set` to behave, but with a caveat originating from @@ -594,27 +619,55 @@ where } } -impl<'a, 'b, T: Table, V: ty::ListValue> ListAccessable<&'b Reader<'a, Self, T>> for List { - type View = PtrElementReader<'a, 'b, Self, T>; +pub type PtrElement = Element, Repr>; - #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } +pub type PtrElementReader<'b, 'p, T, P> = PtrElement>; +pub type PtrElementBuilder<'b, 'p, T, P> = PtrElement>; +pub type PtrElementOwner<'p, T, P> = PtrElement>; + +impl<'b, 'p, T: Table, P: Ptr> ListAccessable<&'b ptr::Reader<'p, T>> for kind::PtrList

{ + type View = PtrElementReader<'b, 'p, T, P>; + + unsafe fn get(list: &'b ptr::Reader<'p, T>, idx: u32) -> Self::View { + Element::new(list, idx) } } -impl<'a, 'b, V, T> PtrElementReader<'a, 'b, List, T> -where - T: Table, - V: ty::DynListValue, -{ +impl<'b, 'p, T: Table, P: Ptr> ListAccessable<&'b mut ptr::Builder<'p, T>> for kind::PtrList

{ + type View = PtrElementBuilder<'b, 'p, T, P>; + + unsafe fn get(list: &'b mut ptr::Builder<'p, T>, idx: u32) -> Self::View { + Element::new(list, idx) + } +} + +impl<'p, T: Table, P: Ptr> ListAccessable> for kind::PtrList

{ + type View = PtrElementOwner<'p, T, P>; + + unsafe fn get(list: ptr::Builder<'p, T>, idx: u32) -> Self::View { + Element::new(list, idx) + } +} + +impl TypeKind for List { + type Kind = kind::PtrList; +} +impl Ptr for List {} + +pub type ListElement = PtrElement, Repr>; + +pub type ListElementReader<'b, 'p, T, V> = ListElement>; +pub type ListElementBuilder<'b, 'p, T, V> = ListElement>; +pub type ListElementOwner<'p, T, V> = ListElement>; + +impl<'b, 'p, T: Table, V: ty::DynListValue> ListElementReader<'b, 'p, T, V> { #[inline] - fn ptr_reader(&self) -> crate::ptr::PtrReader<'a, T> { - unsafe { self.list.as_ref().ptr_unchecked(self.idx) } + fn ptr_reader(&self) -> crate::ptr::PtrReader<'p, T> { + unsafe { self.list.ptr_unchecked(self.idx) } } #[inline] - fn empty_list(&self) -> Reader<'a, V, T> { + fn empty_list(&self) -> Reader<'p, V, T> { List::new(ptr::Reader::empty(ElementSize::Pointer).imbue_from(self.list)) } @@ -627,7 +680,7 @@ where /// Returns the list value in this element, or an empty list if the list is null /// or an error occurs while reading. #[inline] - pub fn get(&self) -> Reader<'a, V, T> { + pub fn get(&self) -> Reader<'p, V, T> { match self.try_get_option() { Ok(Some(reader)) => reader, _ => self.empty_list(), @@ -637,7 +690,7 @@ where /// Returns the list value in this element, or None if the list element is null or /// an error occurs while reading. #[inline] - pub fn get_option(&self) -> Option> { + pub fn get_option(&self) -> Option> { match self.try_get_option() { Ok(Some(reader)) => Some(reader), _ => None, @@ -647,7 +700,7 @@ where /// Returns the list value in this element. If the element is null, this returns an /// empty list. If an error occurs while reading it is returned. #[inline] - pub fn try_get(&self) -> Result> { + pub fn try_get(&self) -> Result> { match self.try_get_option() { Ok(Some(reader)) => Ok(reader), Ok(None) => Ok(self.empty_list()), @@ -658,7 +711,7 @@ where /// Returns the list value in this element. If the element is null, this returns Ok(None). /// If an error occurs while reading it is returned. #[inline] - pub fn try_get_option(&self) -> Result>> { + pub fn try_get_option(&self) -> Result>> { match self.ptr_reader().to_list(Some(PtrElementSize::size_of::())) { Ok(Some(reader)) => Ok(Some(List::new(reader))), Ok(None) => Ok(None), @@ -667,28 +720,15 @@ where } } -impl<'a, 'b, T: Table, V: ty::ListValue> ListAccessable<&'b mut Builder<'a, Self, T>> for List { - type View = PtrElementBuilder<'a, 'b, Self, T>; - - #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } - } -} - -impl<'a, 'b, T, V> PtrElementBuilder<'a, 'b, List, T> -where - T: Table, - V: ty::ListValue, -{ +impl<'b, 'p, T: Table, V: ty::ListValue> ListElementBuilder<'b, 'p, T, V> { #[inline] fn ptr_builder(&mut self) -> crate::ptr::PtrBuilder { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } #[inline] fn into_ptr_builder(self) -> crate::ptr::PtrBuilder<'b, T> { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } /// Gets the value of the element in the list as a builder. If the value is null or invalid @@ -776,18 +816,15 @@ where } } -impl<'a, 'b, T> PtrElementBuilder<'a, 'b, List, T> -where - T: Table, -{ +impl<'b, 'p, T: Table> ListElementBuilder<'b, 'p, T, AnyStruct> { #[inline] fn ptr_builder(&mut self) -> crate::ptr::PtrBuilder { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } #[inline] fn into_ptr_builder(self) -> crate::ptr::PtrBuilder<'b, T> { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } /// Gets the value of the element in the list as a builder. If the value is null or invalid @@ -891,26 +928,25 @@ where } } -impl<'a, 'b, T: Table> ListAccessable<&'b Reader<'a, Self, T>> for AnyList { - type View = PtrElementReader<'a, 'b, Self, T>; - - #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } - } +impl TypeKind for AnyList { + type Kind = kind::PtrList; } +impl Ptr for AnyList {} -impl<'a, 'b, T> PtrElementReader<'a, 'b, AnyList, T> -where - T: Table, -{ +pub type AnyListElement = PtrElement; + +pub type AnyListElementReader<'b, 'p, T> = AnyListElement<&'b ptr::Reader<'p, T>>; +pub type AnyListElementBuilder<'b, 'p, T> = AnyListElement<&'b mut ptr::Builder<'p, T>>; +pub type AnyListElementOwner<'p, T> = AnyListElement>; + +impl<'b, 'p, T: Table> AnyListElementReader<'b, 'p, T> { #[inline] - fn ptr_reader(&self) -> crate::ptr::PtrReader<'a, T> { - unsafe { self.list.as_ref().ptr_unchecked(self.idx) } + fn ptr_reader(&self) -> crate::ptr::PtrReader<'p, T> { + unsafe { self.list.ptr_unchecked(self.idx) } } #[inline] - fn empty_list(&self) -> any::ListReader<'a, T> { + fn empty_list(&self) -> any::ListReader<'p, T> { any::ListReader::from(ptr::Reader::empty(ElementSize::Pointer).imbue_from(self.list)) } @@ -923,7 +959,7 @@ where /// Returns the list value in this element, or an empty list if the list is null /// or an error occurs while reading. #[inline] - pub fn get(&self) -> any::ListReader<'a, T> { + pub fn get(&self) -> any::ListReader<'p, T> { match self.try_get_option() { Ok(Some(reader)) => reader, _ => self.empty_list(), @@ -933,7 +969,7 @@ where /// Returns the list value in this element, or None if the list element is null or /// an error occurs while reading. #[inline] - pub fn get_option(&self) -> Option> { + pub fn get_option(&self) -> Option> { match self.try_get_option() { Ok(Some(reader)) => Some(reader), _ => None, @@ -943,7 +979,7 @@ where /// Returns the list value in this element. If the element is null, this returns an /// empty list. If an error occurs while reading it is returned. #[inline] - pub fn try_get(&self) -> Result> { + pub fn try_get(&self) -> Result> { match self.try_get_option() { Ok(Some(reader)) => Ok(reader), Ok(None) => Ok(self.empty_list()), @@ -954,7 +990,7 @@ where /// Returns the list value in this element. If the element is null, this returns Ok(None). /// If an error occurs while reading it is returned. #[inline] - pub fn try_get_option(&self) -> Result>> { + pub fn try_get_option(&self) -> Result>> { match self.ptr_reader().to_list(None) { Ok(Some(reader)) => Ok(Some(any::ListReader::from(reader))), Ok(None) => Ok(None), @@ -963,27 +999,15 @@ where } } -impl<'a, 'b, T: Table> ListAccessable<&'b mut Builder<'a, Self, T>> for AnyList { - type View = PtrElementBuilder<'a, 'b, Self, T>; - - #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } - } -} - -impl<'a, 'b, T> PtrElementBuilder<'a, 'b, AnyList, T> -where - T: Table, -{ +impl<'b, 'p, T: Table> AnyListElementBuilder<'b, 'p, T> { #[inline] fn ptr_builder(&mut self) -> crate::ptr::PtrBuilder { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } #[inline] fn into_ptr_builder(self) -> crate::ptr::PtrBuilder<'b, T> { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } /// Gets the value of the element in the list as a builder. If the value is null or invalid @@ -1054,22 +1078,20 @@ where } } -impl<'a, 'b, T: Table> ListAccessable<&'b Reader<'a, Self, T>> for Data { - type View = PtrElementReader<'a, 'b, Self, T>; - - #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } - } +impl TypeKind for Data { + type Kind = kind::PtrList; } +impl Ptr for Data {} -impl<'a, 'b, T> PtrElementReader<'a, 'b, Data, T> -where - T: Table, -{ +pub type DataBlobElement = PtrElement; + +pub type DataBlobElementReader<'b, 'p, T> = DataBlobElement<&'b ptr::Reader<'p, T>>; +pub type DataBlobElementBuilder<'b, 'p, T> = DataBlobElement<&'b mut ptr::Builder<'p, T>>; + +impl<'b, 'p, T: Table> DataBlobElementReader<'b, 'p, T> { #[inline] - fn ptr_reader(&self) -> crate::ptr::PtrReader<'a, T> { - unsafe { self.list.as_ref().ptr_unchecked(self.idx) } + fn ptr_reader(&self) -> crate::ptr::PtrReader<'p, T> { + unsafe { self.list.ptr_unchecked(self.idx) } } /// Returns whether this list element is a null pointer. @@ -1081,7 +1103,7 @@ where /// Returns the list value in this element, or an empty list if the list is null /// or an error occurs while reading. #[inline] - pub fn get(&self) -> data::Reader<'a> { + pub fn get(&self) -> data::Reader<'p> { match self.try_get_option() { Ok(Some(reader)) => reader, _ => data::Reader::empty(), @@ -1091,7 +1113,7 @@ where /// Returns the list value in this element, or None if the list element is null or /// an error occurs while reading. #[inline] - pub fn get_option(&self) -> Option> { + pub fn get_option(&self) -> Option> { match self.try_get_option() { Ok(Some(reader)) => Some(reader), _ => None, @@ -1101,7 +1123,7 @@ where /// Returns the list value in this element. If the element is null, this returns an /// empty list. If an error occurs while reading it is returned. #[inline] - pub fn try_get(&self) -> Result> { + pub fn try_get(&self) -> Result> { match self.try_get_option() { Ok(Some(reader)) => Ok(reader), Ok(None) => Ok(data::Reader::empty()), @@ -1112,7 +1134,7 @@ where /// Returns the list value in this element. If the element is null, this returns Ok(None). /// If an error occurs while reading it is returned. #[inline] - pub fn try_get_option(&self) -> Result>> { + pub fn try_get_option(&self) -> Result>> { match self.ptr_reader().to_blob() { Ok(Some(reader)) => Ok(Some(data::Reader::from(reader))), Ok(None) => Ok(None), @@ -1121,27 +1143,15 @@ where } } -impl<'a, 'b, T: Table> ListAccessable<&'b mut Builder<'a, Self, T>> for Data { - type View = PtrElementBuilder<'a, 'b, Self, T>; - - #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } - } -} - -impl<'a, 'b, T> PtrElementBuilder<'a, 'b, Data, T> -where - T: Table, -{ +impl<'b, 'p, T: Table> DataBlobElementBuilder<'b, 'p, T> { #[inline] fn ptr_builder(&mut self) -> crate::ptr::PtrBuilder { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } #[inline] fn into_ptr_builder(self) -> crate::ptr::PtrBuilder<'b, T> { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } #[inline] @@ -1177,22 +1187,20 @@ where } } -impl<'a, 'b, T: Table> ListAccessable<&'b Reader<'a, Self, T>> for Text { - type View = PtrElementReader<'a, 'b, Self, T>; - - #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } - } +impl TypeKind for Text { + type Kind = kind::PtrList; } +impl Ptr for Text {} -impl<'a, 'b, T> PtrElementReader<'a, 'b, Text, T> -where - T: Table, -{ +pub type TextElement = PtrElement; + +pub type TextElementReader<'b, 'p, T> = TextElement<&'b ptr::Reader<'p, T>>; +pub type TextElementBuilder<'b, 'p, T> = TextElement<&'b mut ptr::Builder<'p, T>>; + +impl<'b, 'p, T: Table> TextElementReader<'b, 'p, T> { #[inline] - fn ptr_reader(&self) -> crate::ptr::PtrReader<'a, T> { - unsafe { self.list.as_ref().ptr_unchecked(self.idx) } + fn ptr_reader(&self) -> crate::ptr::PtrReader<'p, T> { + unsafe { self.list.ptr_unchecked(self.idx) } } /// Returns whether this list element is a null pointer. @@ -1204,7 +1212,7 @@ where /// Returns the list value in this element, or an empty list if the list is null /// or an error occurs while reading. #[inline] - pub fn get(&self) -> text::Reader<'a> { + pub fn get(&self) -> text::Reader<'p> { match self.try_get_option() { Ok(Some(reader)) => reader, _ => text::Reader::empty(), @@ -1214,7 +1222,7 @@ where /// Returns the list value in this element, or None if the list element is null or /// an error occurs while reading. #[inline] - pub fn get_option(&self) -> Option> { + pub fn get_option(&self) -> Option> { match self.try_get_option() { Ok(Some(reader)) => Some(reader), _ => None, @@ -1224,7 +1232,7 @@ where /// Returns the list value in this element. If the element is null, this returns an /// empty list. If an error occurs while reading it is returned. #[inline] - pub fn try_get(&self) -> Result> { + pub fn try_get(&self) -> Result> { match self.try_get_option() { Ok(Some(reader)) => Ok(reader), Ok(None) => Ok(text::Reader::empty()), @@ -1235,7 +1243,7 @@ where /// Returns the list value in this element. If the element is null, this returns Ok(None). /// If an error occurs while reading it is returned. #[inline] - pub fn try_get_option(&self) -> Result>> { + pub fn try_get_option(&self) -> Result>> { match self.ptr_reader().to_blob() { Ok(Some(b)) => text::Reader::new(b) .ok_or_else(|| Error::from(ErrorKind::TextNotNulTerminated)) @@ -1246,27 +1254,15 @@ where } } -impl<'a, 'b, T: Table> ListAccessable<&'b mut Builder<'a, Self, T>> for Text { - type View = PtrElementBuilder<'a, 'b, Self, T>; - - #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } - } -} - -impl<'a, 'b, T> PtrElementBuilder<'a, 'b, Text, T> -where - T: Table, -{ +impl<'b, 'p, T: Table> TextElementBuilder<'b, 'p, T> { #[inline] fn ptr_builder(&mut self) -> crate::ptr::PtrBuilder { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } #[inline] fn into_ptr_builder(self) -> crate::ptr::PtrBuilder<'b, T> { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } #[inline] @@ -1333,41 +1329,47 @@ where } } -impl<'a, 'b, T: Table> ListAccessable<&'b Reader<'a, Self, T>> for AnyPtr { +impl ty::ListValue for AnyPtr { + const ELEMENT_SIZE: ElementSize = ElementSize::Pointer; +} + +impl<'a, 'b, T: Table> ListAccessable<&'b ptr::Reader<'a, T>> for AnyPtr { type View = any::PtrReader<'a, T>; #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - list.repr.ptr_unchecked(idx).into() + unsafe fn get(list: &'b ptr::Reader<'a, T>, idx: u32) -> Self::View { + list.ptr_unchecked(idx).into() } } -impl<'a, 'b, T: Table> ListAccessable<&'b mut Builder<'a, Self, T>> for AnyPtr { +impl<'a, 'b, T: Table> ListAccessable<&'b mut ptr::Builder<'a, T>> for AnyPtr { type View = any::PtrBuilder<'b, T>; #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - list.repr.ptr_mut_unchecked(idx).into() + unsafe fn get(list: &'b mut ptr::Builder<'a, T>, idx: u32) -> Self::View { + list.ptr_mut_unchecked(idx).into() } } -impl<'a, 'b, C: ty::Capability, T: Table> ListAccessable<&'b Reader<'a, Self, T>> for Capability { - type View = PtrElementReader<'a, 'b, Self, T>; - - #[inline] - unsafe fn get(list: &'b Reader<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } - } +impl TypeKind for kind::Capability { + type Kind = kind::PtrList; } +impl Ptr for kind::Capability {} + +pub type CapabilityElement = PtrElement, Repr>; + +pub type CapabilityElementReader<'b, 'p, T, C> = CapabilityElement>; +pub type CapabilityElementBuilder<'b, 'p, T, C> = CapabilityElement>; +pub type CapabilityElementOwner<'p, T, C> = CapabilityElement>; -impl<'a, 'b, C, T, Client> PtrElementReader<'a, 'b, Capability, T> +impl<'b, 'p, T, C, Client> CapabilityElementReader<'b, 'p, T, C> where C: ty::Capability, T: rpc::CapTable, { #[inline] - fn ptr_reader(&self) -> crate::ptr::PtrReader<'a, T> { - unsafe { self.list.as_ref().ptr_unchecked(self.idx) } + fn ptr_reader(&self) -> crate::ptr::PtrReader<'p, T> { + unsafe { self.list.ptr_unchecked(self.idx) } } #[inline] @@ -1385,7 +1387,7 @@ where } } -impl<'a, 'b, C, T, Client> PtrElementReader<'a, 'b, Capability, T> +impl<'b, 'p, T, C, Client> CapabilityElementReader<'b, 'p, T, C> where C: ty::Capability, T: rpc::CapTable + rpc::BreakableCapSystem, @@ -1417,28 +1419,19 @@ where } } -impl<'a, 'b, C: ty::Capability, T: Table> ListAccessable<&'b mut Builder<'a, Self, T>> for Capability { - type View = PtrElementBuilder<'a, 'b, Self, T>; - - #[inline] - unsafe fn get(list: &'b mut Builder<'a, Self, T>, idx: u32) -> Self::View { - PtrElement { list, idx } - } -} - -impl<'a, 'b, C, T, Client> PtrElementBuilder<'a, 'b, Capability, T> +impl<'b, 'p, T, C, Client> CapabilityElementBuilder<'b, 'p, T, C> where C: ty::Capability, T: rpc::CapTable, { #[inline] fn ptr_reader(&self) -> crate::ptr::PtrReader { - unsafe { self.list.as_ref().ptr_unchecked(self.idx) } + unsafe { self.list.ptr_unchecked(self.idx) } } #[inline] fn ptr_builder(&mut self) -> crate::ptr::PtrBuilder { - unsafe { self.list.as_mut().ptr_mut_unchecked(self.idx) } + unsafe { self.list.ptr_mut_unchecked(self.idx) } } #[inline] @@ -1461,7 +1454,7 @@ where } } -impl<'a, 'b, C, T, Client> PtrElementBuilder<'a, 'b, Capability, T> +impl<'b, 'p, T, C, Client> CapabilityElementBuilder<'b, 'p, T, C> where C: ty::Capability, T: rpc::CapTable + rpc::BreakableCapSystem, @@ -1477,6 +1470,28 @@ where } // Iterators. WARNING! HELL BELOW +// Ideally one day we'll get rid of all this crap and just use lending iterators. + +/// Walks the type kind tree to find what type is actually supposed to be used for the iterator. +pub trait IterKind { + type Iter; +} + +impl IterKind for T +where + T: TypeKind, + T::Kind: IterKind, +{ + type Iter = T::Kind; +} + +impl IterKind for () { + type Iter = (); +} + +impl IterKind for kind::Struct { + type Iter = Self; +} /// Describes the conversion from an element reader to a value which isn't dependent /// on the reader itself. @@ -1494,65 +1509,66 @@ where /// /// Custom strategies can be used by providing a closure to `into_iter_by` which will be /// called for every element in the list. -pub trait IterStrategy { +pub trait IterStrategy> { /// The resulting type derived from this strategy type Item; /// Applies the strategy to get the output - fn get(&mut self, element: E) -> Self::Item; + fn get<'b>(&mut self, element: V::View) -> Self::Item; } -impl IterStrategy for F +impl IterStrategy for F where - F: FnMut(E) -> Output, + V: ListAccessable, + F: FnMut(V::View) -> Output, { type Item = Output; #[inline] - fn get(&mut self, element: E) -> Self::Item { + fn get(&mut self, element: V::View) -> Self::Item { (self)(element) } } macro_rules! infallible_strategies { ($ty:ty) => { - impl IterStrategy<(), ()> for $ty { + impl<'b, 'p, T: Table> IterStrategy<&'b ptr::Reader<'p, T>, ()> for $ty { type Item = (); #[inline] fn get(&mut self, _: Self::Item) -> Self::Item {} } - impl IterStrategy for $ty { - type Item = V; + impl<'b, 'p, T: Table, D: FieldData> IterStrategy<&'b ptr::Reader<'p, T>, kind::Data> for $ty { + type Item = D; #[inline] fn get(&mut self, element: Self::Item) -> Self::Item { element } } - impl IterStrategy, EnumResult> for $ty { + impl<'b, 'p, T: Table, E: ty::Enum> IterStrategy<&'b ptr::Reader<'p, T>, kind::Enum> for $ty { type Item = EnumResult; #[inline] fn get(&mut self, element: Self::Item) -> Self::Item { element } } - impl IterStrategy, R> for $ty { - type Item = R; + impl<'b, 'p, T: Table, S: ty::Struct> IterStrategy<&'b ptr::Reader<'p, T>, kind::Struct> for $ty { + type Item = S::Reader<'p, T>; #[inline] fn get(&mut self, element: Self::Item) -> Self::Item { element } } - impl<'a, T: Table> IterStrategy> for $ty { - type Item = any::StructReader<'a, T>; + impl<'b, 'p, T: Table> IterStrategy<&'b ptr::Reader<'p, T>, AnyStruct> for $ty { + type Item = any::StructReader<'p, T>; #[inline] fn get(&mut self, element: Self::Item) -> Self::Item { element } } - impl<'a, T: Table> IterStrategy> for $ty { - type Item = any::PtrReader<'a, T>; + impl<'b, 'p, T: Table> IterStrategy<&'b ptr::Reader<'p, T>, AnyPtr> for $ty { + type Item = any::PtrReader<'p, T>; #[inline] fn get(&mut self, element: Self::Item) -> Self::Item { element } @@ -1567,47 +1583,34 @@ pub struct InfalliblePtrs; infallible_strategies!(InfalliblePtrs); -impl<'a, 'b, T, V> IterStrategy, PtrElementReader<'a, 'b, List, T>> for InfalliblePtrs -where - T: Table, - V: ty::DynListValue, -{ - type Item = Reader<'a, V, T>; +impl<'b, 'p, T: Table, V: ty::DynListValue> IterStrategy<&'b ptr::Reader<'p, T>, List> for InfalliblePtrs { + type Item = Reader<'p, V, T>; - fn get(&mut self, element: PtrElementReader<'a, 'b, List, T>) -> Self::Item { + fn get(&mut self, element: ListElementReader<'b, 'p, T, V>) -> Self::Item { element.get() } } -impl<'a, 'b, T> IterStrategy> for InfalliblePtrs -where - T: Table, -{ - type Item = any::ListReader<'a, T>; +impl<'b, 'p, T: Table> IterStrategy<&'b ptr::Reader<'p, T>, AnyList> for InfalliblePtrs { + type Item = any::ListReader<'p, T>; - fn get(&mut self, element: PtrElementReader<'a, 'b, AnyList, T>) -> Self::Item { + fn get(&mut self, element: AnyListElementReader<'b, 'p, T>) -> Self::Item { element.get() } } -impl<'a, 'b, T> IterStrategy> for InfalliblePtrs -where - T: Table, -{ - type Item = data::Reader<'a>; +impl<'b, 'p, T: Table> IterStrategy<&'b ptr::Reader<'p, T>, Data> for InfalliblePtrs { + type Item = data::Reader<'p>; - fn get(&mut self, element: PtrElementReader<'a, 'b, Data, T>) -> Self::Item { + fn get(&mut self, element: DataBlobElementReader<'b, 'p, T>) -> Self::Item { element.get() } } -impl<'a, 'b, T> IterStrategy> for InfalliblePtrs -where - T: Table, -{ - type Item = text::Reader<'a>; +impl<'b, 'p, T: Table> IterStrategy<&'b ptr::Reader<'p, T>, Text> for InfalliblePtrs { + type Item = text::Reader<'p>; - fn get(&mut self, element: PtrElementReader<'a, 'b, Text, T>) -> Self::Item { + fn get(&mut self, element: TextElementReader<'b, 'p, T>) -> Self::Item { element.get() } } @@ -1618,69 +1621,58 @@ pub struct Fallible; infallible_strategies!(Fallible); -impl<'a, 'b, T, V> IterStrategy, PtrElementReader<'a, 'b, List, T>> for Fallible -where - T: Table, - V: ty::DynListValue, -{ - type Item = Result>; +impl<'b, 'p, T: Table, V: ty::DynListValue> IterStrategy<&'b ptr::Reader<'p, T>, List> for Fallible { + type Item = Result>; - fn get(&mut self, element: PtrElementReader<'a, 'b, List, T>) -> Self::Item { + fn get(&mut self, element: ListElementReader<'b, 'p, T, V>) -> Self::Item { element.try_get() } } -impl<'a, 'b, T> IterStrategy> for Fallible -where - T: Table, -{ - type Item = Result>; +impl<'b, 'p, T: Table> IterStrategy<&'b ptr::Reader<'p, T>, AnyList> for Fallible { + type Item = Result>; - fn get(&mut self, element: PtrElementReader<'a, 'b, AnyList, T>) -> Self::Item { + fn get(&mut self, element: AnyListElementReader<'b, 'p, T>) -> Self::Item { element.try_get() } } -impl<'a, 'b, T> IterStrategy> for Fallible -where - T: Table, -{ - type Item = Result>; +impl<'b, 'p, T: Table> IterStrategy<&'b ptr::Reader<'p, T>, Data> for Fallible { + type Item = Result>; - fn get(&mut self, element: PtrElementReader<'a, 'b, Data, T>) -> Self::Item { + fn get(&mut self, element: DataBlobElementReader<'b, 'p, T>) -> Self::Item { element.try_get() } } -impl<'a, 'b, T> IterStrategy> for Fallible -where - T: Table, -{ - type Item = Result>; +impl<'b, 'p, T: Table> IterStrategy<&'b ptr::Reader<'p, T>, Text> for Fallible { + type Item = Result>; - fn get(&mut self, element: PtrElementReader<'a, 'b, Text, T>) -> Self::Item { + fn get(&mut self, element: TextElementReader<'b, 'p, T>) -> Self::Item { element.try_get() } } /// An iterator through a list that maps the element view into a new output. pub struct Iter<'a, V, S = InfalliblePtrs, T: Table = rpc::Empty> { - list: Reader<'a, V, T>, + v: PhantomData V>, + list: ptr::Reader<'a, T>, range: Range, strategy: S, } -impl<'a, V, S, T, Item> Iterator for Iter<'a, V, S, T> +impl<'p, V, S, T, Item> Iterator for Iter<'p, V, S, T> where - V: for<'b> ListAccessable<&'b Reader<'a, V, T>>, - S: for<'b> IterStrategy, Item = Item>, + V: IterKind, + V::Iter: for<'b> ListAccessable<&'b ptr::Reader<'p, T>>, + S: for<'b> IterStrategy<&'b ptr::Reader<'p, T>, V::Iter, Item = Item>, T: Table, { type Item = Item; #[inline] fn next(&mut self) -> Option { - let element = unsafe { self.list.at_unchecked(self.range.next()?) }; + let element = unsafe { >::get(&self.list, self.range.next()?) }; Some(self.strategy.get(element)) } #[inline] @@ -1689,36 +1681,35 @@ where } } -impl<'a, V, S, T, Item> DoubleEndedIterator for Iter<'a, V, S, T> +impl<'p, V, S, T, Item> DoubleEndedIterator for Iter<'p, V, S, T> where - V: for<'b> ListAccessable<&'b Reader<'a, V, T>>, - S: for<'b> IterStrategy>>::View, Item = Item>, + V: IterKind, + V::Iter: for<'b> ListAccessable<&'b ptr::Reader<'p, T>>, + S: for<'b> IterStrategy<&'b ptr::Reader<'p, T>, V::Iter, Item = Item>, T: Table, { #[inline] fn next_back(&mut self) -> Option { - let element = unsafe { self.list.at_unchecked(self.range.next_back()?) }; + let element = unsafe { >::get(&self.list, self.range.next_back()?) }; Some(self.strategy.get(element)) } } -impl<'a, V, T> Reader<'a, V, T> -where - T: Table, -{ +impl<'a, V, T: Table> Reader<'a, V, T> { pub fn into_iter_by(self, strat: S) -> Iter<'a, V, S, T> { let range = 0..self.len(); - Iter { list: self, range, strategy: strat } + Iter { v: PhantomData, list: self.repr, range, strategy: strat } } } -impl<'a, V, T, Item> IntoIterator for Reader<'a, V, T> +impl<'p, V, T, Item> IntoIterator for Reader<'p, V, T> where - V: for<'b> ListAccessable<&'b Reader<'a, V, T>>, + V: IterKind, + V::Iter: for<'b> ListAccessable<&'b ptr::Reader<'p, T>>, + InfalliblePtrs: for<'b> IterStrategy<&'b ptr::Reader<'p, T>, V::Iter, Item = Item>, T: Table, - InfalliblePtrs: for<'lb> IterStrategy, Item = Item>, { - type IntoIter = Iter<'a, V, InfalliblePtrs, T>; + type IntoIter = Iter<'p, V, InfalliblePtrs, T>; type Item = Item; fn into_iter(self) -> Self::IntoIter { diff --git a/recapn/src/message.rs b/recapn/src/message.rs index d844189..3b4a199 100644 --- a/recapn/src/message.rs +++ b/recapn/src/message.rs @@ -5,7 +5,7 @@ use crate::alloc::{ }; use crate::arena::{SegmentId, ArenaSegment, BuildArena, ReadArena}; use crate::orphan::Orphanage; -use crate::{any, ty, ReaderOf}; +use crate::{any, ty}; use crate::ptr::{ObjectBuilder, PtrBuilder, PtrReader}; use crate::rpc::{Empty, InsertableInto}; use core::cell::{Cell, UnsafeCell}; @@ -524,11 +524,6 @@ impl<'a> Reader<'a> { self.root().read_as::() } - #[inline] - pub fn read_as_struct<'b, S: ty::Struct>(&'b self) -> ReaderOf<'b, S> { - self.root().read_as_struct::() - } - /// Calculates the message's total size in words. #[inline] pub fn size_in_words(&self) -> usize { diff --git a/recapn/src/orphan.rs b/recapn/src/orphan.rs index 103fb6d..ebd5846 100644 --- a/recapn/src/orphan.rs +++ b/recapn/src/orphan.rs @@ -2,12 +2,13 @@ use core::marker::PhantomData; use crate::any::AnyStruct; use crate::data::Data; -use crate::field::{Struct, Capability}; use crate::list::List; use crate::ptr::{ElementCount, ElementSize, ObjectBuilder, OrphanBuilder, StructSize}; use crate::rpc::{self, Capable, Table}; use crate::text::{self, Text}; -use crate::{ty, Result}; +use crate::ty; +use crate::ty::kind::{Struct, Capability}; +use crate::Result; pub struct Orphanage<'b, T: Table = rpc::Empty> { builder: ObjectBuilder<'b>, diff --git a/recapn/src/ptr.rs b/recapn/src/ptr.rs index 1f47bad..30afd4e 100644 --- a/recapn/src/ptr.rs +++ b/recapn/src/ptr.rs @@ -25,7 +25,9 @@ pub use crate::data::ptr::{Reader as DataReader, Builder as DataBuilder}; pub use crate::text::ptr::{Reader as TextReader, Builder as TextBuilder}; /// A field type that can be found in the data section of a struct. -pub trait Data: ty::Value + ty::ListValue + Default + Copy + Sealed + 'static { +pub trait Data: ty::TypeKind> + Default + Copy + Sealed + 'static { + const ELEMENT_SIZE: ElementSize; + unsafe fn read(ptr: *const u8, len: u32, slot: usize, default: Self) -> Self; unsafe fn read_unchecked(ptr: *const u8, slot: usize, default: Self) -> Self; @@ -33,7 +35,14 @@ pub trait Data: ty::Value + ty::ListValue + Default + Copy + Sea unsafe fn write_unchecked(ptr: *mut u8, slot: usize, value: Self, default: Self); } +impl Sealed for bool {} +impl ty::TypeKind for bool { + type Kind = ty::kind::Data; +} + impl Data for bool { + const ELEMENT_SIZE: ElementSize = ElementSize::Bit; + #[inline] unsafe fn read(ptr: *const u8, len_bytes: u32, slot: usize, default: Self) -> Self { let byte_offset = slot / 8; @@ -68,8 +77,15 @@ impl Data for bool { } macro_rules! impl_int { - ($ty:ty) => { + ($ty:ty, $size:ident) => { + impl Sealed for $ty {} + impl ty::TypeKind for $ty { + type Kind = ty::kind::Data; + } + impl Data for $ty { + const ELEMENT_SIZE: ElementSize = ElementSize::$size; + #[inline] unsafe fn read(ptr: *const u8, len_bytes: u32, slot: usize, default: Self) -> Self { let slot_byte_offset = slot * core::mem::size_of::(); @@ -109,16 +125,23 @@ macro_rules! impl_int { }; } -impl_int!(u8); -impl_int!(i8); -impl_int!(u16); -impl_int!(i16); -impl_int!(u32); -impl_int!(i32); -impl_int!(u64); -impl_int!(i64); +impl_int!(u8, Byte); +impl_int!(i8, Byte); +impl_int!(u16, TwoBytes); +impl_int!(i16, TwoBytes); +impl_int!(u32, FourBytes); +impl_int!(i32, FourBytes); +impl_int!(u64, EightBytes); +impl_int!(i64, EightBytes); + +impl Sealed for f32 {} +impl ty::TypeKind for f32 { + type Kind = ty::kind::Data; +} impl Data for f32 { + const ELEMENT_SIZE: ElementSize = ElementSize::FourBytes; + #[inline] unsafe fn read(ptr: *const u8, len_bytes: u32, slot: usize, default: Self) -> Self { Self::from_bits(u32::read(ptr, len_bytes, slot, default.to_bits())) @@ -138,7 +161,14 @@ impl Data for f32 { } } +impl Sealed for f64 {} +impl ty::TypeKind for f64 { + type Kind = ty::kind::Data; +} + impl Data for f64 { + const ELEMENT_SIZE: ElementSize = ElementSize::EightBytes; + #[inline] unsafe fn read(ptr: *const u8, len_bytes: u32, slot: usize, default: Self) -> Self { Self::from_bits(u64::read(ptr, len_bytes, slot, default.to_bits())) @@ -3952,6 +3982,16 @@ impl<'a, T: Table> PtrBuilder<'a, T> { }) } + #[inline] + pub fn into_empty_list(self, size: ElementSize) -> ListBuilder<'a, T> { + ListBuilder::empty( + self.builder, + self.ptr, + self.table, + size, + ) + } + /// Gets a list builder for this pointer, or an empty list builder if the value is null or /// invalid. #[inline] @@ -3961,12 +4001,7 @@ impl<'a, T: Table> PtrBuilder<'a, T> { ) -> ListBuilder<'a, T> { match self.to_list_mut(expected_element_size) { Ok(builder) => builder, - Err((_, this)) => ListBuilder::empty( - this.builder, - this.ptr, - this.table.clone(), - expected_element_size.unwrap_or(ElementSize::Void).into(), - ), + Err((_, this)) => this.into_empty_list(expected_element_size.unwrap_or(ElementSize::Void)), } } diff --git a/recapn/src/text.rs b/recapn/src/text.rs index 0419c66..541501a 100644 --- a/recapn/src/text.rs +++ b/recapn/src/text.rs @@ -38,12 +38,6 @@ pub type Reader<'a> = Text>; pub type Builder<'a> = Text>; impl Sealed for Text {} -impl ty::Value for Text { - type Default = Reader<'static>; -} -impl ty::ListValue for Text { - const ELEMENT_SIZE: ElementSize = ElementSize::Pointer; -} impl<'a> Reader<'a> { pub const EMPTY: Self = Self::empty(); diff --git a/recapn/src/ty.rs b/recapn/src/ty.rs index 8c41a29..d150f1f 100644 --- a/recapn/src/ty.rs +++ b/recapn/src/ty.rs @@ -12,12 +12,12 @@ use crate::ReaderOf; use crate::{NotInSchema, IntoFamily, Result}; /// An enum marker trait. -pub trait Enum: Copy + TryFrom + Into + Default + 'static {} +pub trait Enum: TypeKind> + Copy + TryFrom + Into + Default + 'static {} pub type EnumResult = Result; /// A capability marker trait. -pub trait Capability: 'static { +pub trait Capability: TypeKind> + 'static { /// The typeless client this type is a wrapper around. type Client; @@ -40,7 +40,7 @@ pub trait StructView: 'static { /// A marker that indicates that a type represents a struct. /// /// This provides the struct's size, along with the reader and builder associated types. -pub trait Struct: StructView { +pub trait Struct: TypeKind> + StructView { const SIZE: StructSize; } @@ -154,6 +154,19 @@ pub trait FromPtr { fn get(ptr: T) -> Self::Output; } +/// Inherits all kind implementations. This way we can +impl FromPtr for T +where + T: TypeKind, + T::Kind: FromPtr, +{ + type Output = >::Output; + + fn get(ptr: U) -> Self::Output { + >::get(ptr) + } +} + /// A trait used to describe types which can be read from other pointer types (fallible). pub trait ReadPtr: FromPtr { fn try_get_option(ptr: T) -> Result>; @@ -161,7 +174,7 @@ pub trait ReadPtr: FromPtr { fn get_option(ptr: T) -> Option; } -impl<'a, S: Struct, T: Table> FromPtr> for field::Struct { +impl<'a, S: Struct, T: Table> FromPtr> for kind::Struct { type Output = ReaderOf<'a, S, T>; fn get(ptr: any::StructReader<'a, T>) -> Self::Output { @@ -169,7 +182,7 @@ impl<'a, S: Struct, T: Table> FromPtr> for field::Struc } } -impl<'a, S: Struct, T: Table> FromPtr> for field::Struct { +impl<'a, S: Struct, T: Table> FromPtr> for kind::Struct { type Output = ReaderOf<'a, S, T>; fn get(reader: any::PtrReader<'a, T>) -> Self::Output { @@ -180,7 +193,7 @@ impl<'a, S: Struct, T: Table> FromPtr> for field::Struct ReadPtr> for field::Struct { +impl<'a, S: Struct, T: Table> ReadPtr> for kind::Struct { fn try_get_option(reader: any::PtrReader<'a, T>) -> Result> { match reader.as_ref().to_struct() { Ok(Some(ptr)) => Ok(Some(ptr.into())), @@ -200,11 +213,6 @@ impl<'a, S: Struct, T: Table> ReadPtr> for field::Struct ListValue for T +where + T: list::TypeKind + 'static, + T::Kind: ListValue, +{ + const ELEMENT_SIZE: ElementSize = ::ELEMENT_SIZE; +} + +impl ListValue for kind::Data { + const ELEMENT_SIZE: ElementSize = ::ELEMENT_SIZE; +} -pub trait DynListValue: Value { +pub trait DynListValue: 'static { const PTR_ELEMENT_SIZE: ptr::PtrElementSize; } impl DynListValue for T { @@ -238,34 +257,48 @@ pub type UInt64 = u64; pub type Float32 = f32; pub type Float64 = f64; -macro_rules! impl_value { - ($ty:ty, $size:ident) => { - impl Sealed for $ty {} - impl Value for $ty { - type Default = Self; - } - impl ListValue for $ty { - const ELEMENT_SIZE: ElementSize = ElementSize::$size; - } - }; +/// A generic "type kind" constraining trait. +/// +/// Type kinds allow us to write generic trait implementations over non-overlapping types. This +/// pattern of implementing over type kinds is used heavily in this library and primarily starts +/// here. +/// +/// As you might know, you cannot have multiple implementation blocks with overlapping definitions. +/// This generally means that you can't have more than one generic implementation over a generic +/// type. In this library, we need that! Most of the library is generic in some way. +pub trait TypeKind { + /// The kind this type is. + type Kind; } -impl_value!(Void, Void); -impl_value!(Bool, Bit); -impl_value!(UInt8, Byte); -impl_value!(Int8, Byte); -impl_value!(UInt16, TwoBytes); -impl_value!(Int16, TwoBytes); -impl_value!(UInt32, FourBytes); -impl_value!(Int32, FourBytes); -impl_value!(UInt64, EightBytes); -impl_value!(Int64, EightBytes); -impl_value!(Float32, FourBytes); -impl_value!(Float64, EightBytes); - -impl Value for List { - type Default = ptr::ListReader<'static>; -} -impl ListValue for List { - const ELEMENT_SIZE: list::ElementSize = list::ElementSize::Pointer; -} +/// Contains "kind" marker types used for writting blanket implementations over non-overlapping +/// types. +pub mod kind { + use core::marker::PhantomData; + + use crate::field; + use crate::list; + use crate::ptr; + use crate::ty; + + type Fantom = PhantomData T>; + + /// A type kind for primitive data types like uint8, int32, f64, and bool. See [`ptr::Data`]. + pub struct Data(Fantom); + /// A type kind for enum types. See [`ty::Enum`]. + pub struct Enum(Fantom); + /// A type kind for capability types. See [`ty::Capability`]. + pub struct Capability(Fantom); + /// A type kind for user struct types. See [`ty::Struct`]. + pub struct Struct(Fantom); + /// A type kind for user group types. See [`field::Group`]. + pub struct Group(Fantom); + /// A type kind for pointer field types. This is not the same as pointer list types which use + /// [`PtrList`] instead. Most notably, [`Struct`] kinds are not considered [`PtrList`] kinds, + /// but are considered [`PtrField`] kinds. + pub struct PtrField(Fantom

); + /// A type kind for pointer list types. This is not the same as pointer field types which use + /// [`PtrField`] instead. Most notably, [`Struct`] kinds are considered [`PtrField`] kinds, + /// but are not considered [`PtrList`] kinds. + pub struct PtrList(Fantom

); +} \ No newline at end of file diff --git a/recapnc/src/bin/capnpc-rust.rs b/recapnc/src/bin/capnpc-rust.rs index a2f20d1..acd79b0 100644 --- a/recapnc/src/bin/capnpc-rust.rs +++ b/recapnc/src/bin/capnpc-rust.rs @@ -13,7 +13,7 @@ fn main() -> Result<()> { let mut stdin = std::io::stdin().lock(); let message = io::read_from_stream(&mut stdin, StreamOptions::default())?; let reader = Reader::new(&message, ReaderOptions::default()); - let request = reader.root().read_as_struct::(); + let request = reader.read_as::(); let context = GeneratorContext::new(&request)?; diff --git a/recapnc/src/gen/capnp/schema.capnp.rs b/recapnc/src/gen/capnp/schema.capnp.rs index f693e14..a11c59b 100644 --- a/recapnc/src/gen/capnp/schema.capnp.rs +++ b/recapnc/src/gen/capnp/schema.capnp.rs @@ -10,29 +10,29 @@ _p::generate_file! { size: { data: 5, ptrs: 6 }, fields: { ID, id, id_mut, u64 = { slot: 0, default: 0 }, - DISPLAY_NAME, display_name, display_name_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, + DISPLAY_NAME, display_name, display_name_mut, _p::Text = { slot: 0, default: None }, DISPLAY_NAME_PREFIX_LENGTH, display_name_prefix_length, display_name_prefix_length_mut, u32 = { slot: 2, default: 0 }, SCOPE_ID, scope_id, scope_id_mut, u64 = { slot: 2, default: 0 }, - PARAMETERS, parameters, parameters_mut, _p::List<_p::Struct> = { - slot: 5, default: _p::eslpr() + PARAMETERS, parameters, parameters_mut, _p::List = { + slot: 5, default: None }, IS_GENERIC, is_generic, is_generic_mut, bool = { slot: 288, default: false }, - NESTED_NODES, nested_nodes, nested_nodes_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + NESTED_NODES, nested_nodes, nested_nodes_mut, _p::List = { + slot: 1, default: None }, - ANNOTATIONS, annotations, annotations_mut, _p::List<_p::Struct> = { - slot: 2, default: _p::eslpr() + ANNOTATIONS, annotations, annotations_mut, _p::List = { + slot: 2, default: None }, }, union { tag_slot: 6, fields: { FILE, File, file, file_mut, () = { case: 0 }, - STRUCT, Struct, r#struct, struct_mut, _p::Group<__file::node::Struct> = { case: 1 }, - ENUM, Enum, r#enum, enum_mut, _p::Group<__file::node::Enum> = { case: 2 }, - INTERFACE, Interface, interface, interface_mut, _p::Group<__file::node::Interface> = { case: 3 }, - CONST, Const, r#const, const_mut, _p::Group<__file::node::Const> = { case: 4 }, - ANNOTATION, Annotation, annotation, annotation_mut, _p::Group<__file::node::Annotation> = { case: 5 }, + STRUCT, Struct, r#struct, struct_mut, __file::node::Struct = { case: 1 }, + ENUM, Enum, r#enum, enum_mut, __file::node::Enum = { case: 2 }, + INTERFACE, Interface, interface, interface_mut, __file::node::Interface = { case: 3 }, + CONST, Const, r#const, const_mut, __file::node::Const = { case: 4 }, + ANNOTATION, Annotation, annotation, annotation_mut, __file::node::Annotation = { case: 5 }, }, }, nested: { @@ -41,47 +41,47 @@ _p::generate_file! { fields: { DATA_WORD_COUNT, data_word_count, data_word_count_mut, u16 = { slot: 7, default: 0 }, POINTER_COUNT, pointer_count, pointer_count_mut, u16 = { slot: 12, default: 0 }, - PREFERRED_LIST_ENCODING, preferred_list_encoding, preferred_list_encoding_mut, _p::Enum<__file::ElementSize> = { + PREFERRED_LIST_ENCODING, preferred_list_encoding, preferred_list_encoding_mut, __file::ElementSize = { slot: 13, default: __file::ElementSize::Empty }, IS_GROUP, is_group, is_group_mut, bool = { slot: 224, default: false }, DISCRIMINANT_COUNT, discriminant_count, discriminant_count_mut, u16 = { slot: 15, default: 0 }, DISCRIMINANT_OFFSET, discriminant_offset, discriminant_offset_mut, u32 = { slot: 8, default: 0 }, - FIELDS, fields, fields_mut, _p::List<_p::Struct<__file::Field>> = { - slot: 3, default: _p::eslpr() + FIELDS, fields, fields_mut, _p::List<__file::Field> = { + slot: 3, default: None }, }, }, group Enum { mod: r#enum, fields: { - ENUMERANTS, enumerants, enumerants_mut, _p::List<_p::Struct<__file::Enumerant>> = { - slot: 3, default: _p::eslpr() + ENUMERANTS, enumerants, enumerants_mut, _p::List<__file::Enumerant> = { + slot: 3, default: None }, }, }, group Interface { mod: interface, fields: { - METHODS, methods, methods_mut, _p::List<_p::Struct<__file::Method>> = { - slot: 3, default: _p::eslpr() + METHODS, methods, methods_mut, _p::List<__file::Method> = { + slot: 3, default: None }, - SUPERCLASSES, superclasses, superclasses_mut, _p::List<_p::Struct<__file::Superclass>> = { - slot: 4, default: _p::eslpr() + SUPERCLASSES, superclasses, superclasses_mut, _p::List<__file::Superclass> = { + slot: 4, default: None }, }, }, group Const { mod: r#const, fields: { - TYPE, r#type, type_mut, _p::Struct<__file::Type> = { slot: 3, default: _p::StructReader::empty() }, - VALUE, value, value_mut, _p::Struct<__file::Value> = { slot: 4, default: _p::StructReader::empty() }, + TYPE, r#type, type_mut, __file::Type = { slot: 3, default: None }, + VALUE, value, value_mut, __file::Value = { slot: 4, default: None }, }, }, group Annotation { mod: annotation, fields: { - TYPE, r#type, type_mut, _p::Struct<__file::Type> = { slot: 3, default: _p::StructReader::empty() }, + TYPE, r#type, type_mut, __file::Type = { slot: 3, default: None }, TARGETS_FILE, targets_file, targets_file_mut, bool = { slot: 112, default: false }, TARGETS_CONST, targets_const, targets_const_mut, bool = { slot: 113, default: false }, TARGETS_ENUM, targets_enum, targets_enum_mut, bool = { slot: 114, default: false }, @@ -100,14 +100,14 @@ _p::generate_file! { mod: parameter, size: { data: 0, ptrs: 1 }, fields: { - NAME, name, name_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, + NAME, name, name_mut, _p::Text = { slot: 0, default: None }, }, }, struct NestedNode { mod: nested_node, size: { data: 0, ptrs: 1 }, fields: { - NAME, name, name_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, + NAME, name, name_mut, _p::Text = { slot: 0, default: None }, ID, id, id_mut, u64 = { slot: 0, default: 0 }, }, }, @@ -116,9 +116,9 @@ _p::generate_file! { size: { data: 0, ptrs: 1 }, fields: { ID, id, id_mut, u64 = { slot: 0, default: 0 }, - DOC_COMMENT, doc_comment, doc_comment_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, - MEMBERS, members, members_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + DOC_COMMENT, doc_comment, doc_comment_mut, _p::Text = { slot: 0, default: None }, + MEMBERS, members, members_mut, _p::List = { + slot: 1, default: None }, }, nested: { @@ -126,7 +126,7 @@ _p::generate_file! { mod: member, size: { data: 0, ptrs: 1 }, fields: { - DOC_COMMENT, doc_comment, doc_comment_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, + DOC_COMMENT, doc_comment, doc_comment_mut, _p::Text = { slot: 0, default: None }, }, } }, @@ -137,19 +137,19 @@ _p::generate_file! { mod: field, size: { data: 3, ptrs: 4 }, fields: { - NAME, name, name_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, + NAME, name, name_mut, _p::Text = { slot: 0, default: None }, CODE_ORDER, code_order, code_order_mut, u16 = { slot: 0, default: 0 }, - ANNOTATIONS, annotations, annotations_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + ANNOTATIONS, annotations, annotations_mut, _p::List = { + slot: 1, default: None }, DISCRIMINANT_VALUE, discriminant_value, discriminant_value_mut, u16 = { slot: 1, default: 65535 }, - ORDINAL, ordinal, ordinal_mut, _p::Group = (), + ORDINAL, ordinal, ordinal_mut, field::Ordinal = (), }, union { tag_slot: 4, fields: { - SLOT, Slot, slot, slot_mut, _p::Group<__file::field::Slot> = { case: 0 }, - GROUP, Group, group, group_mut, _p::Group<__file::field::Group> = { case: 1 }, + SLOT, Slot, slot, slot_mut, __file::field::Slot = { case: 0 }, + GROUP, Group, group, group_mut, __file::field::Group = { case: 1 }, }, }, nested: { @@ -157,8 +157,8 @@ _p::generate_file! { mod: slot, fields: { OFFSET, offset, offset_mut, u32 = { slot: 1, default: 0 }, - TYPE, r#type, type_mut, _p::Struct<__file::Type> = { slot: 2, default: _p::StructReader::empty() }, - DEFAULT_VALUE, default_value, default_value_mut, _p::Struct<__file::Value> = { slot: 3, default: _p::StructReader::empty() }, + TYPE, r#type, type_mut, __file::Type = { slot: 2, default: None }, + DEFAULT_VALUE, default_value, default_value_mut, __file::Value = { slot: 3, default: None }, HAD_EXPLICIT_DEFAULT, had_explicit_default, had_explicit_default_mut, bool = { slot: 128, default: false }, }, }, @@ -185,10 +185,10 @@ _p::generate_file! { mod: enumerant, size: { data: 1, ptrs: 2 }, fields: { - NAME, name, name_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, + NAME, name, name_mut, _p::Text = { slot: 0, default: None }, CODE_ORDER, code_order, code_order_mut, u16 = { slot: 0, default: 0 }, - ANNOTATIONS, annotations, annotations_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + ANNOTATIONS, annotations, annotations_mut, _p::List = { + slot: 1, default: None }, }, }, @@ -197,8 +197,8 @@ _p::generate_file! { size: { data: 1, ptrs: 1 }, fields: { ID, id, id_mut, u64 = { slot: 0, default: 0 }, - BRAND, brand, brand_mut, _p::List<_p::Struct> = { - slot: 0, default: _p::eslpr() + BRAND, brand, brand_mut, _p::List = { + slot: 0, default: None } }, }, @@ -206,17 +206,17 @@ _p::generate_file! { mod: method, size: { data: 3, ptrs: 5 }, fields: { - NAME, name, name_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, + NAME, name, name_mut, _p::Text = { slot: 0, default: None }, CODE_ORDER, code_order, code_order_mut, u16 = { slot: 0, default: 0 }, - IMPLICIT_PARAMETERS, implicit_parameters, implicit_parameters_mut, _p::List<_p::Struct> = { - slot: 4, default: _p::eslpr() + IMPLICIT_PARAMETERS, implicit_parameters, implicit_parameters_mut, _p::List = { + slot: 4, default: None }, PARAM_STRUCT_TYPE, param_struct_type, param_struct_type_mut, u64 = { slot: 1, default: 0 }, - PARAM_BRAND, param_brand, param_brand_mut, _p::Struct = { slot: 2, default: _p::StructReader::empty() }, + PARAM_BRAND, param_brand, param_brand_mut, Brand = { slot: 2, default: None }, RESULT_STRUCT_TYPE, result_struct_type, result_struct_type_mut, u64 = { slot: 2, default: 0 }, - RESULT_BRAND, result_brand, result_brand_mut, _p::Struct = { slot: 3, default: _p::StructReader::empty() }, - ANNOTATIONS, annotations, annotations_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + RESULT_BRAND, result_brand, result_brand_mut, Brand = { slot: 3, default: None }, + ANNOTATIONS, annotations, annotations_mut, _p::List = { + slot: 1, default: None }, }, }, @@ -241,39 +241,39 @@ _p::generate_file! { FLOAT64, Float64, float64, float64_mut, () = { case: 11 }, TEXT, Text, text, text_mut, () = { case: 12 }, DATA, Data, data, data_mut, () = { case: 13 }, - LIST, List, list, list_mut, _p::Group<__file::r#type::List> = { case: 14 }, - ENUM, Enum, r#enum, enum_mut, _p::Group<__file::r#type::Enum> = { case: 15 }, - STRUCT, Struct, r#struct, struct_mut, _p::Group<__file::r#type::Struct> = { case: 16 }, - INTERFACE, Interface, interface, interface_mut, _p::Group<__file::r#type::Interface> = { case: 17 }, - ANY_POINTER, AnyPointer, any_pointer, any_pointer_mut, _p::Group<__file::r#type::AnyPointer> = { case: 18 }, + LIST, List, list, list_mut, __file::r#type::List = { case: 14 }, + ENUM, Enum, r#enum, enum_mut, __file::r#type::Enum = { case: 15 }, + STRUCT, Struct, r#struct, struct_mut, __file::r#type::Struct = { case: 16 }, + INTERFACE, Interface, interface, interface_mut, __file::r#type::Interface = { case: 17 }, + ANY_POINTER, AnyPointer, any_pointer, any_pointer_mut, __file::r#type::AnyPointer = { case: 18 }, }, }, nested: { group List { mod: list, fields: { - ELEMENT_TYPE, element_type, element_type_mut, _p::Struct<__file::Type> = { slot: 0, default: _p::StructReader::empty() }, + ELEMENT_TYPE, element_type, element_type_mut, __file::Type = { slot: 0, default: None }, }, }, group Enum { mod: r#enum, fields: { TYPE_ID, type_id, type_id_mut, u64 = { slot: 1, default: 0 }, - BRAND, brand, brand_mut, _p::Struct<__file::Brand> = { slot: 0, default: _p::StructReader::empty() }, + BRAND, brand, brand_mut, __file::Brand = { slot: 0, default: None }, }, }, group Struct { mod: r#struct, fields: { TYPE_ID, type_id, type_id_mut, u64 = { slot: 1, default: 0 }, - BRAND, brand, brand_mut, _p::Struct<__file::Brand> = { slot: 0, default: _p::StructReader::empty() }, + BRAND, brand, brand_mut, __file::Brand = { slot: 0, default: None }, }, }, group Interface { mod: interface, fields: { TYPE_ID, type_id, type_id_mut, u64 = { slot: 1, default: 0 }, - BRAND, brand, brand_mut, _p::Struct<__file::Brand> = { slot: 0, default: _p::StructReader::empty() }, + BRAND, brand, brand_mut, __file::Brand = { slot: 0, default: None }, }, }, group AnyPointer { @@ -282,9 +282,9 @@ _p::generate_file! { union { tag_slot: 4, fields: { - UNCONSTRAINED, Unconstrained, unconstrained, unconstrained_mut, _p::Group<__file::r#type::any_pointer::Unconstrained> = { case: 0 }, - PARAMETER, Parameter, parameter, parameter_mut, _p::Group<__file::r#type::any_pointer::Parameter> = { case: 1 }, - IMPLICIT_METHOD_PARAMETER, ImplicitMethodParameter, implicit_method_parameter, implicit_method_parameter_mut, _p::Group<__file::r#type::any_pointer::ImplicitMethodParameter> = { case: 2 }, + UNCONSTRAINED, Unconstrained, unconstrained, unconstrained_mut, __file::r#type::any_pointer::Unconstrained = { case: 0 }, + PARAMETER, Parameter, parameter, parameter_mut, __file::r#type::any_pointer::Parameter = { case: 1 }, + IMPLICIT_METHOD_PARAMETER, ImplicitMethodParameter, implicit_method_parameter, implicit_method_parameter_mut, __file::r#type::any_pointer::ImplicitMethodParameter = { case: 2 }, }, }, nested: { @@ -322,8 +322,8 @@ _p::generate_file! { mod: brand, size: { data: 0, ptrs: 1 }, fields: { - SCOPES, scopes, scopes_mut, _p::List<_p::Struct<__file::brand::Scope>> = { - slot: 0, default: _p::eslpr() + SCOPES, scopes, scopes_mut, _p::List<__file::brand::Scope> = { + slot: 0, default: None } }, nested: { @@ -336,8 +336,8 @@ _p::generate_file! { union { tag_slot: 4, fields: { - BIND, Bind, bind, bind_mut, _p::List<_p::Struct<__file::brand::Binding>> = { - case: 0, slot: 0, default: _p::eslpr() + BIND, Bind, bind, bind_mut, _p::List<__file::brand::Binding> = { + case: 0, slot: 0, default: None }, INHERIT, Inherit, inherit, inherit_mut, () = { case: 1 }, }, @@ -351,7 +351,7 @@ _p::generate_file! { tag_slot: 0, fields: { UNBOUND, Unbound, unbound, unbound_mut, () = { case: 0 }, - TYPE, Type, r#type, type_mut, _p::Struct<__file::Type> = { case: 1, slot: 0, default: _p::StructReader::empty() }, + TYPE, Type, r#type, type_mut, __file::Type = { case: 1, slot: 0, default: None }, }, }, }, @@ -376,13 +376,13 @@ _p::generate_file! { UINT64, Uint64, uint64, uint64_mut, u64 = { case: 9, slot: 1, default: 0 }, FLOAT32, Float32, float32, float32_mut, f32 = { case: 10, slot: 1, default: 0. }, FLOAT64, Float64, float64, float64_mut, f64 = { case: 11, slot: 1, default: 0. }, - TEXT, Text, text, text_mut, _p::Text = { case: 12, slot: 0, default: _p::text::Reader::empty() }, - DATA, Data, data, data_mut, _p::Data = { case: 13, slot: 0, default: _p::data::Reader::empty() }, - LIST, List, list, list_mut, _p::AnyPtr = { case: 14, slot: 0, default: _p::any::ptr::PtrReader::null() }, + TEXT, Text, text, text_mut, _p::Text = { case: 12, slot: 0, default: None }, + DATA, Data, data, data_mut, _p::Data = { case: 13, slot: 0, default: None }, + LIST, List, list, list_mut, _p::AnyPtr = { case: 14, slot: 0, default: None }, ENUM, Enum, r#enum, enum_mut, u16 = { case: 15, slot: 1, default: 0 }, - STRUCT, Struct, r#struct, struct_mut, _p::AnyPtr = { case: 16, slot: 0, default: _p::any::ptr::PtrReader::null() }, + STRUCT, Struct, r#struct, struct_mut, _p::AnyPtr = { case: 16, slot: 0, default: None }, INTERFACE, Interface, interface, interface_mut, () = { case: 17 }, - ANY_POINTER, AnyPointer, any_pointer, any_pointer_mut, _p::AnyPtr = { case: 18, slot: 0, default: _p::any::ptr::PtrReader::null() }, + ANY_POINTER, AnyPointer, any_pointer, any_pointer_mut, _p::AnyPtr = { case: 18, slot: 0, default: None }, }, }, }, @@ -391,10 +391,10 @@ _p::generate_file! { size: { data: 1, ptrs: 2 }, fields: { ID, id, id_mut, u64 = { slot: 0, default: 0 }, - BRAND, brand, brand_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + BRAND, brand, brand_mut, _p::List = { + slot: 1, default: None }, - VALUE, value, value_mut, _p::Struct<__file::Value> = { slot: 0, default: _p::StructReader::empty() }, + VALUE, value, value_mut, __file::Value = { slot: 0, default: None }, }, }, struct CapnpVersion { @@ -410,15 +410,15 @@ _p::generate_file! { mod: code_generator_request, size: { data: 0, ptrs: 4 }, fields: { - CAPNP_VERSION, capnp_version, capnp_version_mut, _p::Struct = { slot: 2, default: _p::StructReader::empty() }, - NODES, nodes, nodes_mut, _p::List<_p::Struct> = { - slot: 0, default: _p::eslpr() + CAPNP_VERSION, capnp_version, capnp_version_mut, CapnpVersion = { slot: 2, default: None }, + NODES, nodes, nodes_mut, _p::List = { + slot: 0, default: None }, - SOURCE_INFO, source_info, source_info_mut, _p::List<_p::Struct> = { - slot: 3, default: _p::eslpr() + SOURCE_INFO, source_info, source_info_mut, _p::List = { + slot: 3, default: None }, - REQUESTED_FILES, requested_files, requested_files_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + REQUESTED_FILES, requested_files, requested_files_mut, _p::List = { + slot: 1, default: None } }, nested: { @@ -427,9 +427,9 @@ _p::generate_file! { size: { data: 1, ptrs: 2 }, fields: { ID, id, id_mut, u64 = { slot: 0, default: 0 }, - FILENAME, filename, filename_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, - IMPORTS, imports, imports_mut, _p::List<_p::Struct<__file::code_generator_request::requested_file::Import>> = { - slot: 1, default: _p::eslpr() + FILENAME, filename, filename_mut, _p::Text = { slot: 0, default: None }, + IMPORTS, imports, imports_mut, _p::List<__file::code_generator_request::requested_file::Import> = { + slot: 1, default: None }, }, nested: { @@ -438,7 +438,7 @@ _p::generate_file! { size: { data: 1, ptrs: 1 }, fields: { ID, id, id_mut, u64 = { slot: 0, default: 0 }, - NAME, name, name_mut, _p::Text = { slot: 0, default: _p::text::Reader::empty() }, + NAME, name, name_mut, _p::Text = { slot: 0, default: None }, }, }, }, @@ -486,4 +486,7 @@ impl From for u16 { } } +impl _p::ty::TypeKind for ElementSize { + type Kind = _p::ty::kind::Enum; +} impl _p::ty::Enum for ElementSize {} diff --git a/recapnc/src/generator.rs b/recapnc/src/generator.rs index 43401e2..f8b3a7f 100644 --- a/recapnc/src/generator.rs +++ b/recapnc/src/generator.rs @@ -475,8 +475,8 @@ impl<'a> GeneratorContext<'a> { Ok((syn_type, kind)) } schema::field::Which::Group(group) => { - let type_name = self.resolve_type_name(scope, group.type_id(), required_imports)?; - let syn_type = Box::new(syn::parse_quote!(_p::Group<#type_name>)); + let path = self.resolve_type_name(scope, group.type_id(), required_imports)?; + let syn_type = Box::new(syn::TypePath { qself: None, path }.into()); Ok((syn_type, FieldKind::Pointer)) } } @@ -520,12 +520,12 @@ impl<'a> GeneratorContext<'a> { syn::parse_quote!(_p::List<#resolved>) }, TypeKind::Enum(e) => { - let type_name = self.resolve_type_name(scope, e.type_id(), required_imports)?; - syn::parse_quote!(_p::Enum<#type_name>) + let path = self.resolve_type_name(scope, e.type_id(), required_imports)?; + syn::TypePath { qself: None, path }.into() }, TypeKind::Struct(s) => { - let type_name = self.resolve_type_name(scope, s.type_id(), required_imports)?; - syn::parse_quote!(_p::Struct<#type_name>) + let path = self.resolve_type_name(scope, s.type_id(), required_imports)?; + syn::TypePath { qself: None, path }.into() }, TypeKind::Interface(_) => todo!("resolve interface types"), TypeKind::AnyPointer(ptr) => match ptr.which()? { @@ -589,7 +589,7 @@ impl<'a> GeneratorContext<'a> { quote!(_p::text::Reader::from_slice(#bytes)) } - _ => quote!(_p::text::Reader::empty()), + _ => quote!(None), } } TypeKind::Data(()) => { @@ -602,7 +602,7 @@ impl<'a> GeneratorContext<'a> { quote!(_p::data::Reader::from_slice(#bytes)) } - _ => quote!(_p::data::Reader::empty()), + _ => quote!(None), } } TypeKind::List(list) => { @@ -634,7 +634,7 @@ impl<'a> GeneratorContext<'a> { todo!() } - _ => quote!(_p::ListReader::empty(_p::ElementSize::size_of::<#element_type>())), + _ => quote!(None), } } TypeKind::Enum(info) => { @@ -679,7 +679,7 @@ impl<'a> GeneratorContext<'a> { quote!(_p::StructReader::slice_unchecked(#words, #size)) } - _ => quote!(_p::StructReader::empty()), + _ => quote!(None), } } TypeKind::Interface(_) => { @@ -691,15 +691,15 @@ impl<'a> GeneratorContext<'a> { match kind.which()? { AnyPtrKind::Unconstrained(unconstrained) => match (unconstrained.which()?, ptr) { (ConstraintKind::AnyKind(_), None) => { - quote!(_p::ptr::PtrReader::null()) + quote!(None) } (ConstraintKind::Struct(_), None) => { - quote!(_p::ptr::StructReader::empty()) + quote!(None) } (ConstraintKind::List(_), None) => { - quote!(_p::ptr::ListReader::empty()) + quote!(None) } - (ConstraintKind::Capability(_), None) => quote!(()), + (ConstraintKind::Capability(_), None) => quote!(None), _ => todo!("generate default values for 'unconstrained' ptr types") }, AnyPtrKind::Parameter(_) => todo!("generate default values for generic types"), diff --git a/recapnc/src/lib.rs b/recapnc/src/lib.rs index 7b59ce2..1b53c8b 100644 --- a/recapnc/src/lib.rs +++ b/recapnc/src/lib.rs @@ -8,8 +8,8 @@ pub mod prelude { pub use recapn::any::{self, AnyList, AnyPtr, AnyStruct}; pub use recapn::data::{self, Data}; pub use recapn::field::{ - self, Accessor, AccessorMut, Descriptor, Enum, FieldGroup, Group, Struct, - UnionViewer, Variant, VariantInfo, VariantDescriptor, VariantMut, ViewOf, Viewable, + self, Accessor, AccessorMut, Descriptor, Group, UnionViewer, + Variant, VariantInfo, VariantDescriptor, VariantMut, ViewOf, Viewable, }; pub use recapn::list::{self, List}; pub use recapn::ptr::{ @@ -52,6 +52,10 @@ pub mod prelude { type Builder<'a, T: _p::Table> = $modname::Builder<'a, T>; } + impl _p::ty::TypeKind for $name { + type Kind = _p::ty::kind::Struct; + } + impl _p::ty::Struct for $name { const SIZE: _p::StructSize = _p::StructSize $size; } @@ -111,7 +115,11 @@ pub mod prelude { type Builder<'a, T: _p::rpc::Table> = $modname::Builder<'a, T>; } - impl _p::FieldGroup for $name { + impl _p::ty::TypeKind for $name { + type Kind = _p::ty::kind::Group; + } + + impl _p::Group for $name { unsafe fn clear<'a, 'b, T: _p::rpc::Table>(_: &'a mut _p::StructBuilder<'b, T>) { std::unimplemented!() } diff --git a/recapnc/src/quotes.rs b/recapnc/src/quotes.rs index f05126b..2f0d49f 100644 --- a/recapnc/src/quotes.rs +++ b/recapnc/src/quotes.rs @@ -230,6 +230,9 @@ to_tokens!(GeneratedStruct |self| { }; let struct_group_marker = if let Some(StructSize { data, ptrs }) = size { quote! { + impl _p::ty::TypeKind for #name { + type Kind = _p::ty::kind::Struct; + } impl _p::ty::Struct for #name { const SIZE: _p::StructSize = _p::StructSize { data: #data, ptrs: #ptrs }; } @@ -237,7 +240,10 @@ to_tokens!(GeneratedStruct |self| { } else { let clears = self.clear_all(); quote! { - impl _p::FieldGroup for #name { + impl _p::ty::TypeKind for #name { + type Kind = _p::ty::kind::Group; + } + impl _p::Group for #name { unsafe fn clear<'a, 'b, T: _p::rpc::Table>(s: &'a mut _p::StructBuilder<'b, T>) { #(#clears)* } @@ -644,6 +650,9 @@ to_tokens!(GeneratedEnum |self| { } } + impl _p::ty::TypeKind for #name { + type Kind = _p::ty::kind::Enum; + } impl _p::ty::Enum for #name {} } }); diff --git a/tests/src/gen/capnp/test-import.capnp.rs b/tests/src/gen/capnp/test-import.capnp.rs index 6ae1440..20787b4 100644 --- a/tests/src/gen/capnp/test-import.capnp.rs +++ b/tests/src/gen/capnp/test-import.capnp.rs @@ -89,6 +89,9 @@ impl _p::StructView for TestImport { type Reader<'a, T: _p::rpc::Table> = test_import::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = test_import::Builder<'a, T>; } +impl _p::ty::TypeKind for TestImport { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for TestImport { const SIZE: _p::StructSize = _p::StructSize { data: 0u16, @@ -96,22 +99,23 @@ impl _p::ty::Struct for TestImport { }; } impl TestImport { - const FIELD: _p::Descriptor<_p::Struct<__imports::capnp_test_capnp::TestAllTypes>> = _p::Descriptor::< - _p::Struct<__imports::capnp_test_capnp::TestAllTypes>, + const FIELD: _p::Descriptor<__imports::capnp_test_capnp::TestAllTypes> = _p::Descriptor::< + __imports::capnp_test_capnp::TestAllTypes, > { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> test_import::Reader<'p, T> { #[inline] pub fn field( &self, - ) -> _p::Accessor<'_, 'p, T, _p::Struct<__imports::capnp_test_capnp::TestAllTypes>> { + ) -> _p::Accessor<'_, 'p, T, __imports::capnp_test_capnp::TestAllTypes> { unsafe { - <_p::Struct< - __imports::capnp_test_capnp::TestAllTypes, - > as _p::field::FieldType>::accessor(&self.0, &TestImport::FIELD) + <__imports::capnp_test_capnp::TestAllTypes as _p::field::FieldType>::accessor( + &self.0, + &TestImport::FIELD, + ) } } } @@ -119,30 +123,23 @@ impl<'p, T: _p::rpc::Table + 'p> test_import::Builder<'p, T> { #[inline] pub fn field( &mut self, - ) -> _p::AccessorMut< - '_, - 'p, - T, - _p::Struct<__imports::capnp_test_capnp::TestAllTypes>, - > { + ) -> _p::AccessorMut<'_, 'p, T, __imports::capnp_test_capnp::TestAllTypes> { unsafe { - <_p::Struct< - __imports::capnp_test_capnp::TestAllTypes, - > as _p::field::FieldType>::accessor(&mut self.0, &TestImport::FIELD) + <__imports::capnp_test_capnp::TestAllTypes as _p::field::FieldType>::accessor( + &mut self.0, + &TestImport::FIELD, + ) } } #[inline] pub fn into_field( self, - ) -> _p::AccessorOwned< - 'p, - T, - _p::Struct<__imports::capnp_test_capnp::TestAllTypes>, - > { + ) -> _p::AccessorOwned<'p, T, __imports::capnp_test_capnp::TestAllTypes> { unsafe { - <_p::Struct< - __imports::capnp_test_capnp::TestAllTypes, - > as _p::field::FieldType>::accessor(self.0, &TestImport::FIELD) + <__imports::capnp_test_capnp::TestAllTypes as _p::field::FieldType>::accessor( + self.0, + &TestImport::FIELD, + ) } } } diff --git a/tests/src/gen/capnp/test-import2.capnp.rs b/tests/src/gen/capnp/test-import2.capnp.rs index 397df2c..f8e7179 100644 --- a/tests/src/gen/capnp/test-import2.capnp.rs +++ b/tests/src/gen/capnp/test-import2.capnp.rs @@ -89,6 +89,9 @@ impl _p::StructView for TestImport2 { type Reader<'a, T: _p::rpc::Table> = test_import2::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = test_import2::Builder<'a, T>; } +impl _p::ty::TypeKind for TestImport2 { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for TestImport2 { const SIZE: _p::StructSize = _p::StructSize { data: 0u16, @@ -96,43 +99,40 @@ impl _p::ty::Struct for TestImport2 { }; } impl TestImport2 { - const FOO: _p::Descriptor<_p::Struct<__imports::capnp_test_capnp::TestAllTypes>> = _p::Descriptor::< - _p::Struct<__imports::capnp_test_capnp::TestAllTypes>, + const FOO: _p::Descriptor<__imports::capnp_test_capnp::TestAllTypes> = _p::Descriptor::< + __imports::capnp_test_capnp::TestAllTypes, > { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }; - const BAR: _p::Descriptor< - _p::Struct<__imports::capnp_test_import_capnp::TestImport>, - > = _p::Descriptor::<_p::Struct<__imports::capnp_test_import_capnp::TestImport>> { + const BAR: _p::Descriptor<__imports::capnp_test_import_capnp::TestImport> = _p::Descriptor::< + __imports::capnp_test_import_capnp::TestImport, + > { slot: 1u32, - default: _p::StructReader::empty(), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> test_import2::Reader<'p, T> { #[inline] pub fn foo( &self, - ) -> _p::Accessor<'_, 'p, T, _p::Struct<__imports::capnp_test_capnp::TestAllTypes>> { + ) -> _p::Accessor<'_, 'p, T, __imports::capnp_test_capnp::TestAllTypes> { unsafe { - <_p::Struct< - __imports::capnp_test_capnp::TestAllTypes, - > as _p::field::FieldType>::accessor(&self.0, &TestImport2::FOO) + <__imports::capnp_test_capnp::TestAllTypes as _p::field::FieldType>::accessor( + &self.0, + &TestImport2::FOO, + ) } } #[inline] pub fn bar( &self, - ) -> _p::Accessor< - '_, - 'p, - T, - _p::Struct<__imports::capnp_test_import_capnp::TestImport>, - > { + ) -> _p::Accessor<'_, 'p, T, __imports::capnp_test_import_capnp::TestImport> { unsafe { - <_p::Struct< - __imports::capnp_test_import_capnp::TestImport, - > as _p::field::FieldType>::accessor(&self.0, &TestImport2::BAR) + <__imports::capnp_test_import_capnp::TestImport as _p::field::FieldType>::accessor( + &self.0, + &TestImport2::BAR, + ) } } } @@ -140,59 +140,45 @@ impl<'p, T: _p::rpc::Table + 'p> test_import2::Builder<'p, T> { #[inline] pub fn foo( &mut self, - ) -> _p::AccessorMut< - '_, - 'p, - T, - _p::Struct<__imports::capnp_test_capnp::TestAllTypes>, - > { + ) -> _p::AccessorMut<'_, 'p, T, __imports::capnp_test_capnp::TestAllTypes> { unsafe { - <_p::Struct< - __imports::capnp_test_capnp::TestAllTypes, - > as _p::field::FieldType>::accessor(&mut self.0, &TestImport2::FOO) + <__imports::capnp_test_capnp::TestAllTypes as _p::field::FieldType>::accessor( + &mut self.0, + &TestImport2::FOO, + ) } } #[inline] pub fn bar( &mut self, - ) -> _p::AccessorMut< - '_, - 'p, - T, - _p::Struct<__imports::capnp_test_import_capnp::TestImport>, - > { + ) -> _p::AccessorMut<'_, 'p, T, __imports::capnp_test_import_capnp::TestImport> { unsafe { - <_p::Struct< - __imports::capnp_test_import_capnp::TestImport, - > as _p::field::FieldType>::accessor(&mut self.0, &TestImport2::BAR) + <__imports::capnp_test_import_capnp::TestImport as _p::field::FieldType>::accessor( + &mut self.0, + &TestImport2::BAR, + ) } } #[inline] pub fn into_foo( self, - ) -> _p::AccessorOwned< - 'p, - T, - _p::Struct<__imports::capnp_test_capnp::TestAllTypes>, - > { + ) -> _p::AccessorOwned<'p, T, __imports::capnp_test_capnp::TestAllTypes> { unsafe { - <_p::Struct< - __imports::capnp_test_capnp::TestAllTypes, - > as _p::field::FieldType>::accessor(self.0, &TestImport2::FOO) + <__imports::capnp_test_capnp::TestAllTypes as _p::field::FieldType>::accessor( + self.0, + &TestImport2::FOO, + ) } } #[inline] pub fn into_bar( self, - ) -> _p::AccessorOwned< - 'p, - T, - _p::Struct<__imports::capnp_test_import_capnp::TestImport>, - > { + ) -> _p::AccessorOwned<'p, T, __imports::capnp_test_import_capnp::TestImport> { unsafe { - <_p::Struct< - __imports::capnp_test_import_capnp::TestImport, - > as _p::field::FieldType>::accessor(self.0, &TestImport2::BAR) + <__imports::capnp_test_import_capnp::TestImport as _p::field::FieldType>::accessor( + self.0, + &TestImport2::BAR, + ) } } } diff --git a/tests/src/gen/capnp/test.capnp.rs b/tests/src/gen/capnp/test.capnp.rs index ac2da83..7d46e56 100644 --- a/tests/src/gen/capnp/test.capnp.rs +++ b/tests/src/gen/capnp/test.capnp.rs @@ -36,6 +36,9 @@ impl core::convert::From for u16 { value as u16 } } +impl _p::ty::TypeKind for TestEnum { + type Kind = _p::ty::kind::Enum; +} impl _p::ty::Enum for TestEnum {} #[derive(Clone)] pub struct TestAllTypes(T); @@ -125,6 +128,9 @@ impl _p::StructView for TestAllTypes { type Reader<'a, T: _p::rpc::Table> = test_all_types::Reader<'a, T>; type Builder<'a, T: _p::rpc::Table> = test_all_types::Builder<'a, T>; } +impl _p::ty::TypeKind for TestAllTypes { + type Kind = _p::ty::kind::Struct; +} impl _p::ty::Struct for TestAllTypes { const SIZE: _p::StructSize = _p::StructSize { data: 6u16, @@ -179,102 +185,96 @@ impl TestAllTypes { }; const TEXT_FIELD: _p::Descriptor<_p::Text> = _p::Descriptor::<_p::Text> { slot: 0u32, - default: _p::text::Reader::empty(), + default: None, }; const DATA_FIELD: _p::Descriptor<_p::Data> = _p::Descriptor::<_p::Data> { slot: 1u32, - default: _p::data::Reader::empty(), + default: None, }; - const STRUCT_FIELD: _p::Descriptor<_p::Struct> = _p::Descriptor::< - _p::Struct, - > { + const STRUCT_FIELD: _p::Descriptor = _p::Descriptor:: { slot: 2u32, - default: _p::StructReader::empty(), + default: None, }; - const ENUM_FIELD: _p::Descriptor<_p::Enum> = _p::Descriptor::< - _p::Enum, - > { + const ENUM_FIELD: _p::Descriptor = _p::Descriptor:: { slot: 18u32, default: TestEnum::Foo, }; const INTERFACE_FIELD: _p::Descriptor<()> = (); const VOID_LIST: _p::Descriptor<_p::List<()>> = _p::Descriptor::<_p::List<()>> { slot: 3u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::<()>()), + default: None, }; const BOOL_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 4u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const INT8_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 5u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const INT16_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 6u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const INT32_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 7u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const INT64_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 8u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const U_INT8_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 9u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const U_INT16_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 10u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const U_INT32_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 11u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const U_INT64_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 12u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const FLOAT32_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 13u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const FLOAT64_LIST: _p::Descriptor<_p::List> = _p::Descriptor::<_p::List> { slot: 14u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::()), + default: None, }; const TEXT_LIST: _p::Descriptor<_p::List<_p::Text>> = _p::Descriptor::< _p::List<_p::Text>, > { slot: 15u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::<_p::Text>()), + default: None, }; const DATA_LIST: _p::Descriptor<_p::List<_p::Data>> = _p::Descriptor::< _p::List<_p::Data>, > { slot: 16u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::<_p::Data>()), + default: None, }; - const STRUCT_LIST: _p::Descriptor<_p::List<_p::Struct>> = _p::Descriptor::< - _p::List<_p::Struct>, + const STRUCT_LIST: _p::Descriptor<_p::List> = _p::Descriptor::< + _p::List, > { slot: 17u32, - default: _p::ListReader::empty( - _p::ElementSize::size_of::<_p::Struct>(), - ), + default: None, }; - const ENUM_LIST: _p::Descriptor<_p::List<_p::Enum>> = _p::Descriptor::< - _p::List<_p::Enum>, + const ENUM_LIST: _p::Descriptor<_p::List> = _p::Descriptor::< + _p::List, > { slot: 18u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::<_p::Enum>()), + default: None, }; const INTERFACE_LIST: _p::Descriptor<_p::List<()>> = _p::Descriptor::<_p::List<()>> { slot: 19u32, - default: _p::ListReader::empty(_p::ElementSize::size_of::<()>()), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> test_all_types::Reader<'p, T> { @@ -384,19 +384,21 @@ impl<'p, T: _p::rpc::Table + 'p> test_all_types::Reader<'p, T> { } } #[inline] - pub fn struct_field(&self) -> _p::Accessor<'_, 'p, T, _p::Struct> { + pub fn struct_field(&self) -> _p::Accessor<'_, 'p, T, TestAllTypes> { unsafe { - <_p::Struct< - TestAllTypes, - > as _p::field::FieldType>::accessor(&self.0, &TestAllTypes::STRUCT_FIELD) + ::accessor( + &self.0, + &TestAllTypes::STRUCT_FIELD, + ) } } #[inline] - pub fn enum_field(&self) -> _p::Accessor<'_, 'p, T, _p::Enum> { + pub fn enum_field(&self) -> _p::Accessor<'_, 'p, T, TestEnum> { unsafe { - <_p::Enum< - TestEnum, - > as _p::field::FieldType>::accessor(&self.0, &TestAllTypes::ENUM_FIELD) + ::accessor( + &self.0, + &TestAllTypes::ENUM_FIELD, + ) } } #[inline] @@ -521,20 +523,18 @@ impl<'p, T: _p::rpc::Table + 'p> test_all_types::Reader<'p, T> { } } #[inline] - pub fn struct_list( - &self, - ) -> _p::Accessor<'_, 'p, T, _p::List<_p::Struct>> { + pub fn struct_list(&self) -> _p::Accessor<'_, 'p, T, _p::List> { unsafe { <_p::List< - _p::Struct, + TestAllTypes, > as _p::field::FieldType>::accessor(&self.0, &TestAllTypes::STRUCT_LIST) } } #[inline] - pub fn enum_list(&self) -> _p::Accessor<'_, 'p, T, _p::List<_p::Enum>> { + pub fn enum_list(&self) -> _p::Accessor<'_, 'p, T, _p::List> { unsafe { <_p::List< - _p::Enum, + TestEnum, > as _p::field::FieldType>::accessor(&self.0, &TestAllTypes::ENUM_LIST) } } @@ -675,24 +675,21 @@ impl<'p, T: _p::rpc::Table + 'p> test_all_types::Builder<'p, T> { } } #[inline] - pub fn struct_field( - &mut self, - ) -> _p::AccessorMut<'_, 'p, T, _p::Struct> { + pub fn struct_field(&mut self) -> _p::AccessorMut<'_, 'p, T, TestAllTypes> { unsafe { - <_p::Struct< - TestAllTypes, - > as _p::field::FieldType>::accessor( + ::accessor( &mut self.0, &TestAllTypes::STRUCT_FIELD, ) } } #[inline] - pub fn enum_field(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::Enum> { + pub fn enum_field(&mut self) -> _p::AccessorMut<'_, 'p, T, TestEnum> { unsafe { - <_p::Enum< - TestEnum, - > as _p::field::FieldType>::accessor(&mut self.0, &TestAllTypes::ENUM_FIELD) + ::accessor( + &mut self.0, + &TestAllTypes::ENUM_FIELD, + ) } } #[inline] @@ -832,22 +829,18 @@ impl<'p, T: _p::rpc::Table + 'p> test_all_types::Builder<'p, T> { } } #[inline] - pub fn struct_list( - &mut self, - ) -> _p::AccessorMut<'_, 'p, T, _p::List<_p::Struct>> { + pub fn struct_list(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::List> { unsafe { <_p::List< - _p::Struct, + TestAllTypes, > as _p::field::FieldType>::accessor(&mut self.0, &TestAllTypes::STRUCT_LIST) } } #[inline] - pub fn enum_list( - &mut self, - ) -> _p::AccessorMut<'_, 'p, T, _p::List<_p::Enum>> { + pub fn enum_list(&mut self) -> _p::AccessorMut<'_, 'p, T, _p::List> { unsafe { <_p::List< - _p::Enum, + TestEnum, > as _p::field::FieldType>::accessor(&mut self.0, &TestAllTypes::ENUM_LIST) } } @@ -881,13 +874,12 @@ impl<'p, T: _p::rpc::Table + 'p> test_all_types::Builder<'p, T> { } } #[inline] - pub fn into_struct_field( - self, - ) -> _p::AccessorOwned<'p, T, _p::Struct> { + pub fn into_struct_field(self) -> _p::AccessorOwned<'p, T, TestAllTypes> { unsafe { - <_p::Struct< - TestAllTypes, - > as _p::field::FieldType>::accessor(self.0, &TestAllTypes::STRUCT_FIELD) + ::accessor( + self.0, + &TestAllTypes::STRUCT_FIELD, + ) } } #[inline] @@ -1003,22 +995,18 @@ impl<'p, T: _p::rpc::Table + 'p> test_all_types::Builder<'p, T> { } } #[inline] - pub fn into_struct_list( - self, - ) -> _p::AccessorOwned<'p, T, _p::List<_p::Struct>> { + pub fn into_struct_list(self) -> _p::AccessorOwned<'p, T, _p::List> { unsafe { <_p::List< - _p::Struct, + TestAllTypes, > as _p::field::FieldType>::accessor(self.0, &TestAllTypes::STRUCT_LIST) } } #[inline] - pub fn into_enum_list( - self, - ) -> _p::AccessorOwned<'p, T, _p::List<_p::Enum>> { + pub fn into_enum_list(self) -> _p::AccessorOwned<'p, T, _p::List> { unsafe { <_p::List< - _p::Enum, + TestEnum, > as _p::field::FieldType>::accessor(self.0, &TestAllTypes::ENUM_LIST) } }