diff --git a/recapn-rpc/src/gen/capnp/rpc.capnp.rs b/recapn-rpc/src/gen/capnp/rpc.capnp.rs index e87832e..81f75d2 100644 --- a/recapn-rpc/src/gen/capnp/rpc.capnp.rs +++ b/recapn-rpc/src/gen/capnp/rpc.capnp.rs @@ -105,7 +105,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const ABORT: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -117,7 +117,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const CALL: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -129,7 +129,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const RETURN: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -141,7 +141,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const FINISH: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -153,7 +153,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const RESOLVE: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -165,7 +165,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const RELEASE: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -177,7 +177,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const OBSOLETE_SAVE: _p::VariantDescriptor<_p::AnyPtr> = _p::VariantDescriptor::< @@ -189,7 +189,7 @@ impl Message { }, field: _p::Descriptor::<_p::AnyPtr> { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }, }; const BOOTSTRAP: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -201,7 +201,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const OBSOLETE_DELETE: _p::VariantDescriptor<_p::AnyPtr> = _p::VariantDescriptor::< @@ -213,7 +213,7 @@ impl Message { }, field: _p::Descriptor::<_p::AnyPtr> { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }, }; const PROVIDE: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -225,7 +225,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const ACCEPT: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -237,7 +237,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const JOIN: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -249,7 +249,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const DISEMBARGO: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -261,7 +261,7 @@ impl Message { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; } @@ -1084,7 +1084,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> { @@ -1240,7 +1240,7 @@ impl Call { _p::Struct, > { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }; const INTERFACE_ID: _p::Descriptor = _p::Descriptor:: { slot: 1u32, @@ -1254,7 +1254,7 @@ impl Call { _p::Struct, > { slot: 1u32, - default: _p::StructReader::empty(), + default: None, }; const SEND_RESULTS_TO: _p::Descriptor<_p::Group> = (); const ALLOW_THIRD_PARTY_TAIL_CALL: _p::Descriptor = _p::Descriptor:: { @@ -1560,7 +1560,7 @@ pub mod call { }, field: _p::Descriptor::<_p::AnyPtr> { slot: 2u32, - default: _p::ptr::PtrReader::null(), + default: None, }, }; } @@ -1850,7 +1850,7 @@ impl Return { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const EXCEPTION: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -1862,7 +1862,7 @@ impl Return { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const CANCELED: _p::VariantDescriptor<()> = _p::VariantDescriptor::<()> { @@ -1902,7 +1902,7 @@ impl Return { }, field: _p::Descriptor::<_p::AnyPtr> { slot: 0u32, - default: _p::ptr::PtrReader::null(), + default: None, }, }; } @@ -2491,7 +2491,7 @@ impl Resolve { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const EXCEPTION: _p::VariantDescriptor<_p::Struct> = _p::VariantDescriptor::< @@ -2503,7 +2503,7 @@ impl Resolve { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; } @@ -2890,7 +2890,7 @@ impl Disembargo { _p::Struct, > { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }; const CONTEXT: _p::Descriptor<_p::Group> = (); } @@ -3387,11 +3387,11 @@ impl Provide { _p::Struct, > { 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> { @@ -3561,7 +3561,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, @@ -3721,11 +3721,11 @@ impl Join { _p::Struct, > { 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> { @@ -3903,7 +3903,7 @@ impl MessageTarget { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; } @@ -4142,15 +4142,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>, > { 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> { @@ -4358,7 +4356,7 @@ impl CapDescriptor { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; const THIRD_PARTY_HOSTED: _p::VariantDescriptor< @@ -4370,7 +4368,7 @@ impl CapDescriptor { }, field: _p::Descriptor::<_p::Struct> { slot: 0u32, - default: _p::StructReader::empty(), + default: None, }, }; } @@ -4806,9 +4804,7 @@ impl PromisedAnswer { _p::List<_p::Struct>, > { 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> { @@ -5205,7 +5201,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, @@ -5367,7 +5363,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, @@ -5385,7 +5381,7 @@ impl Exception { }; 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> { diff --git a/recapn/src/any.rs b/recapn/src/any.rs index d3d5c17..29c74d0 100644 --- a/recapn/src/any.rs +++ b/recapn/src/any.rs @@ -92,10 +92,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; } @@ -583,10 +579,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,9 +892,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; } diff --git a/recapn/src/data.rs b/recapn/src/data.rs index 4476cda..9d69148 100644 --- a/recapn/src/data.rs +++ b/recapn/src/data.rs @@ -22,9 +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; } diff --git a/recapn/src/field.rs b/recapn/src/field.rs index cfb0b8b..e0e76a4 100644 --- a/recapn/src/field.rs +++ b/recapn/src/field.rs @@ -37,7 +37,7 @@ //! lifetimes respectively. So `&'b ptr::StructReader<'p, T>` could be extended to //! `&'borrow ptr::StructReader<'pointer, T>`. -use core::convert::TryFrom; +use core::convert::{TryFrom, Infallible as Never}; use core::marker::PhantomData; use core::str::Utf8Error; @@ -272,9 +272,24 @@ pub type VariantMut<'b, 'p, T, V> = ::VariantAccessor = ::VariantAccessor>; +/// A trait used to specify that a type is used to represent a Cap'n Proto value. +pub trait Value: 'static { + type Default; +} + +/// A trait used to specify that a type is backed by a pointer field. This enables generic pointers +/// in generated code. +pub trait PtrValue: 'static { + type Default; +} + +impl Value for T { + type Default = Option<::Default>; +} + /// Describes a value in a "slot" in a struct. This does not include groups or void, which don't /// have an associated default value or slot. -pub struct FieldInfo { +pub struct FieldInfo { pub slot: u32, pub default: V::Default, } @@ -304,7 +319,7 @@ pub struct Struct { } impl Sealed for Struct {} -impl ty::Value for Struct { +impl PtrValue for Struct { type Default = ptr::StructReader<'static>; } impl ListValue for Struct { @@ -339,9 +354,9 @@ pub struct Capability { } impl Sealed for Capability {} -impl ty::Value for Capability { +impl PtrValue for Capability { /// Capabilities don't have defaults - type Default = (); + type Default = Never; } impl ListValue for Capability { const ELEMENT_SIZE: ElementSize = ElementSize::Pointer; @@ -353,7 +368,7 @@ pub struct Enum { } impl Sealed for Enum {} -impl ty::Value for Enum { +impl Value for Enum { type Default = E; } impl ListValue for Enum { @@ -454,7 +469,7 @@ impl<'b, 'p, T: Table, G: FieldGroup> VoidVariant, StructBuilder<'b, 'p } } -pub struct DataField { +pub struct DataField { descriptor: &'static FieldInfo, repr: Repr, } @@ -471,7 +486,7 @@ impl<'b, 'p, T: Table, D: Data> DataField> { } } -pub struct DataVariant { +pub struct DataVariant { descriptor: &'static FieldInfo, variant: &'static VariantInfo, repr: Repr, @@ -641,7 +656,7 @@ impl<'b, 'p, T: Table, E: ty::Enum> DataVariant, StructBuilder<'b, 'p, T } } -pub struct PtrField { +pub struct PtrField { descriptor: &'static FieldInfo, repr: Repr, } @@ -650,7 +665,7 @@ pub type PtrFieldReader<'b, 'p, T, V> = PtrField>; pub type PtrFieldBuilder<'b, 'p, T, V> = PtrField>; pub type PtrFieldOwner<'p, T, V> = PtrField>; -impl<'b, 'p, T: Table, V: ty::Value> PtrFieldReader<'b, 'p, T, V> { +impl<'b, 'p, T: Table, V: PtrValue> PtrFieldReader<'b, 'p, T, V> { #[inline] fn raw_ptr(&self) -> ptr::PtrReader<'p, T> { self.repr.ptr_field(self.descriptor.slot as u16) @@ -667,7 +682,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> { +impl<'b, 'p, T: Table, V: PtrValue> 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] @@ -725,7 +740,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> { +impl<'p, T: Table, V: PtrValue> 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] @@ -784,7 +799,7 @@ impl<'p, T: Table, V: ty::Value> PtrFieldOwner<'p, T, V> { } /// A base type for accessing union variant fields. -pub struct PtrVariant { +pub struct PtrVariant { descriptor: &'static FieldInfo, variant: &'static VariantInfo, repr: Repr, @@ -794,7 +809,7 @@ 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> { +impl<'b, 'p, T: Table, V: PtrValue> 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 { @@ -803,8 +818,12 @@ impl<'b, 'p, T: Table, V: ty::Value> PtrVariantReader<'b, 'p, T, V> { } #[inline] - fn raw_ptr(&self) -> Option> { - self.is_set().then(|| self.repr.ptr_field(self.descriptor.slot as u16)) + fn raw_ptr_or_null(&self) -> ptr::PtrReader<'b, T> { + if self.is_set() { + self.repr.ptr_field(self.descriptor.slot as u16) + } else { + ptr::PtrReader::null().imbue_from(self.repr) + } } #[inline] @@ -822,7 +841,7 @@ 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> { +impl<'b, 'p, T: Table, V: PtrValue> 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 { @@ -907,7 +926,7 @@ impl<'b, 'p, T: Table, V: ty::Value> PtrVariantBuilder<'b, 'p, T, V> { } } -impl<'p, T: Table, V: ty::Value> PtrVariantOwner<'p, T, V> { +impl<'p, T: Table, V: PtrValue> PtrVariantOwner<'p, T, V> { /// Returns a bool indicating whether or not this field is set in the union #[inline] pub fn is_set(&self) -> bool { @@ -942,6 +961,10 @@ macro_rules! field_type_items { // impls for list +impl PtrValue for List { + type Default = ptr::ListReader<'static>; +} + impl FieldType for List { field_type_items!{} } @@ -952,10 +975,14 @@ where { #[inline] fn default(&self) -> list::Reader<'static, V, T> { - let default = &self.descriptor.default; - assert!(default.element_size().upgradable_to(V::PTR_ELEMENT_SIZE)); + match &self.descriptor.default { + Some(default) => { + debug_assert!(default.element_size().upgradable_to(V::PTR_ELEMENT_SIZE)); - List::new(default.clone().imbue_from(self.repr)) + List::new(default.clone().imbue_from(self.repr)) + } + None => List::empty().imbue_from(self.repr) + } } #[inline] @@ -1017,10 +1044,14 @@ 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)); + match &self.descriptor.default { + Some(default) => { + debug_assert!(default.element_size().upgradable_to(V::PTR_ELEMENT_SIZE)); - List::new(default.clone().imbue_from(self.repr)) + List::new(default.clone().imbue_from(self.repr)) + } + None => List::empty().imbue_from(self.repr) + } } #[inline] @@ -1060,9 +1091,14 @@ 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 { + debug_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(); + new_list + } else { + ptr.init_list(V::ELEMENT_SIZE, ElementCount::ZERO) + }; List::new(new_list) } } @@ -1124,7 +1160,7 @@ impl<'b, 'p, T: Table> PtrFieldBuilder<'b, 'p, T, List> { .to_list_mut(expected_size.map(ElementSize::InlineComposite)) { Ok(ptr) => ptr, - Err((_, ptr)) => { + Err((_, ptr)) => if let Some(default) = default { let default_size = default.element_size(); let size = match expected_size { Some(e) => { @@ -1137,6 +1173,9 @@ impl<'b, 'p, T: Table> PtrFieldBuilder<'b, 'p, T, List> { let mut builder = ptr.init_list(size, default.len()); builder.try_copy_from(default, UnwrapErrors).unwrap(); builder + } else { + let s = ElementSize::InlineComposite(expected_size.unwrap_or(StructSize::EMPTY)); + ptr.init_list(s, ElementCount::ZERO) } }; List::new(ptr) @@ -1165,7 +1204,7 @@ impl FieldType for Struct { impl PtrField, Repr> { #[inline] fn default_ptr(&self) -> ptr::StructReader<'static> { - self.descriptor.default.clone() + self.descriptor.default.clone().unwrap_or_else(ptr::StructReader::empty) } /// Returns the default value of the field @@ -1229,7 +1268,9 @@ where Ok(ptr) => ptr, Err((_, ptr)) => { let mut builder = ptr.init_struct(S::SIZE); - builder.copy_with_caveats(default, false); + if let Some(default) = default { + builder.copy_with_caveats(default, false); + } builder } }; @@ -1275,21 +1316,39 @@ where } } +impl PtrVariant, Repr> { + #[inline] + fn default_ptr(&self) -> ptr::StructReader<'static> { + self.descriptor.default.clone().unwrap_or_else(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: '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_ptr(&self) -> ptr::StructReader<'static, T> { + self.descriptor + .default + .clone() + .unwrap_or_else(ptr::StructReader::empty) + .imbue_from(self.repr) } #[inline] pub fn get_or_default(&self) -> S::Reader<'b, T> { - self.try_get_option() - .ok() - .flatten() - .unwrap_or_else(|| self.default()) + let ptr = match self.raw_ptr_or_null().to_struct() { + Ok(Some(ptr)) => ptr, + _ => self.default_imbued_ptr(), + }; + ty::StructReader::from_ptr(ptr) } #[inline] @@ -1299,8 +1358,12 @@ where #[inline] pub fn try_get(&self) -> Result> { - self.try_get_option() - .map(|op| op.unwrap_or_else(|| self.default())) + 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] @@ -1353,6 +1416,10 @@ where } } +impl PtrValue for text::Text { + type Default = text::Reader<'static>; +} + impl FieldType for text::Text { field_type_items!{} } @@ -1361,7 +1428,7 @@ impl PtrField { /// Returns the default value of the field #[inline] pub fn default(&self) -> text::Reader<'static> { - self.descriptor.default + self.descriptor.default.unwrap_or_else(text::Reader::empty) } } @@ -1412,7 +1479,7 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrFieldBuilder<'b, 'p, T, text::Text> { /// existing value, the default is set instead. #[inline] pub fn get(self) -> text::Builder<'b> { - let default = self.descriptor.default; + let default = self.descriptor.default.unwrap_or_else(text::Reader::empty); let blob = match self.into_raw_build_ptr().to_blob_mut() { Ok(b) => b, Err((_, ptr)) => ptr.set_blob(default.into()), @@ -1475,6 +1542,10 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrVariantBuilder<'b, 'p, T, text::Text> { } +impl PtrValue for data::Data { + type Default = data::Reader<'static>; +} + impl FieldType for data::Data { field_type_items!{} } @@ -1483,7 +1554,7 @@ impl PtrField { /// Returns the default value of the field #[inline] pub fn default(&self) -> data::Reader<'static> { - self.descriptor.default.clone().into() + self.descriptor.default.unwrap_or_else(data::Reader::empty) } } @@ -1519,7 +1590,7 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrFieldBuilder<'b, 'p, T, data::Data> { /// existing value, the default is set instead. #[inline] pub fn get(self) -> data::Builder<'b> { - let default = self.descriptor.default; + let default = self.descriptor.default.unwrap_or_else(data::Reader::empty); match self.into_raw_build_ptr().to_blob_mut() { Ok(data) => data, Err((_, ptr)) => ptr.set_blob(default.into()), @@ -1570,6 +1641,10 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrVariantBuilder<'b, 'p, T, data::Data> { // TODO accessors } +impl PtrValue for AnyPtr { + type Default = ptr::PtrReader<'static, Empty>; +} + impl FieldType for AnyPtr { field_type_items!(); } @@ -1582,6 +1657,10 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrVariantBuilder<'b, 'p, T, AnyPtr> { // TODO accessors } +impl PtrValue for AnyStruct { + type Default = ptr::StructReader<'static, Empty>; +} + impl FieldType for AnyStruct { field_type_items!{} } @@ -1590,7 +1669,7 @@ impl PtrField { /// 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_else(ptr::StructReader::empty) } /// Returns the default value of the field @@ -1644,6 +1723,10 @@ impl<'b, 'p: 'b, T: Table + 'p> PtrVariantBuilder<'b, 'p, T, AnyStruct> { // TODO accessors } +impl PtrValue for AnyList { + type Default = ptr::ListReader<'static, Empty>; +} + impl FieldType for AnyList { field_type_items!{} } @@ -1652,7 +1735,10 @@ 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_else(|| ptr::ListReader::empty(ElementSize::Void)) } /// Returns the default value of the field diff --git a/recapn/src/ptr.rs b/recapn/src/ptr.rs index 66480ea..387eca5 100644 --- a/recapn/src/ptr.rs +++ b/recapn/src/ptr.rs @@ -4,6 +4,7 @@ use crate::alloc::{ AllocLen, Segment, SegmentLen, SegmentOffset, SegmentPtr, SegmentRef, SignedSegmentOffset, Word }; use crate::arena::{SegmentId, SegmentWithId, ReadArena, BuildArena, ArenaSegment}; +use crate::field; use crate::internal::Sealed; use crate::message::ReadLimiter; use crate::num::u29; @@ -25,7 +26,7 @@ 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: field::Value + ty::ListValue + Default + Copy + Sealed + 'static { 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; diff --git a/recapn/src/text.rs b/recapn/src/text.rs index 16a500d..36df54f 100644 --- a/recapn/src/text.rs +++ b/recapn/src/text.rs @@ -38,9 +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; } diff --git a/recapn/src/ty.rs b/recapn/src/ty.rs index 8c41a29..84d1e58 100644 --- a/recapn/src/ty.rs +++ b/recapn/src/ty.rs @@ -200,11 +200,6 @@ impl<'a, S: Struct, T: Table> ReadPtr> for field::Struct DynListValue for T { @@ -241,7 +236,7 @@ pub type Float64 = f64; macro_rules! impl_value { ($ty:ty, $size:ident) => { impl Sealed for $ty {} - impl Value for $ty { + impl field::Value for $ty { type Default = Self; } impl ListValue for $ty { @@ -263,9 +258,6 @@ 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; } diff --git a/recapnc/src/gen/capnp/schema.capnp.rs b/recapnc/src/gen/capnp/schema.capnp.rs index f693e14..b28beb8 100644 --- a/recapnc/src/gen/capnp/schema.capnp.rs +++ b/recapnc/src/gen/capnp/schema.capnp.rs @@ -10,18 +10,18 @@ _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() + 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() + slot: 1, default: None }, ANNOTATIONS, annotations, annotations_mut, _p::List<_p::Struct> = { - slot: 2, default: _p::eslpr() + slot: 2, default: None }, }, union { @@ -48,7 +48,7 @@ _p::generate_file! { 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() + slot: 3, default: None }, }, }, @@ -56,7 +56,7 @@ _p::generate_file! { mod: r#enum, fields: { ENUMERANTS, enumerants, enumerants_mut, _p::List<_p::Struct<__file::Enumerant>> = { - slot: 3, default: _p::eslpr() + slot: 3, default: None }, }, }, @@ -64,24 +64,24 @@ _p::generate_file! { mod: interface, fields: { METHODS, methods, methods_mut, _p::List<_p::Struct<__file::Method>> = { - slot: 3, default: _p::eslpr() + slot: 3, default: None }, SUPERCLASSES, superclasses, superclasses_mut, _p::List<_p::Struct<__file::Superclass>> = { - slot: 4, default: _p::eslpr() + 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, _p::Struct<__file::Type> = { slot: 3, default: None }, + VALUE, value, value_mut, _p::Struct<__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, _p::Struct<__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() }, + DOC_COMMENT, doc_comment, doc_comment_mut, _p::Text = { slot: 0, default: None }, MEMBERS, members, members_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + 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,10 +137,10 @@ _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() + slot: 1, default: None }, DISCRIMINANT_VALUE, discriminant_value, discriminant_value_mut, u16 = { slot: 1, default: 65535 }, ORDINAL, ordinal, ordinal_mut, _p::Group = (), @@ -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, _p::Struct<__file::Type> = { slot: 2, default: None }, + DEFAULT_VALUE, default_value, default_value_mut, _p::Struct<__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() + slot: 1, default: None }, }, }, @@ -198,7 +198,7 @@ _p::generate_file! { fields: { ID, id, id_mut, u64 = { slot: 0, default: 0 }, BRAND, brand, brand_mut, _p::List<_p::Struct> = { - slot: 0, default: _p::eslpr() + 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() + 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, _p::Struct = { 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() }, + RESULT_BRAND, result_brand, result_brand_mut, _p::Struct = { slot: 3, default: None }, ANNOTATIONS, annotations, annotations_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + slot: 1, default: None }, }, }, @@ -252,28 +252,28 @@ _p::generate_file! { 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, _p::Struct<__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, _p::Struct<__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, _p::Struct<__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, _p::Struct<__file::Brand> = { slot: 0, default: None }, }, }, group AnyPointer { @@ -323,7 +323,7 @@ _p::generate_file! { size: { data: 0, ptrs: 1 }, fields: { SCOPES, scopes, scopes_mut, _p::List<_p::Struct<__file::brand::Scope>> = { - slot: 0, default: _p::eslpr() + slot: 0, default: None } }, nested: { @@ -337,7 +337,7 @@ _p::generate_file! { tag_slot: 4, fields: { BIND, Bind, bind, bind_mut, _p::List<_p::Struct<__file::brand::Binding>> = { - case: 0, slot: 0, default: _p::eslpr() + 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, _p::Struct<__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 }, }, }, }, @@ -392,9 +392,9 @@ _p::generate_file! { fields: { ID, id, id_mut, u64 = { slot: 0, default: 0 }, BRAND, brand, brand_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + slot: 1, default: None }, - VALUE, value, value_mut, _p::Struct<__file::Value> = { slot: 0, default: _p::StructReader::empty() }, + VALUE, value, value_mut, _p::Struct<__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() }, + CAPNP_VERSION, capnp_version, capnp_version_mut, _p::Struct = { slot: 2, default: None }, NODES, nodes, nodes_mut, _p::List<_p::Struct> = { - slot: 0, default: _p::eslpr() + slot: 0, default: None }, SOURCE_INFO, source_info, source_info_mut, _p::List<_p::Struct> = { - slot: 3, default: _p::eslpr() + slot: 3, default: None }, REQUESTED_FILES, requested_files, requested_files_mut, _p::List<_p::Struct> = { - slot: 1, default: _p::eslpr() + 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() }, + FILENAME, filename, filename_mut, _p::Text = { slot: 0, default: None }, IMPORTS, imports, imports_mut, _p::List<_p::Struct<__file::code_generator_request::requested_file::Import>> = { - slot: 1, default: _p::eslpr() + 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 }, }, }, }, diff --git a/recapnc/src/generator.rs b/recapnc/src/generator.rs index a4dc562..d272d72 100644 --- a/recapnc/src/generator.rs +++ b/recapnc/src/generator.rs @@ -590,7 +590,7 @@ impl<'a> GeneratorContext<'a> { quote!(_p::text::Reader::from_slice(#bytes)) } - _ => quote!(_p::text::Reader::empty()), + _ => quote!(None), } } TypeKind::Data(()) => { @@ -603,7 +603,7 @@ impl<'a> GeneratorContext<'a> { quote!(_p::data::Reader::from_slice(#bytes)) } - _ => quote!(_p::data::Reader::empty()), + _ => quote!(None), } } TypeKind::List(list) => { @@ -625,7 +625,7 @@ impl<'a> GeneratorContext<'a> { quote!(_p::ListReader::slice_unchecked(#words, #len, #element_size_quote)) } - _ => quote!(_p::ListReader::empty(#element_size_quote)), + _ => quote!(None), } } TypeKind::Enum(info) => { @@ -656,12 +656,10 @@ impl<'a> GeneratorContext<'a> { quote!(_p::StructReader::slice_unchecked(#words, #size)) } - _ => quote!(_p::StructReader::empty()), + _ => quote!(None), } } - TypeKind::Interface(_) => { - unimplemented!("cannot generate values for Capability fields") - } + TypeKind::Interface(_) => quote!(None), TypeKind::AnyPointer(kind) => { let ptr = value.and_then(|v| v.any_pointer().field()) .map(|p| p.ptr()).filter(|p| !p.is_null()); @@ -673,7 +671,7 @@ impl<'a> GeneratorContext<'a> { quote!(_p::PtrReader::slice_unchecked(#words)) } else { - quote!(_p::PtrReader::null()) + quote!(None) } ConstraintKind::Struct(_) => if let Some(ptr) = ptr { let reader = ptr.try_read_as::() @@ -685,7 +683,7 @@ impl<'a> GeneratorContext<'a> { quote!(_p::StructReader::slice_unchecked(#words, #size)) } else { - quote!(_p::StructReader::empty()) + quote!(None) } ConstraintKind::List(_) => if let Some(ptr) = ptr { let reader = ptr.try_read_as::() @@ -697,9 +695,9 @@ impl<'a> GeneratorContext<'a> { quote!(_p::ListReader::slice_unchecked(#words, #len, #size_quote)) } else { - quote!(_p::ListReader::empty()) + quote!(None) } - ConstraintKind::Capability(_) => quote!(()), + ConstraintKind::Capability(_) => quote!(None), }, AnyPtrKind::Parameter(_) => todo!("generate default values for generic types"), _ => unreachable!(), diff --git a/tests/src/gen/capnp/test-import.capnp.rs b/tests/src/gen/capnp/test-import.capnp.rs index 6ae1440..1b8ae77 100644 --- a/tests/src/gen/capnp/test-import.capnp.rs +++ b/tests/src/gen/capnp/test-import.capnp.rs @@ -100,7 +100,7 @@ impl TestImport { _p::Struct<__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> { diff --git a/tests/src/gen/capnp/test-import2.capnp.rs b/tests/src/gen/capnp/test-import2.capnp.rs index 397df2c..a6321ed 100644 --- a/tests/src/gen/capnp/test-import2.capnp.rs +++ b/tests/src/gen/capnp/test-import2.capnp.rs @@ -100,13 +100,13 @@ impl TestImport2 { _p::Struct<__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>> { slot: 1u32, - default: _p::StructReader::empty(), + default: None, }; } impl<'p, T: _p::rpc::Table + 'p> test_import2::Reader<'p, T> { diff --git a/tests/src/gen/capnp/test.capnp.rs b/tests/src/gen/capnp/test.capnp.rs index ac2da83..142b582 100644 --- a/tests/src/gen/capnp/test.capnp.rs +++ b/tests/src/gen/capnp/test.capnp.rs @@ -179,17 +179,17 @@ 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, > { slot: 2u32, - default: _p::StructReader::empty(), + default: None, }; const ENUM_FIELD: _p::Descriptor<_p::Enum> = _p::Descriptor::< _p::Enum, @@ -200,81 +200,79 @@ impl TestAllTypes { 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>, > { 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>, > { 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> {