diff --git a/src/generated.rs b/src/generated.rs index 652f8a124..fd12b4ee6 100644 --- a/src/generated.rs +++ b/src/generated.rs @@ -503,7 +503,7 @@ impl Iterator for ReadXdrIter { Err(e) => return Some(Err(Error::Io(e))), // If there is data in the buf available for reading, continue. Ok([..]) => (), - }; + } // Read the buf into the type. let r = self.reader.with_limited_depth(|dlr| S::read_xdr(dlr)); match r { @@ -939,6 +939,16 @@ impl WriteXdr for Box { } } +// Gated on alloc because in no-alloc builds `Box` is an alias for +// `&'static T`, and this impl would overlap with the `Box` impl above. +#[cfg(feature = "alloc")] +impl WriteXdr for &T { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + T::write_xdr(self, w) + } +} + impl ReadXdr for () { #[cfg(feature = "std")] fn read_xdr(_r: &mut Limited) -> Result { @@ -1533,6 +1543,178 @@ impl WriteXdr for VecM { } } +// VecMView ------------------------------------------------------------------------ + +/// A borrowing equivalent of [`VecM`] that wraps a slice instead of owning a +/// `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of the generated `View` types from +/// slices of fixed-size arrays, without heap allocation. +#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct VecMView<'a, T, const MAX: u32 = { u32::MAX }>(&'a [T]); + +// Copy and Clone are implemented manually because the derived impls would +// require `T: Copy`/`T: Clone`, and the wrapped `&[T]` is copyable for any +// `T`. +impl Copy for VecMView<'_, T, MAX> {} + +#[allow(clippy::expl_impl_clone_on_copy)] +impl Clone for VecMView<'_, T, MAX> { + fn clone(&self) -> Self { + *self + } +} + +impl Deref for VecMView<'_, T, MAX> { + type Target = [T]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for VecMView<'_, T, MAX> { + fn default() -> Self { + Self(&[]) + } +} + +impl<'a, T, const MAX: u32> VecMView<'a, T, MAX> { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `VecMView` from the given slice. + /// + /// ### Panics + /// + /// Panics if the length of the slice exceeds `MAX`. In a const context + /// the panic occurs at compile time. + #[must_use] + pub const fn new(v: &'a [T]) -> Self { + assert!(v.len() <= Self::MAX_LEN, "length exceeds max"); + Self(v) + } + + /// Constructs a `VecMView` from the given slice, erroring if the length of + /// the slice exceeds `MAX`. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_new(v: &'a [T]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(Error::LengthExceedsMax) + } + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'a [T] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } + + pub fn iter(&self) -> slice::Iter<'a, T> { + self.0.iter() + } +} + +impl<'a, T, const MAX: u32> core::iter::IntoIterator for &VecMView<'a, T, MAX> { + type Item = &'a T; + type IntoIter = slice::Iter<'a, T>; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +#[cfg(feature = "alloc")] +impl VecMView<'_, T, MAX> { + /// Converts to an owned [`VecM`], cloning the elements. + #[must_use] + pub fn to_vecm(&self) -> VecM { + VecM(self.0.to_vec()) + } +} + +#[cfg(feature = "alloc")] +impl VecMView<'_, T, MAX> { + /// Converts to an owned [`VecM`], converting each element from its + /// borrowing form to its owned form. + #[must_use] + pub fn to_vecm_from(&self) -> VecM + where + U: for<'r> From<&'r T>, + { + VecM(self.0.iter().map(U::from).collect()) + } +} + +impl<'a, T, const MAX: u32> TryFrom<&'a [T]> for VecMView<'a, T, MAX> { + type Error = Error; + + fn try_from(v: &'a [T]) -> Result { + Self::try_new(v) + } +} + +impl<'a, T, const MAX: u32> From<&'a VecM> for VecMView<'a, T, MAX> { + #[must_use] + fn from(v: &'a VecM) -> Self { + Self( as AsRef<[T]>>::as_ref(v)) + } +} + +impl WriteXdr for VecMView<'_, u8, MAX> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?; + len.write_xdr(w)?; + + w.consume_len(self.len())?; + let padding = pad_len(self.len()); + w.consume_len(padding)?; + + w.write_all(self.0)?; + + w.write_all(&[0u8; 3][..padding])?; + + Ok(()) + }) + } +} + +impl WriteXdr for VecMView<'_, T, MAX> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?; + len.write_xdr(w)?; + + for t in self.0 { + t.write_xdr(w)?; + } + + Ok(()) + }) + } +} + // BytesM ------------------------------------------------------------------------ #[cfg(feature = "alloc")] @@ -1937,6 +2119,145 @@ impl WriteXdr for BytesM { } } +// BytesMView ------------------------------------------------------------------------ + +/// A borrowing equivalent of [`BytesM`] that wraps a byte slice instead of +/// owning a `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of the generated `View` types from +/// slices of fixed-size arrays, without heap allocation. +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct BytesMView<'a, const MAX: u32 = { u32::MAX }>(&'a [u8]); + +impl core::fmt::Display for BytesMView<'_, MAX> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + for b in self.0 { + write!(f, "{b:02x}")?; + } + Ok(()) + } +} + +impl core::fmt::Debug for BytesMView<'_, MAX> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "BytesMView(")?; + for b in self.0 { + write!(f, "{b:02x}")?; + } + write!(f, ")")?; + Ok(()) + } +} + +impl Deref for BytesMView<'_, MAX> { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for BytesMView<'_, MAX> { + fn default() -> Self { + Self(&[]) + } +} + +impl<'a, const MAX: u32> BytesMView<'a, MAX> { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `BytesMView` from the given slice. + /// + /// ### Panics + /// + /// Panics if the length of the slice exceeds `MAX`. In a const context + /// the panic occurs at compile time. + #[must_use] + pub const fn new(v: &'a [u8]) -> Self { + assert!(v.len() <= Self::MAX_LEN, "length exceeds max"); + Self(v) + } + + /// Constructs a `BytesMView` from the given slice, erroring if the length + /// of the slice exceeds `MAX`. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_new(v: &'a [u8]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(Error::LengthExceedsMax) + } + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'a [u8] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +#[cfg(feature = "alloc")] +impl BytesMView<'_, MAX> { + /// Converts to an owned [`BytesM`], cloning the bytes. + #[must_use] + pub fn to_bytesm(&self) -> BytesM { + BytesM(self.0.to_vec()) + } +} + +impl<'a, const MAX: u32> TryFrom<&'a [u8]> for BytesMView<'a, MAX> { + type Error = Error; + + fn try_from(v: &'a [u8]) -> Result { + Self::try_new(v) + } +} + +impl<'a, const MAX: u32> From<&'a BytesM> for BytesMView<'a, MAX> { + #[must_use] + fn from(v: &'a BytesM) -> Self { + Self( as AsRef<[u8]>>::as_ref(v)) + } +} + +impl WriteXdr for BytesMView<'_, MAX> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?; + len.write_xdr(w)?; + + w.consume_len(self.len())?; + let padding = pad_len(self.len()); + w.consume_len(padding)?; + + w.write_all(self.0)?; + + w.write_all(&[0u8; 3][..padding])?; + + Ok(()) + }) + } +} + // StringM ------------------------------------------------------------------------ /// A string type that contains arbitrary bytes. @@ -2340,6 +2661,174 @@ impl WriteXdr for StringM { } } +// StringMView ------------------------------------------------------------------------ + +/// A borrowing equivalent of [`StringM`] that wraps a byte slice instead of +/// owning a `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of the generated `View` types from +/// slices of fixed-size arrays or string literals, without heap allocation. +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct StringMView<'a, const MAX: u32 = { u32::MAX }>(&'a [u8]); + +impl core::fmt::Display for StringMView<'_, MAX> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + for b in escape_bytes::Escape::new(self.0) { + write!(f, "{}", b as char)?; + } + Ok(()) + } +} + +impl core::fmt::Debug for StringMView<'_, MAX> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "StringMView(")?; + for b in escape_bytes::Escape::new(self.0) { + write!(f, "{}", b as char)?; + } + write!(f, ")")?; + Ok(()) + } +} + +impl Deref for StringMView<'_, MAX> { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for StringMView<'_, MAX> { + fn default() -> Self { + Self(&[]) + } +} + +impl<'a, const MAX: u32> StringMView<'a, MAX> { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `StringMView` from the given slice. + /// + /// ### Panics + /// + /// Panics if the length of the slice exceeds `MAX`. In a const context + /// the panic occurs at compile time. + #[must_use] + pub const fn new(v: &'a [u8]) -> Self { + assert!(v.len() <= Self::MAX_LEN, "length exceeds max"); + Self(v) + } + + /// Constructs a `StringMView` from the UTF-8 bytes of the given str. + /// + /// ### Panics + /// + /// Panics if the length of the str exceeds `MAX`. In a const context the + /// panic occurs at compile time. + #[must_use] + pub const fn new_str(s: &'a str) -> Self { + Self::new(s.as_bytes()) + } + + /// Constructs a `StringMView` from the given slice, erroring if the length + /// of the slice exceeds `MAX`. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_new(v: &'a [u8]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(Error::LengthExceedsMax) + } + } + + /// Constructs a `StringMView` from the UTF-8 bytes of the given str, + /// erroring if the length of the str exceeds `MAX`. + /// + /// ### Errors + /// + /// If the length of the str exceeds `MAX`. + pub const fn try_new_str(s: &'a str) -> Result { + Self::try_new(s.as_bytes()) + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'a [u8] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +#[cfg(feature = "alloc")] +impl StringMView<'_, MAX> { + /// Converts to an owned [`StringM`], cloning the bytes. + #[must_use] + pub fn to_stringm(&self) -> StringM { + StringM(self.0.to_vec()) + } +} + +impl<'a, const MAX: u32> TryFrom<&'a [u8]> for StringMView<'a, MAX> { + type Error = Error; + + fn try_from(v: &'a [u8]) -> Result { + Self::try_new(v) + } +} + +impl<'a, const MAX: u32> TryFrom<&'a str> for StringMView<'a, MAX> { + type Error = Error; + + fn try_from(s: &'a str) -> Result { + Self::try_new_str(s) + } +} + +impl<'a, const MAX: u32> From<&'a StringM> for StringMView<'a, MAX> { + #[must_use] + fn from(v: &'a StringM) -> Self { + Self( as AsRef<[u8]>>::as_ref(v)) + } +} + +impl WriteXdr for StringMView<'_, MAX> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?; + len.write_xdr(w)?; + + w.consume_len(self.len())?; + let padding = pad_len(self.len()); + w.consume_len(padding)?; + + w.write_all(self.0)?; + + w.write_all(&[0u8; 3][..padding])?; + + Ok(()) + }) + } +} + // Frame ------------------------------------------------------------------------ /// Frame wraps an XDR object with the framing defined by the Record Marking diff --git a/src/generated/account_entry.rs b/src/generated/account_entry.rs index 805518d99..6c752df76 100644 --- a/src/generated/account_entry.rs +++ b/src/generated/account_entry.rs @@ -100,3 +100,65 @@ impl WriteXdr for AccountEntry { }) } } + +/// AccountEntryView is a borrowing equivalent of [`AccountEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct AccountEntryView<'a> { + pub account_id: AccountId, + pub balance: i64, + pub seq_num: SequenceNumber, + pub num_sub_entries: u32, + pub inflation_dest: Option, + pub flags: u32, + pub home_domain: String32View<'a>, + pub thresholds: Thresholds, + pub signers: VecMView<'a, SignerView<'a>, 20>, + pub ext: AccountEntryExtView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&AccountEntryView<'_>> for AccountEntry { + #[must_use] + fn from(v: &AccountEntryView<'_>) -> Self { + Self { + account_id: v.account_id.clone(), + balance: v.balance, + seq_num: v.seq_num.clone(), + num_sub_entries: v.num_sub_entries, + inflation_dest: v.inflation_dest.clone(), + flags: v.flags, + home_domain: (&v.home_domain).into(), + thresholds: v.thresholds.clone(), + signers: v.signers.to_vecm_from(), + ext: (&v.ext).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for AccountEntry { + #[must_use] + fn from(v: AccountEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for AccountEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.account_id.write_xdr(w)?; + self.balance.write_xdr(w)?; + self.seq_num.write_xdr(w)?; + self.num_sub_entries.write_xdr(w)?; + self.inflation_dest.write_xdr(w)?; + self.flags.write_xdr(w)?; + self.home_domain.write_xdr(w)?; + self.thresholds.write_xdr(w)?; + self.signers.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/account_entry_ext.rs b/src/generated/account_entry_ext.rs index 7a47dbf65..788e30ae7 100644 --- a/src/generated/account_entry_ext.rs +++ b/src/generated/account_entry_ext.rs @@ -135,3 +135,58 @@ impl WriteXdr for AccountEntryExt { }) } } + +/// AccountEntryExtView is a borrowing equivalent of [`AccountEntryExt`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum AccountEntryExtView<'a> { + V0, + V1(AccountEntryExtensionV1View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&AccountEntryExtView<'_>> for AccountEntryExt { + #[must_use] + fn from(v: &AccountEntryExtView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + AccountEntryExtView::V0 => Self::V0, + AccountEntryExtView::V1(value) => Self::V1(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for AccountEntryExt { + #[must_use] + fn from(v: AccountEntryExtView<'_>) -> Self { + Self::from(&v) + } +} + +impl AccountEntryExtView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V1(_) => 1, + } + } +} + +impl WriteXdr for AccountEntryExtView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => ().write_xdr(w)?, + Self::V1(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/account_entry_extension_v1.rs b/src/generated/account_entry_extension_v1.rs index efb9fac2a..f5767e4a2 100644 --- a/src/generated/account_entry_extension_v1.rs +++ b/src/generated/account_entry_extension_v1.rs @@ -57,3 +57,41 @@ impl WriteXdr for AccountEntryExtensionV1 { }) } } + +/// AccountEntryExtensionV1View is a borrowing equivalent of [`AccountEntryExtensionV1`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct AccountEntryExtensionV1View<'a> { + pub liabilities: Liabilities, + pub ext: AccountEntryExtensionV1ExtView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&AccountEntryExtensionV1View<'_>> for AccountEntryExtensionV1 { + #[must_use] + fn from(v: &AccountEntryExtensionV1View<'_>) -> Self { + Self { + liabilities: v.liabilities.clone(), + ext: (&v.ext).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for AccountEntryExtensionV1 { + #[must_use] + fn from(v: AccountEntryExtensionV1View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for AccountEntryExtensionV1View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.liabilities.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/account_entry_extension_v1_ext.rs b/src/generated/account_entry_extension_v1_ext.rs index edce65325..a3bb07047 100644 --- a/src/generated/account_entry_extension_v1_ext.rs +++ b/src/generated/account_entry_extension_v1_ext.rs @@ -135,3 +135,58 @@ impl WriteXdr for AccountEntryExtensionV1Ext { }) } } + +/// AccountEntryExtensionV1ExtView is a borrowing equivalent of [`AccountEntryExtensionV1Ext`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum AccountEntryExtensionV1ExtView<'a> { + V0, + V2(AccountEntryExtensionV2View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&AccountEntryExtensionV1ExtView<'_>> for AccountEntryExtensionV1Ext { + #[must_use] + fn from(v: &AccountEntryExtensionV1ExtView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + AccountEntryExtensionV1ExtView::V0 => Self::V0, + AccountEntryExtensionV1ExtView::V2(value) => Self::V2(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for AccountEntryExtensionV1Ext { + #[must_use] + fn from(v: AccountEntryExtensionV1ExtView<'_>) -> Self { + Self::from(&v) + } +} + +impl AccountEntryExtensionV1ExtView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V2(_) => 2, + } + } +} + +impl WriteXdr for AccountEntryExtensionV1ExtView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => ().write_xdr(w)?, + Self::V2(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/account_entry_extension_v2.rs b/src/generated/account_entry_extension_v2.rs index a89b62a76..95e53a1a5 100644 --- a/src/generated/account_entry_extension_v2.rs +++ b/src/generated/account_entry_extension_v2.rs @@ -65,3 +65,47 @@ impl WriteXdr for AccountEntryExtensionV2 { }) } } + +/// AccountEntryExtensionV2View is a borrowing equivalent of [`AccountEntryExtensionV2`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct AccountEntryExtensionV2View<'a> { + pub num_sponsored: u32, + pub num_sponsoring: u32, + pub signer_sponsoring_i_ds: VecMView<'a, SponsorshipDescriptor, 20>, + pub ext: AccountEntryExtensionV2Ext, +} + +#[cfg(feature = "alloc")] +impl From<&AccountEntryExtensionV2View<'_>> for AccountEntryExtensionV2 { + #[must_use] + fn from(v: &AccountEntryExtensionV2View<'_>) -> Self { + Self { + num_sponsored: v.num_sponsored, + num_sponsoring: v.num_sponsoring, + signer_sponsoring_i_ds: v.signer_sponsoring_i_ds.to_vecm(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for AccountEntryExtensionV2 { + #[must_use] + fn from(v: AccountEntryExtensionV2View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for AccountEntryExtensionV2View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.num_sponsored.write_xdr(w)?; + self.num_sponsoring.write_xdr(w)?; + self.signer_sponsoring_i_ds.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/auth_cert.rs b/src/generated/auth_cert.rs index 02ea23814..d0d29e6d0 100644 --- a/src/generated/auth_cert.rs +++ b/src/generated/auth_cert.rs @@ -57,3 +57,44 @@ impl WriteXdr for AuthCert { }) } } + +/// AuthCertView is a borrowing equivalent of [`AuthCert`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct AuthCertView<'a> { + pub pubkey: Curve25519Public, + pub expiration: u64, + pub sig: SignatureView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&AuthCertView<'_>> for AuthCert { + #[must_use] + fn from(v: &AuthCertView<'_>) -> Self { + Self { + pubkey: v.pubkey.clone(), + expiration: v.expiration, + sig: (&v.sig).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for AuthCert { + #[must_use] + fn from(v: AuthCertView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for AuthCertView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.pubkey.write_xdr(w)?; + self.expiration.write_xdr(w)?; + self.sig.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/authenticated_message.rs b/src/generated/authenticated_message.rs index 71534bb8e..2942a8dcb 100644 --- a/src/generated/authenticated_message.rs +++ b/src/generated/authenticated_message.rs @@ -133,3 +133,54 @@ impl WriteXdr for AuthenticatedMessage { }) } } + +/// AuthenticatedMessageView is a borrowing equivalent of [`AuthenticatedMessage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum AuthenticatedMessageView<'a> { + V0(AuthenticatedMessageV0View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&AuthenticatedMessageView<'_>> for AuthenticatedMessage { + #[must_use] + fn from(v: &AuthenticatedMessageView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + AuthenticatedMessageView::V0(value) => Self::V0(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for AuthenticatedMessage { + #[must_use] + fn from(v: AuthenticatedMessageView<'_>) -> Self { + Self::from(&v) + } +} + +impl AuthenticatedMessageView<'_> { + #[must_use] + pub const fn discriminant(&self) -> u32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + } + } +} + +impl WriteXdr for AuthenticatedMessageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/authenticated_message_v0.rs b/src/generated/authenticated_message_v0.rs index 58a2474af..46787efe9 100644 --- a/src/generated/authenticated_message_v0.rs +++ b/src/generated/authenticated_message_v0.rs @@ -57,3 +57,44 @@ impl WriteXdr for AuthenticatedMessageV0 { }) } } + +/// AuthenticatedMessageV0View is a borrowing equivalent of [`AuthenticatedMessageV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct AuthenticatedMessageV0View<'a> { + pub sequence: u64, + pub message: StellarMessageView<'a>, + pub mac: HmacSha256Mac, +} + +#[cfg(feature = "alloc")] +impl From<&AuthenticatedMessageV0View<'_>> for AuthenticatedMessageV0 { + #[must_use] + fn from(v: &AuthenticatedMessageV0View<'_>) -> Self { + Self { + sequence: v.sequence, + message: (&v.message).into(), + mac: v.mac.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for AuthenticatedMessageV0 { + #[must_use] + fn from(v: AuthenticatedMessageV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for AuthenticatedMessageV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.sequence.write_xdr(w)?; + self.message.write_xdr(w)?; + self.mac.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/bucket_entry.rs b/src/generated/bucket_entry.rs index 716368478..758d41204 100644 --- a/src/generated/bucket_entry.rs +++ b/src/generated/bucket_entry.rs @@ -154,3 +154,66 @@ impl WriteXdr for BucketEntry { }) } } + +/// BucketEntryView is a borrowing equivalent of [`BucketEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum BucketEntryView<'a> { + Liveentry(LedgerEntryView<'a>), + Initentry(LedgerEntryView<'a>), + Deadentry(LedgerKeyView<'a>), + Metaentry(BucketMetadata), +} + +#[cfg(feature = "alloc")] +impl From<&BucketEntryView<'_>> for BucketEntry { + #[must_use] + fn from(v: &BucketEntryView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + BucketEntryView::Liveentry(value) => Self::Liveentry(value.into()), + BucketEntryView::Initentry(value) => Self::Initentry(value.into()), + BucketEntryView::Deadentry(value) => Self::Deadentry(value.into()), + BucketEntryView::Metaentry(value) => Self::Metaentry(value.clone()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for BucketEntry { + #[must_use] + fn from(v: BucketEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl BucketEntryView<'_> { + #[must_use] + pub const fn discriminant(&self) -> BucketEntryType { + #[allow(clippy::match_same_arms)] + match self { + Self::Liveentry(_) => BucketEntryType::Liveentry, + Self::Initentry(_) => BucketEntryType::Initentry, + Self::Deadentry(_) => BucketEntryType::Deadentry, + Self::Metaentry(_) => BucketEntryType::Metaentry, + } + } +} + +impl WriteXdr for BucketEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Liveentry(v) => v.write_xdr(w)?, + Self::Initentry(v) => v.write_xdr(w)?, + Self::Deadentry(v) => v.write_xdr(w)?, + Self::Metaentry(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/claim_predicate.rs b/src/generated/claim_predicate.rs index 1fced3cce..9c9f33149 100644 --- a/src/generated/claim_predicate.rs +++ b/src/generated/claim_predicate.rs @@ -194,3 +194,74 @@ impl WriteXdr for ClaimPredicate { }) } } + +/// ClaimPredicateView is a borrowing equivalent of [`ClaimPredicate`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ClaimPredicateView<'a> { + Unconditional, + And(VecMView<'a, ClaimPredicateView<'a>, 2>), + Or(VecMView<'a, ClaimPredicateView<'a>, 2>), + Not(Option<&'a ClaimPredicateView<'a>>), + BeforeAbsoluteTime(i64), + BeforeRelativeTime(i64), +} + +#[cfg(feature = "alloc")] +impl From<&ClaimPredicateView<'_>> for ClaimPredicate { + #[must_use] + fn from(v: &ClaimPredicateView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ClaimPredicateView::Unconditional => Self::Unconditional, + ClaimPredicateView::And(value) => Self::And(value.to_vecm_from()), + ClaimPredicateView::Or(value) => Self::Or(value.to_vecm_from()), + ClaimPredicateView::Not(value) => Self::Not(value.map(|v| Box::new(v.into()))), + ClaimPredicateView::BeforeAbsoluteTime(value) => Self::BeforeAbsoluteTime(*value), + ClaimPredicateView::BeforeRelativeTime(value) => Self::BeforeRelativeTime(*value), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ClaimPredicate { + #[must_use] + fn from(v: ClaimPredicateView<'_>) -> Self { + Self::from(&v) + } +} + +impl ClaimPredicateView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ClaimPredicateType { + #[allow(clippy::match_same_arms)] + match self { + Self::Unconditional => ClaimPredicateType::Unconditional, + Self::And(_) => ClaimPredicateType::And, + Self::Or(_) => ClaimPredicateType::Or, + Self::Not(_) => ClaimPredicateType::Not, + Self::BeforeAbsoluteTime(_) => ClaimPredicateType::BeforeAbsoluteTime, + Self::BeforeRelativeTime(_) => ClaimPredicateType::BeforeRelativeTime, + } + } +} + +impl WriteXdr for ClaimPredicateView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Unconditional => ().write_xdr(w)?, + Self::And(v) => v.write_xdr(w)?, + Self::Or(v) => v.write_xdr(w)?, + Self::Not(v) => v.write_xdr(w)?, + Self::BeforeAbsoluteTime(v) => v.write_xdr(w)?, + Self::BeforeRelativeTime(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/claimable_balance_entry.rs b/src/generated/claimable_balance_entry.rs index 0851bfffe..a25526297 100644 --- a/src/generated/claimable_balance_entry.rs +++ b/src/generated/claimable_balance_entry.rs @@ -81,3 +81,50 @@ impl WriteXdr for ClaimableBalanceEntry { }) } } + +/// ClaimableBalanceEntryView is a borrowing equivalent of [`ClaimableBalanceEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ClaimableBalanceEntryView<'a> { + pub balance_id: ClaimableBalanceId, + pub claimants: VecMView<'a, ClaimantView<'a>, 10>, + pub asset: Asset, + pub amount: i64, + pub ext: ClaimableBalanceEntryExt, +} + +#[cfg(feature = "alloc")] +impl From<&ClaimableBalanceEntryView<'_>> for ClaimableBalanceEntry { + #[must_use] + fn from(v: &ClaimableBalanceEntryView<'_>) -> Self { + Self { + balance_id: v.balance_id.clone(), + claimants: v.claimants.to_vecm_from(), + asset: v.asset.clone(), + amount: v.amount, + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ClaimableBalanceEntry { + #[must_use] + fn from(v: ClaimableBalanceEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ClaimableBalanceEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.balance_id.write_xdr(w)?; + self.claimants.write_xdr(w)?; + self.asset.write_xdr(w)?; + self.amount.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/claimant.rs b/src/generated/claimant.rs index e954ae5c7..68b7d78d0 100644 --- a/src/generated/claimant.rs +++ b/src/generated/claimant.rs @@ -132,3 +132,54 @@ impl WriteXdr for Claimant { }) } } + +/// ClaimantView is a borrowing equivalent of [`Claimant`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ClaimantView<'a> { + ClaimantTypeV0(ClaimantV0View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ClaimantView<'_>> for Claimant { + #[must_use] + fn from(v: &ClaimantView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ClaimantView::ClaimantTypeV0(value) => Self::ClaimantTypeV0(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for Claimant { + #[must_use] + fn from(v: ClaimantView<'_>) -> Self { + Self::from(&v) + } +} + +impl ClaimantView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ClaimantType { + #[allow(clippy::match_same_arms)] + match self { + Self::ClaimantTypeV0(_) => ClaimantType::ClaimantTypeV0, + } + } +} + +impl WriteXdr for ClaimantView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::ClaimantTypeV0(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/claimant_v0.rs b/src/generated/claimant_v0.rs index 152e1fd90..07fb3f6b5 100644 --- a/src/generated/claimant_v0.rs +++ b/src/generated/claimant_v0.rs @@ -49,3 +49,41 @@ impl WriteXdr for ClaimantV0 { }) } } + +/// ClaimantV0View is a borrowing equivalent of [`ClaimantV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ClaimantV0View<'a> { + pub destination: AccountId, + pub predicate: ClaimPredicateView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ClaimantV0View<'_>> for ClaimantV0 { + #[must_use] + fn from(v: &ClaimantV0View<'_>) -> Self { + Self { + destination: v.destination.clone(), + predicate: (&v.predicate).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ClaimantV0 { + #[must_use] + fn from(v: ClaimantV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ClaimantV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.destination.write_xdr(w)?; + self.predicate.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/config_setting_entry.rs b/src/generated/config_setting_entry.rs index e175ab5c1..afa9105d2 100644 --- a/src/generated/config_setting_entry.rs +++ b/src/generated/config_setting_entry.rs @@ -362,3 +362,172 @@ impl WriteXdr for ConfigSettingEntry { }) } } + +/// ConfigSettingEntryView is a borrowing equivalent of [`ConfigSettingEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ConfigSettingEntryView<'a> { + ContractMaxSizeBytes(u32), + ContractComputeV0(ConfigSettingContractComputeV0), + ContractLedgerCostV0(ConfigSettingContractLedgerCostV0), + ContractHistoricalDataV0(ConfigSettingContractHistoricalDataV0), + ContractEventsV0(ConfigSettingContractEventsV0), + ContractBandwidthV0(ConfigSettingContractBandwidthV0), + ContractCostParamsCpuInstructions(ContractCostParamsView<'a>), + ContractCostParamsMemoryBytes(ContractCostParamsView<'a>), + ContractDataKeySizeBytes(u32), + ContractDataEntrySizeBytes(u32), + StateArchival(StateArchivalSettings), + ContractExecutionLanes(ConfigSettingContractExecutionLanesV0), + LiveSorobanStateSizeWindow(VecMView<'a, u64>), + EvictionIterator(EvictionIterator), + ContractParallelComputeV0(ConfigSettingContractParallelComputeV0), + ContractLedgerCostExtV0(ConfigSettingContractLedgerCostExtV0), + ScpTiming(ConfigSettingScpTiming), + FrozenLedgerKeys(FrozenLedgerKeysView<'a>), + FrozenLedgerKeysDelta(FrozenLedgerKeysDeltaView<'a>), + FreezeBypassTxs(FreezeBypassTxsView<'a>), + FreezeBypassTxsDelta(FreezeBypassTxsDeltaView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ConfigSettingEntryView<'_>> for ConfigSettingEntry { + #[must_use] + fn from(v: &ConfigSettingEntryView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ConfigSettingEntryView::ContractMaxSizeBytes(value) => { + Self::ContractMaxSizeBytes(*value) + } + ConfigSettingEntryView::ContractComputeV0(value) => { + Self::ContractComputeV0(value.clone()) + } + ConfigSettingEntryView::ContractLedgerCostV0(value) => { + Self::ContractLedgerCostV0(value.clone()) + } + ConfigSettingEntryView::ContractHistoricalDataV0(value) => { + Self::ContractHistoricalDataV0(value.clone()) + } + ConfigSettingEntryView::ContractEventsV0(value) => { + Self::ContractEventsV0(value.clone()) + } + ConfigSettingEntryView::ContractBandwidthV0(value) => { + Self::ContractBandwidthV0(value.clone()) + } + ConfigSettingEntryView::ContractCostParamsCpuInstructions(value) => { + Self::ContractCostParamsCpuInstructions(value.into()) + } + ConfigSettingEntryView::ContractCostParamsMemoryBytes(value) => { + Self::ContractCostParamsMemoryBytes(value.into()) + } + ConfigSettingEntryView::ContractDataKeySizeBytes(value) => { + Self::ContractDataKeySizeBytes(*value) + } + ConfigSettingEntryView::ContractDataEntrySizeBytes(value) => { + Self::ContractDataEntrySizeBytes(*value) + } + ConfigSettingEntryView::StateArchival(value) => Self::StateArchival(value.clone()), + ConfigSettingEntryView::ContractExecutionLanes(value) => { + Self::ContractExecutionLanes(value.clone()) + } + ConfigSettingEntryView::LiveSorobanStateSizeWindow(value) => { + Self::LiveSorobanStateSizeWindow(value.to_vecm()) + } + ConfigSettingEntryView::EvictionIterator(value) => { + Self::EvictionIterator(value.clone()) + } + ConfigSettingEntryView::ContractParallelComputeV0(value) => { + Self::ContractParallelComputeV0(value.clone()) + } + ConfigSettingEntryView::ContractLedgerCostExtV0(value) => { + Self::ContractLedgerCostExtV0(value.clone()) + } + ConfigSettingEntryView::ScpTiming(value) => Self::ScpTiming(value.clone()), + ConfigSettingEntryView::FrozenLedgerKeys(value) => Self::FrozenLedgerKeys(value.into()), + ConfigSettingEntryView::FrozenLedgerKeysDelta(value) => { + Self::FrozenLedgerKeysDelta(value.into()) + } + ConfigSettingEntryView::FreezeBypassTxs(value) => Self::FreezeBypassTxs(value.into()), + ConfigSettingEntryView::FreezeBypassTxsDelta(value) => { + Self::FreezeBypassTxsDelta(value.into()) + } + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ConfigSettingEntry { + #[must_use] + fn from(v: ConfigSettingEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl ConfigSettingEntryView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ConfigSettingId { + #[allow(clippy::match_same_arms)] + match self { + Self::ContractMaxSizeBytes(_) => ConfigSettingId::ContractMaxSizeBytes, + Self::ContractComputeV0(_) => ConfigSettingId::ContractComputeV0, + Self::ContractLedgerCostV0(_) => ConfigSettingId::ContractLedgerCostV0, + Self::ContractHistoricalDataV0(_) => ConfigSettingId::ContractHistoricalDataV0, + Self::ContractEventsV0(_) => ConfigSettingId::ContractEventsV0, + Self::ContractBandwidthV0(_) => ConfigSettingId::ContractBandwidthV0, + Self::ContractCostParamsCpuInstructions(_) => { + ConfigSettingId::ContractCostParamsCpuInstructions + } + Self::ContractCostParamsMemoryBytes(_) => { + ConfigSettingId::ContractCostParamsMemoryBytes + } + Self::ContractDataKeySizeBytes(_) => ConfigSettingId::ContractDataKeySizeBytes, + Self::ContractDataEntrySizeBytes(_) => ConfigSettingId::ContractDataEntrySizeBytes, + Self::StateArchival(_) => ConfigSettingId::StateArchival, + Self::ContractExecutionLanes(_) => ConfigSettingId::ContractExecutionLanes, + Self::LiveSorobanStateSizeWindow(_) => ConfigSettingId::LiveSorobanStateSizeWindow, + Self::EvictionIterator(_) => ConfigSettingId::EvictionIterator, + Self::ContractParallelComputeV0(_) => ConfigSettingId::ContractParallelComputeV0, + Self::ContractLedgerCostExtV0(_) => ConfigSettingId::ContractLedgerCostExtV0, + Self::ScpTiming(_) => ConfigSettingId::ScpTiming, + Self::FrozenLedgerKeys(_) => ConfigSettingId::FrozenLedgerKeys, + Self::FrozenLedgerKeysDelta(_) => ConfigSettingId::FrozenLedgerKeysDelta, + Self::FreezeBypassTxs(_) => ConfigSettingId::FreezeBypassTxs, + Self::FreezeBypassTxsDelta(_) => ConfigSettingId::FreezeBypassTxsDelta, + } + } +} + +impl WriteXdr for ConfigSettingEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::ContractMaxSizeBytes(v) => v.write_xdr(w)?, + Self::ContractComputeV0(v) => v.write_xdr(w)?, + Self::ContractLedgerCostV0(v) => v.write_xdr(w)?, + Self::ContractHistoricalDataV0(v) => v.write_xdr(w)?, + Self::ContractEventsV0(v) => v.write_xdr(w)?, + Self::ContractBandwidthV0(v) => v.write_xdr(w)?, + Self::ContractCostParamsCpuInstructions(v) => v.write_xdr(w)?, + Self::ContractCostParamsMemoryBytes(v) => v.write_xdr(w)?, + Self::ContractDataKeySizeBytes(v) => v.write_xdr(w)?, + Self::ContractDataEntrySizeBytes(v) => v.write_xdr(w)?, + Self::StateArchival(v) => v.write_xdr(w)?, + Self::ContractExecutionLanes(v) => v.write_xdr(w)?, + Self::LiveSorobanStateSizeWindow(v) => v.write_xdr(w)?, + Self::EvictionIterator(v) => v.write_xdr(w)?, + Self::ContractParallelComputeV0(v) => v.write_xdr(w)?, + Self::ContractLedgerCostExtV0(v) => v.write_xdr(w)?, + Self::ScpTiming(v) => v.write_xdr(w)?, + Self::FrozenLedgerKeys(v) => v.write_xdr(w)?, + Self::FrozenLedgerKeysDelta(v) => v.write_xdr(w)?, + Self::FreezeBypassTxs(v) => v.write_xdr(w)?, + Self::FreezeBypassTxsDelta(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/config_upgrade_set.rs b/src/generated/config_upgrade_set.rs index a2bc4c83a..a63d02058 100644 --- a/src/generated/config_upgrade_set.rs +++ b/src/generated/config_upgrade_set.rs @@ -44,3 +44,38 @@ impl WriteXdr for ConfigUpgradeSet { }) } } + +/// ConfigUpgradeSetView is a borrowing equivalent of [`ConfigUpgradeSet`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ConfigUpgradeSetView<'a> { + pub updated_entry: VecMView<'a, ConfigSettingEntryView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&ConfigUpgradeSetView<'_>> for ConfigUpgradeSet { + #[must_use] + fn from(v: &ConfigUpgradeSetView<'_>) -> Self { + Self { + updated_entry: v.updated_entry.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ConfigUpgradeSet { + #[must_use] + fn from(v: ConfigUpgradeSetView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ConfigUpgradeSetView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.updated_entry.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/contract_code_entry.rs b/src/generated/contract_code_entry.rs index 2ef077f49..d7707c5d2 100644 --- a/src/generated/contract_code_entry.rs +++ b/src/generated/contract_code_entry.rs @@ -63,3 +63,44 @@ impl WriteXdr for ContractCodeEntry { }) } } + +/// ContractCodeEntryView is a borrowing equivalent of [`ContractCodeEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ContractCodeEntryView<'a> { + pub ext: ContractCodeEntryExt, + pub hash: Hash, + pub code: BytesMView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ContractCodeEntryView<'_>> for ContractCodeEntry { + #[must_use] + fn from(v: &ContractCodeEntryView<'_>) -> Self { + Self { + ext: v.ext.clone(), + hash: v.hash.clone(), + code: v.code.to_bytesm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ContractCodeEntry { + #[must_use] + fn from(v: ContractCodeEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ContractCodeEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.hash.write_xdr(w)?; + self.code.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/contract_cost_params.rs b/src/generated/contract_cost_params.rs index bf4005608..7b6e74bf5 100644 --- a/src/generated/contract_cost_params.rs +++ b/src/generated/contract_cost_params.rs @@ -107,3 +107,31 @@ impl AsRef<[ContractCostParamEntry]> for ContractCostParams { self.0 .0 } } + +/// ContractCostParamsView is a borrowing equivalent of [`ContractCostParams`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ContractCostParamsView<'a>(pub VecMView<'a, ContractCostParamEntry, 1024>); + +#[cfg(feature = "alloc")] +impl From<&ContractCostParamsView<'_>> for ContractCostParams { + #[must_use] + fn from(v: &ContractCostParamsView<'_>) -> Self { + Self(v.0.to_vecm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for ContractCostParams { + #[must_use] + fn from(v: ContractCostParamsView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ContractCostParamsView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/contract_data_entry.rs b/src/generated/contract_data_entry.rs index d86834ae5..7637f1419 100644 --- a/src/generated/contract_data_entry.rs +++ b/src/generated/contract_data_entry.rs @@ -61,3 +61,50 @@ impl WriteXdr for ContractDataEntry { }) } } + +/// ContractDataEntryView is a borrowing equivalent of [`ContractDataEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ContractDataEntryView<'a> { + pub ext: ExtensionPoint, + pub contract: ScAddress, + pub key: ScValView<'a>, + pub durability: ContractDataDurability, + pub val: ScValView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ContractDataEntryView<'_>> for ContractDataEntry { + #[must_use] + fn from(v: &ContractDataEntryView<'_>) -> Self { + Self { + ext: v.ext.clone(), + contract: v.contract.clone(), + key: (&v.key).into(), + durability: v.durability, + val: (&v.val).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ContractDataEntry { + #[must_use] + fn from(v: ContractDataEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ContractDataEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.contract.write_xdr(w)?; + self.key.write_xdr(w)?; + self.durability.write_xdr(w)?; + self.val.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/contract_event.rs b/src/generated/contract_event.rs index 44c8ca519..a11b970c4 100644 --- a/src/generated/contract_event.rs +++ b/src/generated/contract_event.rs @@ -75,3 +75,47 @@ impl WriteXdr for ContractEvent { }) } } + +/// ContractEventView is a borrowing equivalent of [`ContractEvent`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ContractEventView<'a> { + pub ext: ExtensionPoint, + pub contract_id: Option, + pub type_: ContractEventType, + pub body: ContractEventBodyView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ContractEventView<'_>> for ContractEvent { + #[must_use] + fn from(v: &ContractEventView<'_>) -> Self { + Self { + ext: v.ext.clone(), + contract_id: v.contract_id.clone(), + type_: v.type_, + body: (&v.body).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ContractEvent { + #[must_use] + fn from(v: ContractEventView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ContractEventView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.contract_id.write_xdr(w)?; + self.type_.write_xdr(w)?; + self.body.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/contract_event_body.rs b/src/generated/contract_event_body.rs index 07ef72e06..e8fea060a 100644 --- a/src/generated/contract_event_body.rs +++ b/src/generated/contract_event_body.rs @@ -132,3 +132,54 @@ impl WriteXdr for ContractEventBody { }) } } + +/// ContractEventBodyView is a borrowing equivalent of [`ContractEventBody`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ContractEventBodyView<'a> { + V0(ContractEventV0View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ContractEventBodyView<'_>> for ContractEventBody { + #[must_use] + fn from(v: &ContractEventBodyView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ContractEventBodyView::V0(value) => Self::V0(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ContractEventBody { + #[must_use] + fn from(v: ContractEventBodyView<'_>) -> Self { + Self::from(&v) + } +} + +impl ContractEventBodyView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + } + } +} + +impl WriteXdr for ContractEventBodyView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/contract_event_v0.rs b/src/generated/contract_event_v0.rs index 86fb4f2f3..b17e9b798 100644 --- a/src/generated/contract_event_v0.rs +++ b/src/generated/contract_event_v0.rs @@ -49,3 +49,41 @@ impl WriteXdr for ContractEventV0 { }) } } + +/// ContractEventV0View is a borrowing equivalent of [`ContractEventV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ContractEventV0View<'a> { + pub topics: VecMView<'a, ScValView<'a>>, + pub data: ScValView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ContractEventV0View<'_>> for ContractEventV0 { + #[must_use] + fn from(v: &ContractEventV0View<'_>) -> Self { + Self { + topics: v.topics.to_vecm_from(), + data: (&v.data).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ContractEventV0 { + #[must_use] + fn from(v: ContractEventV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ContractEventV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.topics.write_xdr(w)?; + self.data.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/contract_executable.rs b/src/generated/contract_executable.rs index 88f49189a..aaf2acc09 100644 --- a/src/generated/contract_executable.rs +++ b/src/generated/contract_executable.rs @@ -148,3 +148,62 @@ impl WriteXdr for ContractExecutable { }) } } + +/// ContractExecutableView is a borrowing equivalent of [`ContractExecutable`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ContractExecutableView<'a> { + Wasm(Hash), + StellarAsset, + ExternalRef(ContractExecutableExternalRefView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ContractExecutableView<'_>> for ContractExecutable { + #[must_use] + fn from(v: &ContractExecutableView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ContractExecutableView::Wasm(value) => Self::Wasm(value.clone()), + ContractExecutableView::StellarAsset => Self::StellarAsset, + ContractExecutableView::ExternalRef(value) => Self::ExternalRef(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ContractExecutable { + #[must_use] + fn from(v: ContractExecutableView<'_>) -> Self { + Self::from(&v) + } +} + +impl ContractExecutableView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ContractExecutableType { + #[allow(clippy::match_same_arms)] + match self { + Self::Wasm(_) => ContractExecutableType::Wasm, + Self::StellarAsset => ContractExecutableType::StellarAsset, + Self::ExternalRef(_) => ContractExecutableType::ExternalRef, + } + } +} + +impl WriteXdr for ContractExecutableView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Wasm(v) => v.write_xdr(w)?, + Self::StellarAsset => ().write_xdr(w)?, + Self::ExternalRef(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/contract_executable_external_ref.rs b/src/generated/contract_executable_external_ref.rs index 555a4b1f5..73b57a887 100644 --- a/src/generated/contract_executable_external_ref.rs +++ b/src/generated/contract_executable_external_ref.rs @@ -48,3 +48,41 @@ impl WriteXdr for ContractExecutableExternalRef { }) } } + +/// ContractExecutableExternalRefView is a borrowing equivalent of [`ContractExecutableExternalRef`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ContractExecutableExternalRefView<'a> { + pub executable_owner: ScAddress, + pub tag: ScStringView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ContractExecutableExternalRefView<'_>> for ContractExecutableExternalRef { + #[must_use] + fn from(v: &ContractExecutableExternalRefView<'_>) -> Self { + Self { + executable_owner: v.executable_owner.clone(), + tag: (&v.tag).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ContractExecutableExternalRef { + #[must_use] + fn from(v: ContractExecutableExternalRefView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ContractExecutableExternalRefView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.executable_owner.write_xdr(w)?; + self.tag.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/create_claimable_balance_op.rs b/src/generated/create_claimable_balance_op.rs index e5b45c781..fca2ee942 100644 --- a/src/generated/create_claimable_balance_op.rs +++ b/src/generated/create_claimable_balance_op.rs @@ -57,3 +57,44 @@ impl WriteXdr for CreateClaimableBalanceOp { }) } } + +/// CreateClaimableBalanceOpView is a borrowing equivalent of [`CreateClaimableBalanceOp`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct CreateClaimableBalanceOpView<'a> { + pub asset: Asset, + pub amount: i64, + pub claimants: VecMView<'a, ClaimantView<'a>, 10>, +} + +#[cfg(feature = "alloc")] +impl From<&CreateClaimableBalanceOpView<'_>> for CreateClaimableBalanceOp { + #[must_use] + fn from(v: &CreateClaimableBalanceOpView<'_>) -> Self { + Self { + asset: v.asset.clone(), + amount: v.amount, + claimants: v.claimants.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for CreateClaimableBalanceOp { + #[must_use] + fn from(v: CreateClaimableBalanceOpView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for CreateClaimableBalanceOpView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.asset.write_xdr(w)?; + self.amount.write_xdr(w)?; + self.claimants.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/create_contract_args.rs b/src/generated/create_contract_args.rs index 64ae97d8a..01bea713e 100644 --- a/src/generated/create_contract_args.rs +++ b/src/generated/create_contract_args.rs @@ -49,3 +49,41 @@ impl WriteXdr for CreateContractArgs { }) } } + +/// CreateContractArgsView is a borrowing equivalent of [`CreateContractArgs`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct CreateContractArgsView<'a> { + pub contract_id_preimage: ContractIdPreimage, + pub executable: ContractExecutableView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&CreateContractArgsView<'_>> for CreateContractArgs { + #[must_use] + fn from(v: &CreateContractArgsView<'_>) -> Self { + Self { + contract_id_preimage: v.contract_id_preimage.clone(), + executable: (&v.executable).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for CreateContractArgs { + #[must_use] + fn from(v: CreateContractArgsView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for CreateContractArgsView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.contract_id_preimage.write_xdr(w)?; + self.executable.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/create_contract_args_v2.rs b/src/generated/create_contract_args_v2.rs index cb8210d34..9abdd486f 100644 --- a/src/generated/create_contract_args_v2.rs +++ b/src/generated/create_contract_args_v2.rs @@ -54,3 +54,44 @@ impl WriteXdr for CreateContractArgsV2 { }) } } + +/// CreateContractArgsV2View is a borrowing equivalent of [`CreateContractArgsV2`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct CreateContractArgsV2View<'a> { + pub contract_id_preimage: ContractIdPreimage, + pub executable: ContractExecutableView<'a>, + pub constructor_args: VecMView<'a, ScValView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&CreateContractArgsV2View<'_>> for CreateContractArgsV2 { + #[must_use] + fn from(v: &CreateContractArgsV2View<'_>) -> Self { + Self { + contract_id_preimage: v.contract_id_preimage.clone(), + executable: (&v.executable).into(), + constructor_args: v.constructor_args.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for CreateContractArgsV2 { + #[must_use] + fn from(v: CreateContractArgsV2View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for CreateContractArgsV2View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.contract_id_preimage.write_xdr(w)?; + self.executable.write_xdr(w)?; + self.constructor_args.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/data_entry.rs b/src/generated/data_entry.rs index bb7823a9b..e454ef2e5 100644 --- a/src/generated/data_entry.rs +++ b/src/generated/data_entry.rs @@ -64,3 +64,47 @@ impl WriteXdr for DataEntry { }) } } + +/// DataEntryView is a borrowing equivalent of [`DataEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct DataEntryView<'a> { + pub account_id: AccountId, + pub data_name: String64View<'a>, + pub data_value: DataValueView<'a>, + pub ext: DataEntryExt, +} + +#[cfg(feature = "alloc")] +impl From<&DataEntryView<'_>> for DataEntry { + #[must_use] + fn from(v: &DataEntryView<'_>) -> Self { + Self { + account_id: v.account_id.clone(), + data_name: (&v.data_name).into(), + data_value: (&v.data_value).into(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for DataEntry { + #[must_use] + fn from(v: DataEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for DataEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.account_id.write_xdr(w)?; + self.data_name.write_xdr(w)?; + self.data_value.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/data_value.rs b/src/generated/data_value.rs index 77052eed6..9bb4bcc34 100644 --- a/src/generated/data_value.rs +++ b/src/generated/data_value.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for DataValue { self.0 .0 } } + +/// DataValueView is a borrowing equivalent of [`DataValue`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct DataValueView<'a>(pub BytesMView<'a, 64>); + +#[cfg(feature = "alloc")] +impl From<&DataValueView<'_>> for DataValue { + #[must_use] + fn from(v: &DataValueView<'_>) -> Self { + Self(v.0.to_bytesm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for DataValue { + #[must_use] + fn from(v: DataValueView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for DataValueView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/decorated_signature.rs b/src/generated/decorated_signature.rs index a9ddb78ec..16a8cfe1b 100644 --- a/src/generated/decorated_signature.rs +++ b/src/generated/decorated_signature.rs @@ -49,3 +49,41 @@ impl WriteXdr for DecoratedSignature { }) } } + +/// DecoratedSignatureView is a borrowing equivalent of [`DecoratedSignature`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct DecoratedSignatureView<'a> { + pub hint: SignatureHint, + pub signature: SignatureView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&DecoratedSignatureView<'_>> for DecoratedSignature { + #[must_use] + fn from(v: &DecoratedSignatureView<'_>) -> Self { + Self { + hint: v.hint.clone(), + signature: (&v.signature).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for DecoratedSignature { + #[must_use] + fn from(v: DecoratedSignatureView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for DecoratedSignatureView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.hint.write_xdr(w)?; + self.signature.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/dependent_tx_cluster.rs b/src/generated/dependent_tx_cluster.rs index 958de8bc2..f4575227a 100644 --- a/src/generated/dependent_tx_cluster.rs +++ b/src/generated/dependent_tx_cluster.rs @@ -107,3 +107,31 @@ impl AsRef<[TransactionEnvelope]> for DependentTxCluster { self.0 .0 } } + +/// DependentTxClusterView is a borrowing equivalent of [`DependentTxCluster`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct DependentTxClusterView<'a>(pub VecMView<'a, TransactionEnvelopeView<'a>>); + +#[cfg(feature = "alloc")] +impl From<&DependentTxClusterView<'_>> for DependentTxCluster { + #[must_use] + fn from(v: &DependentTxClusterView<'_>) -> Self { + Self(v.0.to_vecm_from()) + } +} + +#[cfg(feature = "alloc")] +impl From> for DependentTxCluster { + #[must_use] + fn from(v: DependentTxClusterView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for DependentTxClusterView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/diagnostic_event.rs b/src/generated/diagnostic_event.rs index 0e1165ffd..95a6ebbb0 100644 --- a/src/generated/diagnostic_event.rs +++ b/src/generated/diagnostic_event.rs @@ -49,3 +49,41 @@ impl WriteXdr for DiagnosticEvent { }) } } + +/// DiagnosticEventView is a borrowing equivalent of [`DiagnosticEvent`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct DiagnosticEventView<'a> { + pub in_successful_contract_call: bool, + pub event: ContractEventView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&DiagnosticEventView<'_>> for DiagnosticEvent { + #[must_use] + fn from(v: &DiagnosticEventView<'_>) -> Self { + Self { + in_successful_contract_call: v.in_successful_contract_call, + event: (&v.event).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for DiagnosticEvent { + #[must_use] + fn from(v: DiagnosticEventView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for DiagnosticEventView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.in_successful_contract_call.write_xdr(w)?; + self.event.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/encoded_ledger_key.rs b/src/generated/encoded_ledger_key.rs index f4397f428..846130195 100644 --- a/src/generated/encoded_ledger_key.rs +++ b/src/generated/encoded_ledger_key.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for EncodedLedgerKey { self.0 .0 } } + +/// EncodedLedgerKeyView is a borrowing equivalent of [`EncodedLedgerKey`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct EncodedLedgerKeyView<'a>(pub BytesMView<'a>); + +#[cfg(feature = "alloc")] +impl From<&EncodedLedgerKeyView<'_>> for EncodedLedgerKey { + #[must_use] + fn from(v: &EncodedLedgerKeyView<'_>) -> Self { + Self(v.0.to_bytesm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for EncodedLedgerKey { + #[must_use] + fn from(v: EncodedLedgerKeyView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for EncodedLedgerKeyView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/encrypted_body.rs b/src/generated/encrypted_body.rs index ecc633c65..59aef472d 100644 --- a/src/generated/encrypted_body.rs +++ b/src/generated/encrypted_body.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for EncryptedBody { self.0 .0 } } + +/// EncryptedBodyView is a borrowing equivalent of [`EncryptedBody`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct EncryptedBodyView<'a>(pub BytesMView<'a, 64000>); + +#[cfg(feature = "alloc")] +impl From<&EncryptedBodyView<'_>> for EncryptedBody { + #[must_use] + fn from(v: &EncryptedBodyView<'_>) -> Self { + Self(v.0.to_bytesm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for EncryptedBody { + #[must_use] + fn from(v: EncryptedBodyView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for EncryptedBodyView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/fee_bump_transaction.rs b/src/generated/fee_bump_transaction.rs index 1ba9e748f..15ad59af7 100644 --- a/src/generated/fee_bump_transaction.rs +++ b/src/generated/fee_bump_transaction.rs @@ -71,3 +71,47 @@ impl WriteXdr for FeeBumpTransaction { }) } } + +/// FeeBumpTransactionView is a borrowing equivalent of [`FeeBumpTransaction`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct FeeBumpTransactionView<'a> { + pub fee_source: MuxedAccount, + pub fee: i64, + pub inner_tx: FeeBumpTransactionInnerTxView<'a>, + pub ext: FeeBumpTransactionExt, +} + +#[cfg(feature = "alloc")] +impl From<&FeeBumpTransactionView<'_>> for FeeBumpTransaction { + #[must_use] + fn from(v: &FeeBumpTransactionView<'_>) -> Self { + Self { + fee_source: v.fee_source.clone(), + fee: v.fee, + inner_tx: (&v.inner_tx).into(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for FeeBumpTransaction { + #[must_use] + fn from(v: FeeBumpTransactionView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for FeeBumpTransactionView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.fee_source.write_xdr(w)?; + self.fee.write_xdr(w)?; + self.inner_tx.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/fee_bump_transaction_envelope.rs b/src/generated/fee_bump_transaction_envelope.rs index 904a2b345..a59e20a88 100644 --- a/src/generated/fee_bump_transaction_envelope.rs +++ b/src/generated/fee_bump_transaction_envelope.rs @@ -51,3 +51,41 @@ impl WriteXdr for FeeBumpTransactionEnvelope { }) } } + +/// FeeBumpTransactionEnvelopeView is a borrowing equivalent of [`FeeBumpTransactionEnvelope`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct FeeBumpTransactionEnvelopeView<'a> { + pub tx: FeeBumpTransactionView<'a>, + pub signatures: VecMView<'a, DecoratedSignatureView<'a>, 20>, +} + +#[cfg(feature = "alloc")] +impl From<&FeeBumpTransactionEnvelopeView<'_>> for FeeBumpTransactionEnvelope { + #[must_use] + fn from(v: &FeeBumpTransactionEnvelopeView<'_>) -> Self { + Self { + tx: (&v.tx).into(), + signatures: v.signatures.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for FeeBumpTransactionEnvelope { + #[must_use] + fn from(v: FeeBumpTransactionEnvelopeView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for FeeBumpTransactionEnvelopeView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx.write_xdr(w)?; + self.signatures.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/fee_bump_transaction_inner_tx.rs b/src/generated/fee_bump_transaction_inner_tx.rs index 52bad56bb..8014df888 100644 --- a/src/generated/fee_bump_transaction_inner_tx.rs +++ b/src/generated/fee_bump_transaction_inner_tx.rs @@ -128,3 +128,54 @@ impl WriteXdr for FeeBumpTransactionInnerTx { }) } } + +/// FeeBumpTransactionInnerTxView is a borrowing equivalent of [`FeeBumpTransactionInnerTx`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum FeeBumpTransactionInnerTxView<'a> { + Tx(TransactionV1EnvelopeView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&FeeBumpTransactionInnerTxView<'_>> for FeeBumpTransactionInnerTx { + #[must_use] + fn from(v: &FeeBumpTransactionInnerTxView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + FeeBumpTransactionInnerTxView::Tx(value) => Self::Tx(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for FeeBumpTransactionInnerTx { + #[must_use] + fn from(v: FeeBumpTransactionInnerTxView<'_>) -> Self { + Self::from(&v) + } +} + +impl FeeBumpTransactionInnerTxView<'_> { + #[must_use] + pub const fn discriminant(&self) -> EnvelopeType { + #[allow(clippy::match_same_arms)] + match self { + Self::Tx(_) => EnvelopeType::Tx, + } + } +} + +impl WriteXdr for FeeBumpTransactionInnerTxView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Tx(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/flood_advert.rs b/src/generated/flood_advert.rs index c071bfd67..30b0f4417 100644 --- a/src/generated/flood_advert.rs +++ b/src/generated/flood_advert.rs @@ -45,3 +45,38 @@ impl WriteXdr for FloodAdvert { }) } } + +/// FloodAdvertView is a borrowing equivalent of [`FloodAdvert`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct FloodAdvertView<'a> { + pub tx_hashes: TxAdvertVectorView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&FloodAdvertView<'_>> for FloodAdvert { + #[must_use] + fn from(v: &FloodAdvertView<'_>) -> Self { + Self { + tx_hashes: (&v.tx_hashes).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for FloodAdvert { + #[must_use] + fn from(v: FloodAdvertView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for FloodAdvertView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx_hashes.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/flood_demand.rs b/src/generated/flood_demand.rs index e1ad4ed46..857c1902d 100644 --- a/src/generated/flood_demand.rs +++ b/src/generated/flood_demand.rs @@ -45,3 +45,38 @@ impl WriteXdr for FloodDemand { }) } } + +/// FloodDemandView is a borrowing equivalent of [`FloodDemand`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct FloodDemandView<'a> { + pub tx_hashes: TxDemandVectorView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&FloodDemandView<'_>> for FloodDemand { + #[must_use] + fn from(v: &FloodDemandView<'_>) -> Self { + Self { + tx_hashes: (&v.tx_hashes).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for FloodDemand { + #[must_use] + fn from(v: FloodDemandView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for FloodDemandView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx_hashes.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/freeze_bypass_txs.rs b/src/generated/freeze_bypass_txs.rs index 5e75f5f64..739b4f2be 100644 --- a/src/generated/freeze_bypass_txs.rs +++ b/src/generated/freeze_bypass_txs.rs @@ -44,3 +44,38 @@ impl WriteXdr for FreezeBypassTxs { }) } } + +/// FreezeBypassTxsView is a borrowing equivalent of [`FreezeBypassTxs`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct FreezeBypassTxsView<'a> { + pub tx_hashes: VecMView<'a, Hash>, +} + +#[cfg(feature = "alloc")] +impl From<&FreezeBypassTxsView<'_>> for FreezeBypassTxs { + #[must_use] + fn from(v: &FreezeBypassTxsView<'_>) -> Self { + Self { + tx_hashes: v.tx_hashes.to_vecm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for FreezeBypassTxs { + #[must_use] + fn from(v: FreezeBypassTxsView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for FreezeBypassTxsView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx_hashes.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/freeze_bypass_txs_delta.rs b/src/generated/freeze_bypass_txs_delta.rs index ae453740b..31c5485e0 100644 --- a/src/generated/freeze_bypass_txs_delta.rs +++ b/src/generated/freeze_bypass_txs_delta.rs @@ -48,3 +48,41 @@ impl WriteXdr for FreezeBypassTxsDelta { }) } } + +/// FreezeBypassTxsDeltaView is a borrowing equivalent of [`FreezeBypassTxsDelta`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct FreezeBypassTxsDeltaView<'a> { + pub add_txs: VecMView<'a, Hash>, + pub remove_txs: VecMView<'a, Hash>, +} + +#[cfg(feature = "alloc")] +impl From<&FreezeBypassTxsDeltaView<'_>> for FreezeBypassTxsDelta { + #[must_use] + fn from(v: &FreezeBypassTxsDeltaView<'_>) -> Self { + Self { + add_txs: v.add_txs.to_vecm(), + remove_txs: v.remove_txs.to_vecm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for FreezeBypassTxsDelta { + #[must_use] + fn from(v: FreezeBypassTxsDeltaView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for FreezeBypassTxsDeltaView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.add_txs.write_xdr(w)?; + self.remove_txs.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/frozen_ledger_keys.rs b/src/generated/frozen_ledger_keys.rs index 42c2e1a90..e75e0b9e8 100644 --- a/src/generated/frozen_ledger_keys.rs +++ b/src/generated/frozen_ledger_keys.rs @@ -44,3 +44,38 @@ impl WriteXdr for FrozenLedgerKeys { }) } } + +/// FrozenLedgerKeysView is a borrowing equivalent of [`FrozenLedgerKeys`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct FrozenLedgerKeysView<'a> { + pub keys: VecMView<'a, EncodedLedgerKeyView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&FrozenLedgerKeysView<'_>> for FrozenLedgerKeys { + #[must_use] + fn from(v: &FrozenLedgerKeysView<'_>) -> Self { + Self { + keys: v.keys.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for FrozenLedgerKeys { + #[must_use] + fn from(v: FrozenLedgerKeysView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for FrozenLedgerKeysView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.keys.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/frozen_ledger_keys_delta.rs b/src/generated/frozen_ledger_keys_delta.rs index 7cb91d241..322fc97a3 100644 --- a/src/generated/frozen_ledger_keys_delta.rs +++ b/src/generated/frozen_ledger_keys_delta.rs @@ -48,3 +48,41 @@ impl WriteXdr for FrozenLedgerKeysDelta { }) } } + +/// FrozenLedgerKeysDeltaView is a borrowing equivalent of [`FrozenLedgerKeysDelta`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct FrozenLedgerKeysDeltaView<'a> { + pub keys_to_freeze: VecMView<'a, EncodedLedgerKeyView<'a>>, + pub keys_to_unfreeze: VecMView<'a, EncodedLedgerKeyView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&FrozenLedgerKeysDeltaView<'_>> for FrozenLedgerKeysDelta { + #[must_use] + fn from(v: &FrozenLedgerKeysDeltaView<'_>) -> Self { + Self { + keys_to_freeze: v.keys_to_freeze.to_vecm_from(), + keys_to_unfreeze: v.keys_to_unfreeze.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for FrozenLedgerKeysDelta { + #[must_use] + fn from(v: FrozenLedgerKeysDeltaView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for FrozenLedgerKeysDeltaView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.keys_to_freeze.write_xdr(w)?; + self.keys_to_unfreeze.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/generalized_transaction_set.rs b/src/generated/generalized_transaction_set.rs index d92e8a862..b35aa52e8 100644 --- a/src/generated/generalized_transaction_set.rs +++ b/src/generated/generalized_transaction_set.rs @@ -129,3 +129,54 @@ impl WriteXdr for GeneralizedTransactionSet { }) } } + +/// GeneralizedTransactionSetView is a borrowing equivalent of [`GeneralizedTransactionSet`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum GeneralizedTransactionSetView<'a> { + V1(TransactionSetV1View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&GeneralizedTransactionSetView<'_>> for GeneralizedTransactionSet { + #[must_use] + fn from(v: &GeneralizedTransactionSetView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + GeneralizedTransactionSetView::V1(value) => Self::V1(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for GeneralizedTransactionSet { + #[must_use] + fn from(v: GeneralizedTransactionSetView<'_>) -> Self { + Self::from(&v) + } +} + +impl GeneralizedTransactionSetView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V1(_) => 1, + } + } +} + +impl WriteXdr for GeneralizedTransactionSetView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V1(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/hash_id_preimage.rs b/src/generated/hash_id_preimage.rs index f962908bf..8e5a87b72 100644 --- a/src/generated/hash_id_preimage.rs +++ b/src/generated/hash_id_preimage.rs @@ -209,3 +209,76 @@ impl WriteXdr for HashIdPreimage { }) } } + +/// HashIdPreimageView is a borrowing equivalent of [`HashIdPreimage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum HashIdPreimageView<'a> { + OpId(HashIdPreimageOperationId), + PoolRevokeOpId(HashIdPreimageRevokeId), + ContractId(HashIdPreimageContractId), + SorobanAuthorization(HashIdPreimageSorobanAuthorizationView<'a>), + SorobanAuthorizationWithAddress(HashIdPreimageSorobanAuthorizationWithAddressView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&HashIdPreimageView<'_>> for HashIdPreimage { + #[must_use] + fn from(v: &HashIdPreimageView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + HashIdPreimageView::OpId(value) => Self::OpId(value.clone()), + HashIdPreimageView::PoolRevokeOpId(value) => Self::PoolRevokeOpId(value.clone()), + HashIdPreimageView::ContractId(value) => Self::ContractId(value.clone()), + HashIdPreimageView::SorobanAuthorization(value) => { + Self::SorobanAuthorization(value.into()) + } + HashIdPreimageView::SorobanAuthorizationWithAddress(value) => { + Self::SorobanAuthorizationWithAddress(value.into()) + } + } + } +} + +#[cfg(feature = "alloc")] +impl From> for HashIdPreimage { + #[must_use] + fn from(v: HashIdPreimageView<'_>) -> Self { + Self::from(&v) + } +} + +impl HashIdPreimageView<'_> { + #[must_use] + pub const fn discriminant(&self) -> EnvelopeType { + #[allow(clippy::match_same_arms)] + match self { + Self::OpId(_) => EnvelopeType::OpId, + Self::PoolRevokeOpId(_) => EnvelopeType::PoolRevokeOpId, + Self::ContractId(_) => EnvelopeType::ContractId, + Self::SorobanAuthorization(_) => EnvelopeType::SorobanAuthorization, + Self::SorobanAuthorizationWithAddress(_) => { + EnvelopeType::SorobanAuthorizationWithAddress + } + } + } +} + +impl WriteXdr for HashIdPreimageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::OpId(v) => v.write_xdr(w)?, + Self::PoolRevokeOpId(v) => v.write_xdr(w)?, + Self::ContractId(v) => v.write_xdr(w)?, + Self::SorobanAuthorization(v) => v.write_xdr(w)?, + Self::SorobanAuthorizationWithAddress(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/hash_id_preimage_soroban_authorization.rs b/src/generated/hash_id_preimage_soroban_authorization.rs index 14862a8d0..28a78e928 100644 --- a/src/generated/hash_id_preimage_soroban_authorization.rs +++ b/src/generated/hash_id_preimage_soroban_authorization.rs @@ -61,3 +61,47 @@ impl WriteXdr for HashIdPreimageSorobanAuthorization { }) } } + +/// HashIdPreimageSorobanAuthorizationView is a borrowing equivalent of [`HashIdPreimageSorobanAuthorization`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct HashIdPreimageSorobanAuthorizationView<'a> { + pub network_id: Hash, + pub nonce: i64, + pub signature_expiration_ledger: u32, + pub invocation: SorobanAuthorizedInvocationView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&HashIdPreimageSorobanAuthorizationView<'_>> for HashIdPreimageSorobanAuthorization { + #[must_use] + fn from(v: &HashIdPreimageSorobanAuthorizationView<'_>) -> Self { + Self { + network_id: v.network_id.clone(), + nonce: v.nonce, + signature_expiration_ledger: v.signature_expiration_ledger, + invocation: (&v.invocation).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for HashIdPreimageSorobanAuthorization { + #[must_use] + fn from(v: HashIdPreimageSorobanAuthorizationView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for HashIdPreimageSorobanAuthorizationView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.network_id.write_xdr(w)?; + self.nonce.write_xdr(w)?; + self.signature_expiration_ledger.write_xdr(w)?; + self.invocation.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/hash_id_preimage_soroban_authorization_with_address.rs b/src/generated/hash_id_preimage_soroban_authorization_with_address.rs index 4d3f60eed..a997d5154 100644 --- a/src/generated/hash_id_preimage_soroban_authorization_with_address.rs +++ b/src/generated/hash_id_preimage_soroban_authorization_with_address.rs @@ -65,3 +65,54 @@ impl WriteXdr for HashIdPreimageSorobanAuthorizationWithAddress { }) } } + +/// HashIdPreimageSorobanAuthorizationWithAddressView is a borrowing equivalent of [`HashIdPreimageSorobanAuthorizationWithAddress`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct HashIdPreimageSorobanAuthorizationWithAddressView<'a> { + pub network_id: Hash, + pub nonce: i64, + pub signature_expiration_ledger: u32, + pub address: ScAddress, + pub invocation: SorobanAuthorizedInvocationView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&HashIdPreimageSorobanAuthorizationWithAddressView<'_>> + for HashIdPreimageSorobanAuthorizationWithAddress +{ + #[must_use] + fn from(v: &HashIdPreimageSorobanAuthorizationWithAddressView<'_>) -> Self { + Self { + network_id: v.network_id.clone(), + nonce: v.nonce, + signature_expiration_ledger: v.signature_expiration_ledger, + address: v.address.clone(), + invocation: (&v.invocation).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> + for HashIdPreimageSorobanAuthorizationWithAddress +{ + #[must_use] + fn from(v: HashIdPreimageSorobanAuthorizationWithAddressView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for HashIdPreimageSorobanAuthorizationWithAddressView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.network_id.write_xdr(w)?; + self.nonce.write_xdr(w)?; + self.signature_expiration_ledger.write_xdr(w)?; + self.address.write_xdr(w)?; + self.invocation.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/hello.rs b/src/generated/hello.rs index 42e44457a..073e85b93 100644 --- a/src/generated/hello.rs +++ b/src/generated/hello.rs @@ -77,3 +77,62 @@ impl WriteXdr for Hello { }) } } + +/// HelloView is a borrowing equivalent of [`Hello`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct HelloView<'a> { + pub ledger_version: u32, + pub overlay_version: u32, + pub overlay_min_version: u32, + pub network_id: Hash, + pub version_str: StringMView<'a, 100>, + pub listening_port: i32, + pub peer_id: NodeId, + pub cert: AuthCertView<'a>, + pub nonce: Uint256, +} + +#[cfg(feature = "alloc")] +impl From<&HelloView<'_>> for Hello { + #[must_use] + fn from(v: &HelloView<'_>) -> Self { + Self { + ledger_version: v.ledger_version, + overlay_version: v.overlay_version, + overlay_min_version: v.overlay_min_version, + network_id: v.network_id.clone(), + version_str: v.version_str.to_stringm(), + listening_port: v.listening_port, + peer_id: v.peer_id.clone(), + cert: (&v.cert).into(), + nonce: v.nonce.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for Hello { + #[must_use] + fn from(v: HelloView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for HelloView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ledger_version.write_xdr(w)?; + self.overlay_version.write_xdr(w)?; + self.overlay_min_version.write_xdr(w)?; + self.network_id.write_xdr(w)?; + self.version_str.write_xdr(w)?; + self.listening_port.write_xdr(w)?; + self.peer_id.write_xdr(w)?; + self.cert.write_xdr(w)?; + self.nonce.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/host_function.rs b/src/generated/host_function.rs index 1c62d2dee..da0d60336 100644 --- a/src/generated/host_function.rs +++ b/src/generated/host_function.rs @@ -167,3 +167,68 @@ impl WriteXdr for HostFunction { }) } } + +/// HostFunctionView is a borrowing equivalent of [`HostFunction`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum HostFunctionView<'a> { + InvokeContract(InvokeContractArgsView<'a>), + CreateContract(CreateContractArgsView<'a>), + UploadContractWasm(BytesMView<'a>), + CreateContractV2(CreateContractArgsV2View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&HostFunctionView<'_>> for HostFunction { + #[must_use] + fn from(v: &HostFunctionView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + HostFunctionView::InvokeContract(value) => Self::InvokeContract(value.into()), + HostFunctionView::CreateContract(value) => Self::CreateContract(value.into()), + HostFunctionView::UploadContractWasm(value) => { + Self::UploadContractWasm(value.to_bytesm()) + } + HostFunctionView::CreateContractV2(value) => Self::CreateContractV2(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for HostFunction { + #[must_use] + fn from(v: HostFunctionView<'_>) -> Self { + Self::from(&v) + } +} + +impl HostFunctionView<'_> { + #[must_use] + pub const fn discriminant(&self) -> HostFunctionType { + #[allow(clippy::match_same_arms)] + match self { + Self::InvokeContract(_) => HostFunctionType::InvokeContract, + Self::CreateContract(_) => HostFunctionType::CreateContract, + Self::UploadContractWasm(_) => HostFunctionType::UploadContractWasm, + Self::CreateContractV2(_) => HostFunctionType::CreateContractV2, + } + } +} + +impl WriteXdr for HostFunctionView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::InvokeContract(v) => v.write_xdr(w)?, + Self::CreateContract(v) => v.write_xdr(w)?, + Self::UploadContractWasm(v) => v.write_xdr(w)?, + Self::CreateContractV2(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/hot_archive_bucket_entry.rs b/src/generated/hot_archive_bucket_entry.rs index 44d9601d2..fffa9823c 100644 --- a/src/generated/hot_archive_bucket_entry.rs +++ b/src/generated/hot_archive_bucket_entry.rs @@ -150,3 +150,62 @@ impl WriteXdr for HotArchiveBucketEntry { }) } } + +/// HotArchiveBucketEntryView is a borrowing equivalent of [`HotArchiveBucketEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum HotArchiveBucketEntryView<'a> { + Archived(LedgerEntryView<'a>), + Live(LedgerKeyView<'a>), + Metaentry(BucketMetadata), +} + +#[cfg(feature = "alloc")] +impl From<&HotArchiveBucketEntryView<'_>> for HotArchiveBucketEntry { + #[must_use] + fn from(v: &HotArchiveBucketEntryView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + HotArchiveBucketEntryView::Archived(value) => Self::Archived(value.into()), + HotArchiveBucketEntryView::Live(value) => Self::Live(value.into()), + HotArchiveBucketEntryView::Metaentry(value) => Self::Metaentry(value.clone()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for HotArchiveBucketEntry { + #[must_use] + fn from(v: HotArchiveBucketEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl HotArchiveBucketEntryView<'_> { + #[must_use] + pub const fn discriminant(&self) -> HotArchiveBucketEntryType { + #[allow(clippy::match_same_arms)] + match self { + Self::Archived(_) => HotArchiveBucketEntryType::Archived, + Self::Live(_) => HotArchiveBucketEntryType::Live, + Self::Metaentry(_) => HotArchiveBucketEntryType::Metaentry, + } + } +} + +impl WriteXdr for HotArchiveBucketEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Archived(v) => v.write_xdr(w)?, + Self::Live(v) => v.write_xdr(w)?, + Self::Metaentry(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/inflation_result.rs b/src/generated/inflation_result.rs index d3815d5a1..3703f01d7 100644 --- a/src/generated/inflation_result.rs +++ b/src/generated/inflation_result.rs @@ -138,3 +138,58 @@ impl WriteXdr for InflationResult { }) } } + +/// InflationResultView is a borrowing equivalent of [`InflationResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum InflationResultView<'a> { + Success(VecMView<'a, InflationPayout>), + NotTime, +} + +#[cfg(feature = "alloc")] +impl From<&InflationResultView<'_>> for InflationResult { + #[must_use] + fn from(v: &InflationResultView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + InflationResultView::Success(value) => Self::Success(value.to_vecm()), + InflationResultView::NotTime => Self::NotTime, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for InflationResult { + #[must_use] + fn from(v: InflationResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl InflationResultView<'_> { + #[must_use] + pub const fn discriminant(&self) -> InflationResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => InflationResultCode::Success, + Self::NotTime => InflationResultCode::NotTime, + } + } +} + +impl WriteXdr for InflationResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Success(v) => v.write_xdr(w)?, + Self::NotTime => ().write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/inner_transaction_result.rs b/src/generated/inner_transaction_result.rs index 165ef9896..0363086d9 100644 --- a/src/generated/inner_transaction_result.rs +++ b/src/generated/inner_transaction_result.rs @@ -91,3 +91,44 @@ impl WriteXdr for InnerTransactionResult { }) } } + +/// InnerTransactionResultView is a borrowing equivalent of [`InnerTransactionResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct InnerTransactionResultView<'a> { + pub fee_charged: i64, + pub result: InnerTransactionResultResultView<'a>, + pub ext: InnerTransactionResultExt, +} + +#[cfg(feature = "alloc")] +impl From<&InnerTransactionResultView<'_>> for InnerTransactionResult { + #[must_use] + fn from(v: &InnerTransactionResultView<'_>) -> Self { + Self { + fee_charged: v.fee_charged, + result: (&v.result).into(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for InnerTransactionResult { + #[must_use] + fn from(v: InnerTransactionResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for InnerTransactionResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.fee_charged.write_xdr(w)?; + self.result.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/inner_transaction_result_pair.rs b/src/generated/inner_transaction_result_pair.rs index dcc08cae9..27fa214a5 100644 --- a/src/generated/inner_transaction_result_pair.rs +++ b/src/generated/inner_transaction_result_pair.rs @@ -49,3 +49,41 @@ impl WriteXdr for InnerTransactionResultPair { }) } } + +/// InnerTransactionResultPairView is a borrowing equivalent of [`InnerTransactionResultPair`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct InnerTransactionResultPairView<'a> { + pub transaction_hash: Hash, + pub result: InnerTransactionResultView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&InnerTransactionResultPairView<'_>> for InnerTransactionResultPair { + #[must_use] + fn from(v: &InnerTransactionResultPairView<'_>) -> Self { + Self { + transaction_hash: v.transaction_hash.clone(), + result: (&v.result).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for InnerTransactionResultPair { + #[must_use] + fn from(v: InnerTransactionResultPairView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for InnerTransactionResultPairView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.transaction_hash.write_xdr(w)?; + self.result.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/inner_transaction_result_result.rs b/src/generated/inner_transaction_result_result.rs index 478fa4d40..7232ecc2b 100644 --- a/src/generated/inner_transaction_result_result.rs +++ b/src/generated/inner_transaction_result_result.rs @@ -275,3 +275,126 @@ impl WriteXdr for InnerTransactionResultResult { }) } } + +/// InnerTransactionResultResultView is a borrowing equivalent of [`InnerTransactionResultResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum InnerTransactionResultResultView<'a> { + TxSuccess(VecMView<'a, OperationResultView<'a>>), + TxFailed(VecMView<'a, OperationResultView<'a>>), + TxTooEarly, + TxTooLate, + TxMissingOperation, + TxBadSeq, + TxBadAuth, + TxInsufficientBalance, + TxNoAccount, + TxInsufficientFee, + TxBadAuthExtra, + TxInternalError, + TxNotSupported, + TxBadSponsorship, + TxBadMinSeqAgeOrGap, + TxMalformed, + TxSorobanInvalid, + TxFrozenKeyAccessed, +} + +#[cfg(feature = "alloc")] +impl From<&InnerTransactionResultResultView<'_>> for InnerTransactionResultResult { + #[must_use] + fn from(v: &InnerTransactionResultResultView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + InnerTransactionResultResultView::TxSuccess(value) => { + Self::TxSuccess(value.to_vecm_from()) + } + InnerTransactionResultResultView::TxFailed(value) => { + Self::TxFailed(value.to_vecm_from()) + } + InnerTransactionResultResultView::TxTooEarly => Self::TxTooEarly, + InnerTransactionResultResultView::TxTooLate => Self::TxTooLate, + InnerTransactionResultResultView::TxMissingOperation => Self::TxMissingOperation, + InnerTransactionResultResultView::TxBadSeq => Self::TxBadSeq, + InnerTransactionResultResultView::TxBadAuth => Self::TxBadAuth, + InnerTransactionResultResultView::TxInsufficientBalance => Self::TxInsufficientBalance, + InnerTransactionResultResultView::TxNoAccount => Self::TxNoAccount, + InnerTransactionResultResultView::TxInsufficientFee => Self::TxInsufficientFee, + InnerTransactionResultResultView::TxBadAuthExtra => Self::TxBadAuthExtra, + InnerTransactionResultResultView::TxInternalError => Self::TxInternalError, + InnerTransactionResultResultView::TxNotSupported => Self::TxNotSupported, + InnerTransactionResultResultView::TxBadSponsorship => Self::TxBadSponsorship, + InnerTransactionResultResultView::TxBadMinSeqAgeOrGap => Self::TxBadMinSeqAgeOrGap, + InnerTransactionResultResultView::TxMalformed => Self::TxMalformed, + InnerTransactionResultResultView::TxSorobanInvalid => Self::TxSorobanInvalid, + InnerTransactionResultResultView::TxFrozenKeyAccessed => Self::TxFrozenKeyAccessed, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for InnerTransactionResultResult { + #[must_use] + fn from(v: InnerTransactionResultResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl InnerTransactionResultResultView<'_> { + #[must_use] + pub const fn discriminant(&self) -> TransactionResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::TxSuccess(_) => TransactionResultCode::TxSuccess, + Self::TxFailed(_) => TransactionResultCode::TxFailed, + Self::TxTooEarly => TransactionResultCode::TxTooEarly, + Self::TxTooLate => TransactionResultCode::TxTooLate, + Self::TxMissingOperation => TransactionResultCode::TxMissingOperation, + Self::TxBadSeq => TransactionResultCode::TxBadSeq, + Self::TxBadAuth => TransactionResultCode::TxBadAuth, + Self::TxInsufficientBalance => TransactionResultCode::TxInsufficientBalance, + Self::TxNoAccount => TransactionResultCode::TxNoAccount, + Self::TxInsufficientFee => TransactionResultCode::TxInsufficientFee, + Self::TxBadAuthExtra => TransactionResultCode::TxBadAuthExtra, + Self::TxInternalError => TransactionResultCode::TxInternalError, + Self::TxNotSupported => TransactionResultCode::TxNotSupported, + Self::TxBadSponsorship => TransactionResultCode::TxBadSponsorship, + Self::TxBadMinSeqAgeOrGap => TransactionResultCode::TxBadMinSeqAgeOrGap, + Self::TxMalformed => TransactionResultCode::TxMalformed, + Self::TxSorobanInvalid => TransactionResultCode::TxSorobanInvalid, + Self::TxFrozenKeyAccessed => TransactionResultCode::TxFrozenKeyAccessed, + } + } +} + +impl WriteXdr for InnerTransactionResultResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::TxSuccess(v) => v.write_xdr(w)?, + Self::TxFailed(v) => v.write_xdr(w)?, + Self::TxTooEarly => ().write_xdr(w)?, + Self::TxTooLate => ().write_xdr(w)?, + Self::TxMissingOperation => ().write_xdr(w)?, + Self::TxBadSeq => ().write_xdr(w)?, + Self::TxBadAuth => ().write_xdr(w)?, + Self::TxInsufficientBalance => ().write_xdr(w)?, + Self::TxNoAccount => ().write_xdr(w)?, + Self::TxInsufficientFee => ().write_xdr(w)?, + Self::TxBadAuthExtra => ().write_xdr(w)?, + Self::TxInternalError => ().write_xdr(w)?, + Self::TxNotSupported => ().write_xdr(w)?, + Self::TxBadSponsorship => ().write_xdr(w)?, + Self::TxBadMinSeqAgeOrGap => ().write_xdr(w)?, + Self::TxMalformed => ().write_xdr(w)?, + Self::TxSorobanInvalid => ().write_xdr(w)?, + Self::TxFrozenKeyAccessed => ().write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/invoke_contract_args.rs b/src/generated/invoke_contract_args.rs index 277114327..bcfeca769 100644 --- a/src/generated/invoke_contract_args.rs +++ b/src/generated/invoke_contract_args.rs @@ -52,3 +52,44 @@ impl WriteXdr for InvokeContractArgs { }) } } + +/// InvokeContractArgsView is a borrowing equivalent of [`InvokeContractArgs`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct InvokeContractArgsView<'a> { + pub contract_address: ScAddress, + pub function_name: ScSymbolView<'a>, + pub args: VecMView<'a, ScValView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&InvokeContractArgsView<'_>> for InvokeContractArgs { + #[must_use] + fn from(v: &InvokeContractArgsView<'_>) -> Self { + Self { + contract_address: v.contract_address.clone(), + function_name: (&v.function_name).into(), + args: v.args.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for InvokeContractArgs { + #[must_use] + fn from(v: InvokeContractArgsView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for InvokeContractArgsView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.contract_address.write_xdr(w)?; + self.function_name.write_xdr(w)?; + self.args.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/invoke_host_function_op.rs b/src/generated/invoke_host_function_op.rs index f8377fa90..bda478448 100644 --- a/src/generated/invoke_host_function_op.rs +++ b/src/generated/invoke_host_function_op.rs @@ -51,3 +51,41 @@ impl WriteXdr for InvokeHostFunctionOp { }) } } + +/// InvokeHostFunctionOpView is a borrowing equivalent of [`InvokeHostFunctionOp`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct InvokeHostFunctionOpView<'a> { + pub host_function: HostFunctionView<'a>, + pub auth: VecMView<'a, SorobanAuthorizationEntryView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&InvokeHostFunctionOpView<'_>> for InvokeHostFunctionOp { + #[must_use] + fn from(v: &InvokeHostFunctionOpView<'_>) -> Self { + Self { + host_function: (&v.host_function).into(), + auth: v.auth.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for InvokeHostFunctionOp { + #[must_use] + fn from(v: InvokeHostFunctionOpView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for InvokeHostFunctionOpView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.host_function.write_xdr(w)?; + self.auth.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/invoke_host_function_success_pre_image.rs b/src/generated/invoke_host_function_success_pre_image.rs index 9caa1011f..5de523774 100644 --- a/src/generated/invoke_host_function_success_pre_image.rs +++ b/src/generated/invoke_host_function_success_pre_image.rs @@ -49,3 +49,41 @@ impl WriteXdr for InvokeHostFunctionSuccessPreImage { }) } } + +/// InvokeHostFunctionSuccessPreImageView is a borrowing equivalent of [`InvokeHostFunctionSuccessPreImage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct InvokeHostFunctionSuccessPreImageView<'a> { + pub return_value: ScValView<'a>, + pub events: VecMView<'a, ContractEventView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&InvokeHostFunctionSuccessPreImageView<'_>> for InvokeHostFunctionSuccessPreImage { + #[must_use] + fn from(v: &InvokeHostFunctionSuccessPreImageView<'_>) -> Self { + Self { + return_value: (&v.return_value).into(), + events: v.events.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for InvokeHostFunctionSuccessPreImage { + #[must_use] + fn from(v: InvokeHostFunctionSuccessPreImageView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for InvokeHostFunctionSuccessPreImageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.return_value.write_xdr(w)?; + self.events.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_close_meta.rs b/src/generated/ledger_close_meta.rs index 7ba1a97a3..37b29ac86 100644 --- a/src/generated/ledger_close_meta.rs +++ b/src/generated/ledger_close_meta.rs @@ -142,3 +142,62 @@ impl WriteXdr for LedgerCloseMeta { }) } } + +/// LedgerCloseMetaView is a borrowing equivalent of [`LedgerCloseMeta`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum LedgerCloseMetaView<'a> { + V0(LedgerCloseMetaV0View<'a>), + V1(LedgerCloseMetaV1View<'a>), + V2(LedgerCloseMetaV2View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&LedgerCloseMetaView<'_>> for LedgerCloseMeta { + #[must_use] + fn from(v: &LedgerCloseMetaView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + LedgerCloseMetaView::V0(value) => Self::V0(value.into()), + LedgerCloseMetaView::V1(value) => Self::V1(value.into()), + LedgerCloseMetaView::V2(value) => Self::V2(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerCloseMeta { + #[must_use] + fn from(v: LedgerCloseMetaView<'_>) -> Self { + Self::from(&v) + } +} + +impl LedgerCloseMetaView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + Self::V2(_) => 2, + } + } +} + +impl WriteXdr for LedgerCloseMetaView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0(v) => v.write_xdr(w)?, + Self::V1(v) => v.write_xdr(w)?, + Self::V2(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_close_meta_batch.rs b/src/generated/ledger_close_meta_batch.rs index 424e2ab2b..058d6a7a5 100644 --- a/src/generated/ledger_close_meta_batch.rs +++ b/src/generated/ledger_close_meta_batch.rs @@ -58,3 +58,44 @@ impl WriteXdr for LedgerCloseMetaBatch { }) } } + +/// LedgerCloseMetaBatchView is a borrowing equivalent of [`LedgerCloseMetaBatch`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerCloseMetaBatchView<'a> { + pub start_sequence: u32, + pub end_sequence: u32, + pub ledger_close_metas: VecMView<'a, LedgerCloseMetaView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerCloseMetaBatchView<'_>> for LedgerCloseMetaBatch { + #[must_use] + fn from(v: &LedgerCloseMetaBatchView<'_>) -> Self { + Self { + start_sequence: v.start_sequence, + end_sequence: v.end_sequence, + ledger_close_metas: v.ledger_close_metas.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerCloseMetaBatch { + #[must_use] + fn from(v: LedgerCloseMetaBatchView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerCloseMetaBatchView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.start_sequence.write_xdr(w)?; + self.end_sequence.write_xdr(w)?; + self.ledger_close_metas.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_close_meta_v0.rs b/src/generated/ledger_close_meta_v0.rs index 5449e08b2..6ec2ba878 100644 --- a/src/generated/ledger_close_meta_v0.rs +++ b/src/generated/ledger_close_meta_v0.rs @@ -70,3 +70,50 @@ impl WriteXdr for LedgerCloseMetaV0 { }) } } + +/// LedgerCloseMetaV0View is a borrowing equivalent of [`LedgerCloseMetaV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerCloseMetaV0View<'a> { + pub ledger_header: LedgerHeaderHistoryEntryView<'a>, + pub tx_set: TransactionSetView<'a>, + pub tx_processing: VecMView<'a, TransactionResultMetaView<'a>>, + pub upgrades_processing: VecMView<'a, UpgradeEntryMetaView<'a>>, + pub scp_info: VecMView<'a, ScpHistoryEntryView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerCloseMetaV0View<'_>> for LedgerCloseMetaV0 { + #[must_use] + fn from(v: &LedgerCloseMetaV0View<'_>) -> Self { + Self { + ledger_header: (&v.ledger_header).into(), + tx_set: (&v.tx_set).into(), + tx_processing: v.tx_processing.to_vecm_from(), + upgrades_processing: v.upgrades_processing.to_vecm_from(), + scp_info: v.scp_info.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerCloseMetaV0 { + #[must_use] + fn from(v: LedgerCloseMetaV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerCloseMetaV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ledger_header.write_xdr(w)?; + self.tx_set.write_xdr(w)?; + self.tx_processing.write_xdr(w)?; + self.upgrades_processing.write_xdr(w)?; + self.scp_info.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_close_meta_v1.rs b/src/generated/ledger_close_meta_v1.rs index 323c9f307..0f14e5a26 100644 --- a/src/generated/ledger_close_meta_v1.rs +++ b/src/generated/ledger_close_meta_v1.rs @@ -98,3 +98,62 @@ impl WriteXdr for LedgerCloseMetaV1 { }) } } + +/// LedgerCloseMetaV1View is a borrowing equivalent of [`LedgerCloseMetaV1`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerCloseMetaV1View<'a> { + pub ext: LedgerCloseMetaExt, + pub ledger_header: LedgerHeaderHistoryEntryView<'a>, + pub tx_set: GeneralizedTransactionSetView<'a>, + pub tx_processing: VecMView<'a, TransactionResultMetaView<'a>>, + pub upgrades_processing: VecMView<'a, UpgradeEntryMetaView<'a>>, + pub scp_info: VecMView<'a, ScpHistoryEntryView<'a>>, + pub total_byte_size_of_live_soroban_state: u64, + pub evicted_keys: VecMView<'a, LedgerKeyView<'a>>, + pub unused: VecMView<'a, LedgerEntryView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerCloseMetaV1View<'_>> for LedgerCloseMetaV1 { + #[must_use] + fn from(v: &LedgerCloseMetaV1View<'_>) -> Self { + Self { + ext: v.ext.clone(), + ledger_header: (&v.ledger_header).into(), + tx_set: (&v.tx_set).into(), + tx_processing: v.tx_processing.to_vecm_from(), + upgrades_processing: v.upgrades_processing.to_vecm_from(), + scp_info: v.scp_info.to_vecm_from(), + total_byte_size_of_live_soroban_state: v.total_byte_size_of_live_soroban_state, + evicted_keys: v.evicted_keys.to_vecm_from(), + unused: v.unused.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerCloseMetaV1 { + #[must_use] + fn from(v: LedgerCloseMetaV1View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerCloseMetaV1View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.ledger_header.write_xdr(w)?; + self.tx_set.write_xdr(w)?; + self.tx_processing.write_xdr(w)?; + self.upgrades_processing.write_xdr(w)?; + self.scp_info.write_xdr(w)?; + self.total_byte_size_of_live_soroban_state.write_xdr(w)?; + self.evicted_keys.write_xdr(w)?; + self.unused.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_close_meta_v2.rs b/src/generated/ledger_close_meta_v2.rs index e27678110..01c81ec93 100644 --- a/src/generated/ledger_close_meta_v2.rs +++ b/src/generated/ledger_close_meta_v2.rs @@ -92,3 +92,59 @@ impl WriteXdr for LedgerCloseMetaV2 { }) } } + +/// LedgerCloseMetaV2View is a borrowing equivalent of [`LedgerCloseMetaV2`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerCloseMetaV2View<'a> { + pub ext: LedgerCloseMetaExt, + pub ledger_header: LedgerHeaderHistoryEntryView<'a>, + pub tx_set: GeneralizedTransactionSetView<'a>, + pub tx_processing: VecMView<'a, TransactionResultMetaV1View<'a>>, + pub upgrades_processing: VecMView<'a, UpgradeEntryMetaView<'a>>, + pub scp_info: VecMView<'a, ScpHistoryEntryView<'a>>, + pub total_byte_size_of_live_soroban_state: u64, + pub evicted_keys: VecMView<'a, LedgerKeyView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerCloseMetaV2View<'_>> for LedgerCloseMetaV2 { + #[must_use] + fn from(v: &LedgerCloseMetaV2View<'_>) -> Self { + Self { + ext: v.ext.clone(), + ledger_header: (&v.ledger_header).into(), + tx_set: (&v.tx_set).into(), + tx_processing: v.tx_processing.to_vecm_from(), + upgrades_processing: v.upgrades_processing.to_vecm_from(), + scp_info: v.scp_info.to_vecm_from(), + total_byte_size_of_live_soroban_state: v.total_byte_size_of_live_soroban_state, + evicted_keys: v.evicted_keys.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerCloseMetaV2 { + #[must_use] + fn from(v: LedgerCloseMetaV2View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerCloseMetaV2View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.ledger_header.write_xdr(w)?; + self.tx_set.write_xdr(w)?; + self.tx_processing.write_xdr(w)?; + self.upgrades_processing.write_xdr(w)?; + self.scp_info.write_xdr(w)?; + self.total_byte_size_of_live_soroban_state.write_xdr(w)?; + self.evicted_keys.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_close_value_signature.rs b/src/generated/ledger_close_value_signature.rs index 9fc1549ff..a3bb52e98 100644 --- a/src/generated/ledger_close_value_signature.rs +++ b/src/generated/ledger_close_value_signature.rs @@ -49,3 +49,41 @@ impl WriteXdr for LedgerCloseValueSignature { }) } } + +/// LedgerCloseValueSignatureView is a borrowing equivalent of [`LedgerCloseValueSignature`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerCloseValueSignatureView<'a> { + pub node_id: NodeId, + pub signature: SignatureView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerCloseValueSignatureView<'_>> for LedgerCloseValueSignature { + #[must_use] + fn from(v: &LedgerCloseValueSignatureView<'_>) -> Self { + Self { + node_id: v.node_id.clone(), + signature: (&v.signature).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerCloseValueSignature { + #[must_use] + fn from(v: LedgerCloseValueSignatureView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerCloseValueSignatureView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.node_id.write_xdr(w)?; + self.signature.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_entry.rs b/src/generated/ledger_entry.rs index 9a1e7bf13..7550ad7f6 100644 --- a/src/generated/ledger_entry.rs +++ b/src/generated/ledger_entry.rs @@ -86,3 +86,44 @@ impl WriteXdr for LedgerEntry { }) } } + +/// LedgerEntryView is a borrowing equivalent of [`LedgerEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerEntryView<'a> { + pub last_modified_ledger_seq: u32, + pub data: LedgerEntryDataView<'a>, + pub ext: LedgerEntryExt, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerEntryView<'_>> for LedgerEntry { + #[must_use] + fn from(v: &LedgerEntryView<'_>) -> Self { + Self { + last_modified_ledger_seq: v.last_modified_ledger_seq, + data: (&v.data).into(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerEntry { + #[must_use] + fn from(v: LedgerEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.last_modified_ledger_seq.write_xdr(w)?; + self.data.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_entry_change.rs b/src/generated/ledger_entry_change.rs index 20e66f654..928c8f56b 100644 --- a/src/generated/ledger_entry_change.rs +++ b/src/generated/ledger_entry_change.rs @@ -162,3 +162,70 @@ impl WriteXdr for LedgerEntryChange { }) } } + +/// LedgerEntryChangeView is a borrowing equivalent of [`LedgerEntryChange`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum LedgerEntryChangeView<'a> { + Created(LedgerEntryView<'a>), + Updated(LedgerEntryView<'a>), + Removed(LedgerKeyView<'a>), + State(LedgerEntryView<'a>), + Restored(LedgerEntryView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&LedgerEntryChangeView<'_>> for LedgerEntryChange { + #[must_use] + fn from(v: &LedgerEntryChangeView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + LedgerEntryChangeView::Created(value) => Self::Created(value.into()), + LedgerEntryChangeView::Updated(value) => Self::Updated(value.into()), + LedgerEntryChangeView::Removed(value) => Self::Removed(value.into()), + LedgerEntryChangeView::State(value) => Self::State(value.into()), + LedgerEntryChangeView::Restored(value) => Self::Restored(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerEntryChange { + #[must_use] + fn from(v: LedgerEntryChangeView<'_>) -> Self { + Self::from(&v) + } +} + +impl LedgerEntryChangeView<'_> { + #[must_use] + pub const fn discriminant(&self) -> LedgerEntryChangeType { + #[allow(clippy::match_same_arms)] + match self { + Self::Created(_) => LedgerEntryChangeType::Created, + Self::Updated(_) => LedgerEntryChangeType::Updated, + Self::Removed(_) => LedgerEntryChangeType::Removed, + Self::State(_) => LedgerEntryChangeType::State, + Self::Restored(_) => LedgerEntryChangeType::Restored, + } + } +} + +impl WriteXdr for LedgerEntryChangeView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Created(v) => v.write_xdr(w)?, + Self::Updated(v) => v.write_xdr(w)?, + Self::Removed(v) => v.write_xdr(w)?, + Self::State(v) => v.write_xdr(w)?, + Self::Restored(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_entry_changes.rs b/src/generated/ledger_entry_changes.rs index e2e949c5a..1e57bd6b9 100644 --- a/src/generated/ledger_entry_changes.rs +++ b/src/generated/ledger_entry_changes.rs @@ -107,3 +107,31 @@ impl AsRef<[LedgerEntryChange]> for LedgerEntryChanges { self.0 .0 } } + +/// LedgerEntryChangesView is a borrowing equivalent of [`LedgerEntryChanges`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerEntryChangesView<'a>(pub VecMView<'a, LedgerEntryChangeView<'a>>); + +#[cfg(feature = "alloc")] +impl From<&LedgerEntryChangesView<'_>> for LedgerEntryChanges { + #[must_use] + fn from(v: &LedgerEntryChangesView<'_>) -> Self { + Self(v.0.to_vecm_from()) + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerEntryChanges { + #[must_use] + fn from(v: LedgerEntryChangesView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerEntryChangesView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/ledger_entry_data.rs b/src/generated/ledger_entry_data.rs index a9c58d52b..396132a58 100644 --- a/src/generated/ledger_entry_data.rs +++ b/src/generated/ledger_entry_data.rs @@ -223,3 +223,90 @@ impl WriteXdr for LedgerEntryData { }) } } + +/// LedgerEntryDataView is a borrowing equivalent of [`LedgerEntryData`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum LedgerEntryDataView<'a> { + Account(AccountEntryView<'a>), + Trustline(TrustLineEntry), + Offer(OfferEntry), + Data(DataEntryView<'a>), + ClaimableBalance(ClaimableBalanceEntryView<'a>), + LiquidityPool(LiquidityPoolEntry), + ContractData(ContractDataEntryView<'a>), + ContractCode(ContractCodeEntryView<'a>), + ConfigSetting(ConfigSettingEntryView<'a>), + Ttl(TtlEntry), +} + +#[cfg(feature = "alloc")] +impl From<&LedgerEntryDataView<'_>> for LedgerEntryData { + #[must_use] + fn from(v: &LedgerEntryDataView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + LedgerEntryDataView::Account(value) => Self::Account(value.into()), + LedgerEntryDataView::Trustline(value) => Self::Trustline(value.clone()), + LedgerEntryDataView::Offer(value) => Self::Offer(value.clone()), + LedgerEntryDataView::Data(value) => Self::Data(value.into()), + LedgerEntryDataView::ClaimableBalance(value) => Self::ClaimableBalance(value.into()), + LedgerEntryDataView::LiquidityPool(value) => Self::LiquidityPool(value.clone()), + LedgerEntryDataView::ContractData(value) => Self::ContractData(value.into()), + LedgerEntryDataView::ContractCode(value) => Self::ContractCode(value.into()), + LedgerEntryDataView::ConfigSetting(value) => Self::ConfigSetting(value.into()), + LedgerEntryDataView::Ttl(value) => Self::Ttl(value.clone()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerEntryData { + #[must_use] + fn from(v: LedgerEntryDataView<'_>) -> Self { + Self::from(&v) + } +} + +impl LedgerEntryDataView<'_> { + #[must_use] + pub const fn discriminant(&self) -> LedgerEntryType { + #[allow(clippy::match_same_arms)] + match self { + Self::Account(_) => LedgerEntryType::Account, + Self::Trustline(_) => LedgerEntryType::Trustline, + Self::Offer(_) => LedgerEntryType::Offer, + Self::Data(_) => LedgerEntryType::Data, + Self::ClaimableBalance(_) => LedgerEntryType::ClaimableBalance, + Self::LiquidityPool(_) => LedgerEntryType::LiquidityPool, + Self::ContractData(_) => LedgerEntryType::ContractData, + Self::ContractCode(_) => LedgerEntryType::ContractCode, + Self::ConfigSetting(_) => LedgerEntryType::ConfigSetting, + Self::Ttl(_) => LedgerEntryType::Ttl, + } + } +} + +impl WriteXdr for LedgerEntryDataView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Account(v) => v.write_xdr(w)?, + Self::Trustline(v) => v.write_xdr(w)?, + Self::Offer(v) => v.write_xdr(w)?, + Self::Data(v) => v.write_xdr(w)?, + Self::ClaimableBalance(v) => v.write_xdr(w)?, + Self::LiquidityPool(v) => v.write_xdr(w)?, + Self::ContractData(v) => v.write_xdr(w)?, + Self::ContractCode(v) => v.write_xdr(w)?, + Self::ConfigSetting(v) => v.write_xdr(w)?, + Self::Ttl(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_footprint.rs b/src/generated/ledger_footprint.rs index a2b262c19..56c57ee33 100644 --- a/src/generated/ledger_footprint.rs +++ b/src/generated/ledger_footprint.rs @@ -49,3 +49,41 @@ impl WriteXdr for LedgerFootprint { }) } } + +/// LedgerFootprintView is a borrowing equivalent of [`LedgerFootprint`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerFootprintView<'a> { + pub read_only: VecMView<'a, LedgerKeyView<'a>>, + pub read_write: VecMView<'a, LedgerKeyView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerFootprintView<'_>> for LedgerFootprint { + #[must_use] + fn from(v: &LedgerFootprintView<'_>) -> Self { + Self { + read_only: v.read_only.to_vecm_from(), + read_write: v.read_write.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerFootprint { + #[must_use] + fn from(v: LedgerFootprintView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerFootprintView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.read_only.write_xdr(w)?; + self.read_write.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_header.rs b/src/generated/ledger_header.rs index 61bb4e686..a885940e1 100644 --- a/src/generated/ledger_header.rs +++ b/src/generated/ledger_header.rs @@ -134,3 +134,80 @@ impl WriteXdr for LedgerHeader { }) } } + +/// LedgerHeaderView is a borrowing equivalent of [`LedgerHeader`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerHeaderView<'a> { + pub ledger_version: u32, + pub previous_ledger_hash: Hash, + pub scp_value: StellarValueView<'a>, + pub tx_set_result_hash: Hash, + pub bucket_list_hash: Hash, + pub ledger_seq: u32, + pub total_coins: i64, + pub fee_pool: i64, + pub inflation_seq: u32, + pub id_pool: u64, + pub base_fee: u32, + pub base_reserve: u32, + pub max_tx_set_size: u32, + pub skip_list: [Hash; 4], + pub ext: LedgerHeaderExt, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerHeaderView<'_>> for LedgerHeader { + #[must_use] + fn from(v: &LedgerHeaderView<'_>) -> Self { + Self { + ledger_version: v.ledger_version, + previous_ledger_hash: v.previous_ledger_hash.clone(), + scp_value: (&v.scp_value).into(), + tx_set_result_hash: v.tx_set_result_hash.clone(), + bucket_list_hash: v.bucket_list_hash.clone(), + ledger_seq: v.ledger_seq, + total_coins: v.total_coins, + fee_pool: v.fee_pool, + inflation_seq: v.inflation_seq, + id_pool: v.id_pool, + base_fee: v.base_fee, + base_reserve: v.base_reserve, + max_tx_set_size: v.max_tx_set_size, + skip_list: v.skip_list.clone(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerHeader { + #[must_use] + fn from(v: LedgerHeaderView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerHeaderView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ledger_version.write_xdr(w)?; + self.previous_ledger_hash.write_xdr(w)?; + self.scp_value.write_xdr(w)?; + self.tx_set_result_hash.write_xdr(w)?; + self.bucket_list_hash.write_xdr(w)?; + self.ledger_seq.write_xdr(w)?; + self.total_coins.write_xdr(w)?; + self.fee_pool.write_xdr(w)?; + self.inflation_seq.write_xdr(w)?; + self.id_pool.write_xdr(w)?; + self.base_fee.write_xdr(w)?; + self.base_reserve.write_xdr(w)?; + self.max_tx_set_size.write_xdr(w)?; + self.skip_list.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_header_history_entry.rs b/src/generated/ledger_header_history_entry.rs index 963fdcdc8..91780b1b1 100644 --- a/src/generated/ledger_header_history_entry.rs +++ b/src/generated/ledger_header_history_entry.rs @@ -60,3 +60,44 @@ impl WriteXdr for LedgerHeaderHistoryEntry { }) } } + +/// LedgerHeaderHistoryEntryView is a borrowing equivalent of [`LedgerHeaderHistoryEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerHeaderHistoryEntryView<'a> { + pub hash: Hash, + pub header: LedgerHeaderView<'a>, + pub ext: LedgerHeaderHistoryEntryExt, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerHeaderHistoryEntryView<'_>> for LedgerHeaderHistoryEntry { + #[must_use] + fn from(v: &LedgerHeaderHistoryEntryView<'_>) -> Self { + Self { + hash: v.hash.clone(), + header: (&v.header).into(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerHeaderHistoryEntry { + #[must_use] + fn from(v: LedgerHeaderHistoryEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerHeaderHistoryEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.hash.write_xdr(w)?; + self.header.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_key.rs b/src/generated/ledger_key.rs index 5dc5ef28a..84b0ee39b 100644 --- a/src/generated/ledger_key.rs +++ b/src/generated/ledger_key.rs @@ -264,3 +264,90 @@ impl WriteXdr for LedgerKey { }) } } + +/// LedgerKeyView is a borrowing equivalent of [`LedgerKey`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum LedgerKeyView<'a> { + Account(LedgerKeyAccount), + Trustline(LedgerKeyTrustLine), + Offer(LedgerKeyOffer), + Data(LedgerKeyDataView<'a>), + ClaimableBalance(LedgerKeyClaimableBalance), + LiquidityPool(LedgerKeyLiquidityPool), + ContractData(LedgerKeyContractDataView<'a>), + ContractCode(LedgerKeyContractCode), + ConfigSetting(LedgerKeyConfigSetting), + Ttl(LedgerKeyTtl), +} + +#[cfg(feature = "alloc")] +impl From<&LedgerKeyView<'_>> for LedgerKey { + #[must_use] + fn from(v: &LedgerKeyView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + LedgerKeyView::Account(value) => Self::Account(value.clone()), + LedgerKeyView::Trustline(value) => Self::Trustline(value.clone()), + LedgerKeyView::Offer(value) => Self::Offer(value.clone()), + LedgerKeyView::Data(value) => Self::Data(value.into()), + LedgerKeyView::ClaimableBalance(value) => Self::ClaimableBalance(value.clone()), + LedgerKeyView::LiquidityPool(value) => Self::LiquidityPool(value.clone()), + LedgerKeyView::ContractData(value) => Self::ContractData(value.into()), + LedgerKeyView::ContractCode(value) => Self::ContractCode(value.clone()), + LedgerKeyView::ConfigSetting(value) => Self::ConfigSetting(value.clone()), + LedgerKeyView::Ttl(value) => Self::Ttl(value.clone()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerKey { + #[must_use] + fn from(v: LedgerKeyView<'_>) -> Self { + Self::from(&v) + } +} + +impl LedgerKeyView<'_> { + #[must_use] + pub const fn discriminant(&self) -> LedgerEntryType { + #[allow(clippy::match_same_arms)] + match self { + Self::Account(_) => LedgerEntryType::Account, + Self::Trustline(_) => LedgerEntryType::Trustline, + Self::Offer(_) => LedgerEntryType::Offer, + Self::Data(_) => LedgerEntryType::Data, + Self::ClaimableBalance(_) => LedgerEntryType::ClaimableBalance, + Self::LiquidityPool(_) => LedgerEntryType::LiquidityPool, + Self::ContractData(_) => LedgerEntryType::ContractData, + Self::ContractCode(_) => LedgerEntryType::ContractCode, + Self::ConfigSetting(_) => LedgerEntryType::ConfigSetting, + Self::Ttl(_) => LedgerEntryType::Ttl, + } + } +} + +impl WriteXdr for LedgerKeyView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Account(v) => v.write_xdr(w)?, + Self::Trustline(v) => v.write_xdr(w)?, + Self::Offer(v) => v.write_xdr(w)?, + Self::Data(v) => v.write_xdr(w)?, + Self::ClaimableBalance(v) => v.write_xdr(w)?, + Self::LiquidityPool(v) => v.write_xdr(w)?, + Self::ContractData(v) => v.write_xdr(w)?, + Self::ContractCode(v) => v.write_xdr(w)?, + Self::ConfigSetting(v) => v.write_xdr(w)?, + Self::Ttl(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_key_contract_data.rs b/src/generated/ledger_key_contract_data.rs index 74174e644..f5d5e4d3d 100644 --- a/src/generated/ledger_key_contract_data.rs +++ b/src/generated/ledger_key_contract_data.rs @@ -53,3 +53,44 @@ impl WriteXdr for LedgerKeyContractData { }) } } + +/// LedgerKeyContractDataView is a borrowing equivalent of [`LedgerKeyContractData`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerKeyContractDataView<'a> { + pub contract: ScAddress, + pub key: ScValView<'a>, + pub durability: ContractDataDurability, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerKeyContractDataView<'_>> for LedgerKeyContractData { + #[must_use] + fn from(v: &LedgerKeyContractDataView<'_>) -> Self { + Self { + contract: v.contract.clone(), + key: (&v.key).into(), + durability: v.durability, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerKeyContractData { + #[must_use] + fn from(v: LedgerKeyContractDataView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerKeyContractDataView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.contract.write_xdr(w)?; + self.key.write_xdr(w)?; + self.durability.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_key_data.rs b/src/generated/ledger_key_data.rs index 00236df6d..d54096c32 100644 --- a/src/generated/ledger_key_data.rs +++ b/src/generated/ledger_key_data.rs @@ -49,3 +49,41 @@ impl WriteXdr for LedgerKeyData { }) } } + +/// LedgerKeyDataView is a borrowing equivalent of [`LedgerKeyData`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerKeyDataView<'a> { + pub account_id: AccountId, + pub data_name: String64View<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerKeyDataView<'_>> for LedgerKeyData { + #[must_use] + fn from(v: &LedgerKeyDataView<'_>) -> Self { + Self { + account_id: v.account_id.clone(), + data_name: (&v.data_name).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerKeyData { + #[must_use] + fn from(v: LedgerKeyDataView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerKeyDataView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.account_id.write_xdr(w)?; + self.data_name.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/ledger_scp_messages.rs b/src/generated/ledger_scp_messages.rs index 8298b3592..f025ac477 100644 --- a/src/generated/ledger_scp_messages.rs +++ b/src/generated/ledger_scp_messages.rs @@ -49,3 +49,41 @@ impl WriteXdr for LedgerScpMessages { }) } } + +/// LedgerScpMessagesView is a borrowing equivalent of [`LedgerScpMessages`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct LedgerScpMessagesView<'a> { + pub ledger_seq: u32, + pub messages: VecMView<'a, ScpEnvelopeView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&LedgerScpMessagesView<'_>> for LedgerScpMessages { + #[must_use] + fn from(v: &LedgerScpMessagesView<'_>) -> Self { + Self { + ledger_seq: v.ledger_seq, + messages: v.messages.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for LedgerScpMessages { + #[must_use] + fn from(v: LedgerScpMessagesView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for LedgerScpMessagesView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ledger_seq.write_xdr(w)?; + self.messages.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/manage_buy_offer_result.rs b/src/generated/manage_buy_offer_result.rs index c78376365..5907c5d7a 100644 --- a/src/generated/manage_buy_offer_result.rs +++ b/src/generated/manage_buy_offer_result.rs @@ -231,3 +231,102 @@ impl WriteXdr for ManageBuyOfferResult { }) } } + +/// ManageBuyOfferResultView is a borrowing equivalent of [`ManageBuyOfferResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ManageBuyOfferResultView<'a> { + Success(ManageOfferSuccessResultView<'a>), + Malformed, + SellNoTrust, + BuyNoTrust, + SellNotAuthorized, + BuyNotAuthorized, + LineFull, + Underfunded, + CrossSelf, + SellNoIssuer, + BuyNoIssuer, + NotFound, + LowReserve, +} + +#[cfg(feature = "alloc")] +impl From<&ManageBuyOfferResultView<'_>> for ManageBuyOfferResult { + #[must_use] + fn from(v: &ManageBuyOfferResultView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ManageBuyOfferResultView::Success(value) => Self::Success(value.into()), + ManageBuyOfferResultView::Malformed => Self::Malformed, + ManageBuyOfferResultView::SellNoTrust => Self::SellNoTrust, + ManageBuyOfferResultView::BuyNoTrust => Self::BuyNoTrust, + ManageBuyOfferResultView::SellNotAuthorized => Self::SellNotAuthorized, + ManageBuyOfferResultView::BuyNotAuthorized => Self::BuyNotAuthorized, + ManageBuyOfferResultView::LineFull => Self::LineFull, + ManageBuyOfferResultView::Underfunded => Self::Underfunded, + ManageBuyOfferResultView::CrossSelf => Self::CrossSelf, + ManageBuyOfferResultView::SellNoIssuer => Self::SellNoIssuer, + ManageBuyOfferResultView::BuyNoIssuer => Self::BuyNoIssuer, + ManageBuyOfferResultView::NotFound => Self::NotFound, + ManageBuyOfferResultView::LowReserve => Self::LowReserve, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ManageBuyOfferResult { + #[must_use] + fn from(v: ManageBuyOfferResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl ManageBuyOfferResultView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ManageBuyOfferResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => ManageBuyOfferResultCode::Success, + Self::Malformed => ManageBuyOfferResultCode::Malformed, + Self::SellNoTrust => ManageBuyOfferResultCode::SellNoTrust, + Self::BuyNoTrust => ManageBuyOfferResultCode::BuyNoTrust, + Self::SellNotAuthorized => ManageBuyOfferResultCode::SellNotAuthorized, + Self::BuyNotAuthorized => ManageBuyOfferResultCode::BuyNotAuthorized, + Self::LineFull => ManageBuyOfferResultCode::LineFull, + Self::Underfunded => ManageBuyOfferResultCode::Underfunded, + Self::CrossSelf => ManageBuyOfferResultCode::CrossSelf, + Self::SellNoIssuer => ManageBuyOfferResultCode::SellNoIssuer, + Self::BuyNoIssuer => ManageBuyOfferResultCode::BuyNoIssuer, + Self::NotFound => ManageBuyOfferResultCode::NotFound, + Self::LowReserve => ManageBuyOfferResultCode::LowReserve, + } + } +} + +impl WriteXdr for ManageBuyOfferResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Success(v) => v.write_xdr(w)?, + Self::Malformed => ().write_xdr(w)?, + Self::SellNoTrust => ().write_xdr(w)?, + Self::BuyNoTrust => ().write_xdr(w)?, + Self::SellNotAuthorized => ().write_xdr(w)?, + Self::BuyNotAuthorized => ().write_xdr(w)?, + Self::LineFull => ().write_xdr(w)?, + Self::Underfunded => ().write_xdr(w)?, + Self::CrossSelf => ().write_xdr(w)?, + Self::SellNoIssuer => ().write_xdr(w)?, + Self::BuyNoIssuer => ().write_xdr(w)?, + Self::NotFound => ().write_xdr(w)?, + Self::LowReserve => ().write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/manage_data_op.rs b/src/generated/manage_data_op.rs index 07db773fb..9a9733f97 100644 --- a/src/generated/manage_data_op.rs +++ b/src/generated/manage_data_op.rs @@ -49,3 +49,41 @@ impl WriteXdr for ManageDataOp { }) } } + +/// ManageDataOpView is a borrowing equivalent of [`ManageDataOp`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ManageDataOpView<'a> { + pub data_name: String64View<'a>, + pub data_value: Option>, +} + +#[cfg(feature = "alloc")] +impl From<&ManageDataOpView<'_>> for ManageDataOp { + #[must_use] + fn from(v: &ManageDataOpView<'_>) -> Self { + Self { + data_name: (&v.data_name).into(), + data_value: v.data_value.as_ref().map(Into::into), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ManageDataOp { + #[must_use] + fn from(v: ManageDataOpView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ManageDataOpView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.data_name.write_xdr(w)?; + self.data_value.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/manage_offer_success_result.rs b/src/generated/manage_offer_success_result.rs index bf7458c5d..28193da91 100644 --- a/src/generated/manage_offer_success_result.rs +++ b/src/generated/manage_offer_success_result.rs @@ -59,3 +59,41 @@ impl WriteXdr for ManageOfferSuccessResult { }) } } + +/// ManageOfferSuccessResultView is a borrowing equivalent of [`ManageOfferSuccessResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ManageOfferSuccessResultView<'a> { + pub offers_claimed: VecMView<'a, ClaimAtom>, + pub offer: ManageOfferSuccessResultOffer, +} + +#[cfg(feature = "alloc")] +impl From<&ManageOfferSuccessResultView<'_>> for ManageOfferSuccessResult { + #[must_use] + fn from(v: &ManageOfferSuccessResultView<'_>) -> Self { + Self { + offers_claimed: v.offers_claimed.to_vecm(), + offer: v.offer.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ManageOfferSuccessResult { + #[must_use] + fn from(v: ManageOfferSuccessResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ManageOfferSuccessResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.offers_claimed.write_xdr(w)?; + self.offer.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/manage_sell_offer_result.rs b/src/generated/manage_sell_offer_result.rs index 6e9371a7e..55975189e 100644 --- a/src/generated/manage_sell_offer_result.rs +++ b/src/generated/manage_sell_offer_result.rs @@ -232,3 +232,102 @@ impl WriteXdr for ManageSellOfferResult { }) } } + +/// ManageSellOfferResultView is a borrowing equivalent of [`ManageSellOfferResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ManageSellOfferResultView<'a> { + Success(ManageOfferSuccessResultView<'a>), + Malformed, + SellNoTrust, + BuyNoTrust, + SellNotAuthorized, + BuyNotAuthorized, + LineFull, + Underfunded, + CrossSelf, + SellNoIssuer, + BuyNoIssuer, + NotFound, + LowReserve, +} + +#[cfg(feature = "alloc")] +impl From<&ManageSellOfferResultView<'_>> for ManageSellOfferResult { + #[must_use] + fn from(v: &ManageSellOfferResultView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ManageSellOfferResultView::Success(value) => Self::Success(value.into()), + ManageSellOfferResultView::Malformed => Self::Malformed, + ManageSellOfferResultView::SellNoTrust => Self::SellNoTrust, + ManageSellOfferResultView::BuyNoTrust => Self::BuyNoTrust, + ManageSellOfferResultView::SellNotAuthorized => Self::SellNotAuthorized, + ManageSellOfferResultView::BuyNotAuthorized => Self::BuyNotAuthorized, + ManageSellOfferResultView::LineFull => Self::LineFull, + ManageSellOfferResultView::Underfunded => Self::Underfunded, + ManageSellOfferResultView::CrossSelf => Self::CrossSelf, + ManageSellOfferResultView::SellNoIssuer => Self::SellNoIssuer, + ManageSellOfferResultView::BuyNoIssuer => Self::BuyNoIssuer, + ManageSellOfferResultView::NotFound => Self::NotFound, + ManageSellOfferResultView::LowReserve => Self::LowReserve, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ManageSellOfferResult { + #[must_use] + fn from(v: ManageSellOfferResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl ManageSellOfferResultView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ManageSellOfferResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => ManageSellOfferResultCode::Success, + Self::Malformed => ManageSellOfferResultCode::Malformed, + Self::SellNoTrust => ManageSellOfferResultCode::SellNoTrust, + Self::BuyNoTrust => ManageSellOfferResultCode::BuyNoTrust, + Self::SellNotAuthorized => ManageSellOfferResultCode::SellNotAuthorized, + Self::BuyNotAuthorized => ManageSellOfferResultCode::BuyNotAuthorized, + Self::LineFull => ManageSellOfferResultCode::LineFull, + Self::Underfunded => ManageSellOfferResultCode::Underfunded, + Self::CrossSelf => ManageSellOfferResultCode::CrossSelf, + Self::SellNoIssuer => ManageSellOfferResultCode::SellNoIssuer, + Self::BuyNoIssuer => ManageSellOfferResultCode::BuyNoIssuer, + Self::NotFound => ManageSellOfferResultCode::NotFound, + Self::LowReserve => ManageSellOfferResultCode::LowReserve, + } + } +} + +impl WriteXdr for ManageSellOfferResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Success(v) => v.write_xdr(w)?, + Self::Malformed => ().write_xdr(w)?, + Self::SellNoTrust => ().write_xdr(w)?, + Self::BuyNoTrust => ().write_xdr(w)?, + Self::SellNotAuthorized => ().write_xdr(w)?, + Self::BuyNotAuthorized => ().write_xdr(w)?, + Self::LineFull => ().write_xdr(w)?, + Self::Underfunded => ().write_xdr(w)?, + Self::CrossSelf => ().write_xdr(w)?, + Self::SellNoIssuer => ().write_xdr(w)?, + Self::BuyNoIssuer => ().write_xdr(w)?, + Self::NotFound => ().write_xdr(w)?, + Self::LowReserve => ().write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/memo.rs b/src/generated/memo.rs index e174d07fc..189df5a56 100644 --- a/src/generated/memo.rs +++ b/src/generated/memo.rs @@ -168,3 +168,70 @@ impl WriteXdr for Memo { }) } } + +/// MemoView is a borrowing equivalent of [`Memo`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum MemoView<'a> { + None, + Text(StringMView<'a, 28>), + Id(u64), + Hash(Hash), + Return(Hash), +} + +#[cfg(feature = "alloc")] +impl From<&MemoView<'_>> for Memo { + #[must_use] + fn from(v: &MemoView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + MemoView::None => Self::None, + MemoView::Text(value) => Self::Text(value.to_stringm()), + MemoView::Id(value) => Self::Id(*value), + MemoView::Hash(value) => Self::Hash(value.clone()), + MemoView::Return(value) => Self::Return(value.clone()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for Memo { + #[must_use] + fn from(v: MemoView<'_>) -> Self { + Self::from(&v) + } +} + +impl MemoView<'_> { + #[must_use] + pub const fn discriminant(&self) -> MemoType { + #[allow(clippy::match_same_arms)] + match self { + Self::None => MemoType::None, + Self::Text(_) => MemoType::Text, + Self::Id(_) => MemoType::Id, + Self::Hash(_) => MemoType::Hash, + Self::Return(_) => MemoType::Return, + } + } +} + +impl WriteXdr for MemoView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::None => ().write_xdr(w)?, + Self::Text(v) => v.write_xdr(w)?, + Self::Id(v) => v.write_xdr(w)?, + Self::Hash(v) => v.write_xdr(w)?, + Self::Return(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/operation.rs b/src/generated/operation.rs index 6486aa346..902ad0b62 100644 --- a/src/generated/operation.rs +++ b/src/generated/operation.rs @@ -110,3 +110,41 @@ impl WriteXdr for Operation { }) } } + +/// OperationView is a borrowing equivalent of [`Operation`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct OperationView<'a> { + pub source_account: Option, + pub body: OperationBodyView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&OperationView<'_>> for Operation { + #[must_use] + fn from(v: &OperationView<'_>) -> Self { + Self { + source_account: v.source_account.clone(), + body: (&v.body).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for Operation { + #[must_use] + fn from(v: OperationView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for OperationView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.source_account.write_xdr(w)?; + self.body.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/operation_body.rs b/src/generated/operation_body.rs index 40ff0de53..d8665dd23 100644 --- a/src/generated/operation_body.rs +++ b/src/generated/operation_body.rs @@ -400,3 +400,176 @@ impl WriteXdr for OperationBody { }) } } + +/// OperationBodyView is a borrowing equivalent of [`OperationBody`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum OperationBodyView<'a> { + CreateAccount(CreateAccountOp), + Payment(PaymentOp), + PathPaymentStrictReceive(PathPaymentStrictReceiveOpView<'a>), + ManageSellOffer(ManageSellOfferOp), + CreatePassiveSellOffer(CreatePassiveSellOfferOp), + SetOptions(SetOptionsOpView<'a>), + ChangeTrust(ChangeTrustOp), + AllowTrust(AllowTrustOp), + AccountMerge(MuxedAccount), + Inflation, + ManageData(ManageDataOpView<'a>), + BumpSequence(BumpSequenceOp), + ManageBuyOffer(ManageBuyOfferOp), + PathPaymentStrictSend(PathPaymentStrictSendOpView<'a>), + CreateClaimableBalance(CreateClaimableBalanceOpView<'a>), + ClaimClaimableBalance(ClaimClaimableBalanceOp), + BeginSponsoringFutureReserves(BeginSponsoringFutureReservesOp), + EndSponsoringFutureReserves, + RevokeSponsorship(RevokeSponsorshipOpView<'a>), + Clawback(ClawbackOp), + ClawbackClaimableBalance(ClawbackClaimableBalanceOp), + SetTrustLineFlags(SetTrustLineFlagsOp), + LiquidityPoolDeposit(LiquidityPoolDepositOp), + LiquidityPoolWithdraw(LiquidityPoolWithdrawOp), + InvokeHostFunction(InvokeHostFunctionOpView<'a>), + ExtendFootprintTtl(ExtendFootprintTtlOp), + RestoreFootprint(RestoreFootprintOp), +} + +#[cfg(feature = "alloc")] +impl From<&OperationBodyView<'_>> for OperationBody { + #[must_use] + fn from(v: &OperationBodyView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + OperationBodyView::CreateAccount(value) => Self::CreateAccount(value.clone()), + OperationBodyView::Payment(value) => Self::Payment(value.clone()), + OperationBodyView::PathPaymentStrictReceive(value) => { + Self::PathPaymentStrictReceive(value.into()) + } + OperationBodyView::ManageSellOffer(value) => Self::ManageSellOffer(value.clone()), + OperationBodyView::CreatePassiveSellOffer(value) => { + Self::CreatePassiveSellOffer(value.clone()) + } + OperationBodyView::SetOptions(value) => Self::SetOptions(value.into()), + OperationBodyView::ChangeTrust(value) => Self::ChangeTrust(value.clone()), + OperationBodyView::AllowTrust(value) => Self::AllowTrust(value.clone()), + OperationBodyView::AccountMerge(value) => Self::AccountMerge(value.clone()), + OperationBodyView::Inflation => Self::Inflation, + OperationBodyView::ManageData(value) => Self::ManageData(value.into()), + OperationBodyView::BumpSequence(value) => Self::BumpSequence(value.clone()), + OperationBodyView::ManageBuyOffer(value) => Self::ManageBuyOffer(value.clone()), + OperationBodyView::PathPaymentStrictSend(value) => { + Self::PathPaymentStrictSend(value.into()) + } + OperationBodyView::CreateClaimableBalance(value) => { + Self::CreateClaimableBalance(value.into()) + } + OperationBodyView::ClaimClaimableBalance(value) => { + Self::ClaimClaimableBalance(value.clone()) + } + OperationBodyView::BeginSponsoringFutureReserves(value) => { + Self::BeginSponsoringFutureReserves(value.clone()) + } + OperationBodyView::EndSponsoringFutureReserves => Self::EndSponsoringFutureReserves, + OperationBodyView::RevokeSponsorship(value) => Self::RevokeSponsorship(value.into()), + OperationBodyView::Clawback(value) => Self::Clawback(value.clone()), + OperationBodyView::ClawbackClaimableBalance(value) => { + Self::ClawbackClaimableBalance(value.clone()) + } + OperationBodyView::SetTrustLineFlags(value) => Self::SetTrustLineFlags(value.clone()), + OperationBodyView::LiquidityPoolDeposit(value) => { + Self::LiquidityPoolDeposit(value.clone()) + } + OperationBodyView::LiquidityPoolWithdraw(value) => { + Self::LiquidityPoolWithdraw(value.clone()) + } + OperationBodyView::InvokeHostFunction(value) => Self::InvokeHostFunction(value.into()), + OperationBodyView::ExtendFootprintTtl(value) => Self::ExtendFootprintTtl(value.clone()), + OperationBodyView::RestoreFootprint(value) => Self::RestoreFootprint(value.clone()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for OperationBody { + #[must_use] + fn from(v: OperationBodyView<'_>) -> Self { + Self::from(&v) + } +} + +impl OperationBodyView<'_> { + #[must_use] + pub const fn discriminant(&self) -> OperationType { + #[allow(clippy::match_same_arms)] + match self { + Self::CreateAccount(_) => OperationType::CreateAccount, + Self::Payment(_) => OperationType::Payment, + Self::PathPaymentStrictReceive(_) => OperationType::PathPaymentStrictReceive, + Self::ManageSellOffer(_) => OperationType::ManageSellOffer, + Self::CreatePassiveSellOffer(_) => OperationType::CreatePassiveSellOffer, + Self::SetOptions(_) => OperationType::SetOptions, + Self::ChangeTrust(_) => OperationType::ChangeTrust, + Self::AllowTrust(_) => OperationType::AllowTrust, + Self::AccountMerge(_) => OperationType::AccountMerge, + Self::Inflation => OperationType::Inflation, + Self::ManageData(_) => OperationType::ManageData, + Self::BumpSequence(_) => OperationType::BumpSequence, + Self::ManageBuyOffer(_) => OperationType::ManageBuyOffer, + Self::PathPaymentStrictSend(_) => OperationType::PathPaymentStrictSend, + Self::CreateClaimableBalance(_) => OperationType::CreateClaimableBalance, + Self::ClaimClaimableBalance(_) => OperationType::ClaimClaimableBalance, + Self::BeginSponsoringFutureReserves(_) => OperationType::BeginSponsoringFutureReserves, + Self::EndSponsoringFutureReserves => OperationType::EndSponsoringFutureReserves, + Self::RevokeSponsorship(_) => OperationType::RevokeSponsorship, + Self::Clawback(_) => OperationType::Clawback, + Self::ClawbackClaimableBalance(_) => OperationType::ClawbackClaimableBalance, + Self::SetTrustLineFlags(_) => OperationType::SetTrustLineFlags, + Self::LiquidityPoolDeposit(_) => OperationType::LiquidityPoolDeposit, + Self::LiquidityPoolWithdraw(_) => OperationType::LiquidityPoolWithdraw, + Self::InvokeHostFunction(_) => OperationType::InvokeHostFunction, + Self::ExtendFootprintTtl(_) => OperationType::ExtendFootprintTtl, + Self::RestoreFootprint(_) => OperationType::RestoreFootprint, + } + } +} + +impl WriteXdr for OperationBodyView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::CreateAccount(v) => v.write_xdr(w)?, + Self::Payment(v) => v.write_xdr(w)?, + Self::PathPaymentStrictReceive(v) => v.write_xdr(w)?, + Self::ManageSellOffer(v) => v.write_xdr(w)?, + Self::CreatePassiveSellOffer(v) => v.write_xdr(w)?, + Self::SetOptions(v) => v.write_xdr(w)?, + Self::ChangeTrust(v) => v.write_xdr(w)?, + Self::AllowTrust(v) => v.write_xdr(w)?, + Self::AccountMerge(v) => v.write_xdr(w)?, + Self::Inflation => ().write_xdr(w)?, + Self::ManageData(v) => v.write_xdr(w)?, + Self::BumpSequence(v) => v.write_xdr(w)?, + Self::ManageBuyOffer(v) => v.write_xdr(w)?, + Self::PathPaymentStrictSend(v) => v.write_xdr(w)?, + Self::CreateClaimableBalance(v) => v.write_xdr(w)?, + Self::ClaimClaimableBalance(v) => v.write_xdr(w)?, + Self::BeginSponsoringFutureReserves(v) => v.write_xdr(w)?, + Self::EndSponsoringFutureReserves => ().write_xdr(w)?, + Self::RevokeSponsorship(v) => v.write_xdr(w)?, + Self::Clawback(v) => v.write_xdr(w)?, + Self::ClawbackClaimableBalance(v) => v.write_xdr(w)?, + Self::SetTrustLineFlags(v) => v.write_xdr(w)?, + Self::LiquidityPoolDeposit(v) => v.write_xdr(w)?, + Self::LiquidityPoolWithdraw(v) => v.write_xdr(w)?, + Self::InvokeHostFunction(v) => v.write_xdr(w)?, + Self::ExtendFootprintTtl(v) => v.write_xdr(w)?, + Self::RestoreFootprint(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/operation_meta.rs b/src/generated/operation_meta.rs index 2196a70e6..83feabcdc 100644 --- a/src/generated/operation_meta.rs +++ b/src/generated/operation_meta.rs @@ -45,3 +45,38 @@ impl WriteXdr for OperationMeta { }) } } + +/// OperationMetaView is a borrowing equivalent of [`OperationMeta`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct OperationMetaView<'a> { + pub changes: LedgerEntryChangesView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&OperationMetaView<'_>> for OperationMeta { + #[must_use] + fn from(v: &OperationMetaView<'_>) -> Self { + Self { + changes: (&v.changes).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for OperationMeta { + #[must_use] + fn from(v: OperationMetaView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for OperationMetaView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.changes.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/operation_meta_v2.rs b/src/generated/operation_meta_v2.rs index 7daa9fdcb..4b76bd865 100644 --- a/src/generated/operation_meta_v2.rs +++ b/src/generated/operation_meta_v2.rs @@ -55,3 +55,44 @@ impl WriteXdr for OperationMetaV2 { }) } } + +/// OperationMetaV2View is a borrowing equivalent of [`OperationMetaV2`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct OperationMetaV2View<'a> { + pub ext: ExtensionPoint, + pub changes: LedgerEntryChangesView<'a>, + pub events: VecMView<'a, ContractEventView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&OperationMetaV2View<'_>> for OperationMetaV2 { + #[must_use] + fn from(v: &OperationMetaV2View<'_>) -> Self { + Self { + ext: v.ext.clone(), + changes: (&v.changes).into(), + events: v.events.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for OperationMetaV2 { + #[must_use] + fn from(v: OperationMetaV2View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for OperationMetaV2View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.changes.write_xdr(w)?; + self.events.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/operation_result.rs b/src/generated/operation_result.rs index 62ab81479..ea8849840 100644 --- a/src/generated/operation_result.rs +++ b/src/generated/operation_result.rs @@ -238,3 +238,78 @@ impl WriteXdr for OperationResult { }) } } + +/// OperationResultView is a borrowing equivalent of [`OperationResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum OperationResultView<'a> { + OpInner(OperationResultTrView<'a>), + OpBadAuth, + OpNoAccount, + OpNotSupported, + OpTooManySubentries, + OpExceededWorkLimit, + OpTooManySponsoring, +} + +#[cfg(feature = "alloc")] +impl From<&OperationResultView<'_>> for OperationResult { + #[must_use] + fn from(v: &OperationResultView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + OperationResultView::OpInner(value) => Self::OpInner(value.into()), + OperationResultView::OpBadAuth => Self::OpBadAuth, + OperationResultView::OpNoAccount => Self::OpNoAccount, + OperationResultView::OpNotSupported => Self::OpNotSupported, + OperationResultView::OpTooManySubentries => Self::OpTooManySubentries, + OperationResultView::OpExceededWorkLimit => Self::OpExceededWorkLimit, + OperationResultView::OpTooManySponsoring => Self::OpTooManySponsoring, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for OperationResult { + #[must_use] + fn from(v: OperationResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl OperationResultView<'_> { + #[must_use] + pub const fn discriminant(&self) -> OperationResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::OpInner(_) => OperationResultCode::OpInner, + Self::OpBadAuth => OperationResultCode::OpBadAuth, + Self::OpNoAccount => OperationResultCode::OpNoAccount, + Self::OpNotSupported => OperationResultCode::OpNotSupported, + Self::OpTooManySubentries => OperationResultCode::OpTooManySubentries, + Self::OpExceededWorkLimit => OperationResultCode::OpExceededWorkLimit, + Self::OpTooManySponsoring => OperationResultCode::OpTooManySponsoring, + } + } +} + +impl WriteXdr for OperationResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::OpInner(v) => v.write_xdr(w)?, + Self::OpBadAuth => ().write_xdr(w)?, + Self::OpNoAccount => ().write_xdr(w)?, + Self::OpNotSupported => ().write_xdr(w)?, + Self::OpTooManySubentries => ().write_xdr(w)?, + Self::OpExceededWorkLimit => ().write_xdr(w)?, + Self::OpTooManySponsoring => ().write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/operation_result_tr.rs b/src/generated/operation_result_tr.rs index 0e66be4e9..3ad747c5f 100644 --- a/src/generated/operation_result_tr.rs +++ b/src/generated/operation_result_tr.rs @@ -404,3 +404,186 @@ impl WriteXdr for OperationResultTr { }) } } + +/// OperationResultTrView is a borrowing equivalent of [`OperationResultTr`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum OperationResultTrView<'a> { + CreateAccount(CreateAccountResult), + Payment(PaymentResult), + PathPaymentStrictReceive(PathPaymentStrictReceiveResultView<'a>), + ManageSellOffer(ManageSellOfferResultView<'a>), + CreatePassiveSellOffer(ManageSellOfferResultView<'a>), + SetOptions(SetOptionsResult), + ChangeTrust(ChangeTrustResult), + AllowTrust(AllowTrustResult), + AccountMerge(AccountMergeResult), + Inflation(InflationResultView<'a>), + ManageData(ManageDataResult), + BumpSequence(BumpSequenceResult), + ManageBuyOffer(ManageBuyOfferResultView<'a>), + PathPaymentStrictSend(PathPaymentStrictSendResultView<'a>), + CreateClaimableBalance(CreateClaimableBalanceResult), + ClaimClaimableBalance(ClaimClaimableBalanceResult), + BeginSponsoringFutureReserves(BeginSponsoringFutureReservesResult), + EndSponsoringFutureReserves(EndSponsoringFutureReservesResult), + RevokeSponsorship(RevokeSponsorshipResult), + Clawback(ClawbackResult), + ClawbackClaimableBalance(ClawbackClaimableBalanceResult), + SetTrustLineFlags(SetTrustLineFlagsResult), + LiquidityPoolDeposit(LiquidityPoolDepositResult), + LiquidityPoolWithdraw(LiquidityPoolWithdrawResult), + InvokeHostFunction(InvokeHostFunctionResult), + ExtendFootprintTtl(ExtendFootprintTtlResult), + RestoreFootprint(RestoreFootprintResult), +} + +#[cfg(feature = "alloc")] +impl From<&OperationResultTrView<'_>> for OperationResultTr { + #[must_use] + fn from(v: &OperationResultTrView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + OperationResultTrView::CreateAccount(value) => Self::CreateAccount(value.clone()), + OperationResultTrView::Payment(value) => Self::Payment(value.clone()), + OperationResultTrView::PathPaymentStrictReceive(value) => { + Self::PathPaymentStrictReceive(value.into()) + } + OperationResultTrView::ManageSellOffer(value) => Self::ManageSellOffer(value.into()), + OperationResultTrView::CreatePassiveSellOffer(value) => { + Self::CreatePassiveSellOffer(value.into()) + } + OperationResultTrView::SetOptions(value) => Self::SetOptions(value.clone()), + OperationResultTrView::ChangeTrust(value) => Self::ChangeTrust(value.clone()), + OperationResultTrView::AllowTrust(value) => Self::AllowTrust(value.clone()), + OperationResultTrView::AccountMerge(value) => Self::AccountMerge(value.clone()), + OperationResultTrView::Inflation(value) => Self::Inflation(value.into()), + OperationResultTrView::ManageData(value) => Self::ManageData(value.clone()), + OperationResultTrView::BumpSequence(value) => Self::BumpSequence(value.clone()), + OperationResultTrView::ManageBuyOffer(value) => Self::ManageBuyOffer(value.into()), + OperationResultTrView::PathPaymentStrictSend(value) => { + Self::PathPaymentStrictSend(value.into()) + } + OperationResultTrView::CreateClaimableBalance(value) => { + Self::CreateClaimableBalance(value.clone()) + } + OperationResultTrView::ClaimClaimableBalance(value) => { + Self::ClaimClaimableBalance(value.clone()) + } + OperationResultTrView::BeginSponsoringFutureReserves(value) => { + Self::BeginSponsoringFutureReserves(value.clone()) + } + OperationResultTrView::EndSponsoringFutureReserves(value) => { + Self::EndSponsoringFutureReserves(value.clone()) + } + OperationResultTrView::RevokeSponsorship(value) => { + Self::RevokeSponsorship(value.clone()) + } + OperationResultTrView::Clawback(value) => Self::Clawback(value.clone()), + OperationResultTrView::ClawbackClaimableBalance(value) => { + Self::ClawbackClaimableBalance(value.clone()) + } + OperationResultTrView::SetTrustLineFlags(value) => { + Self::SetTrustLineFlags(value.clone()) + } + OperationResultTrView::LiquidityPoolDeposit(value) => { + Self::LiquidityPoolDeposit(value.clone()) + } + OperationResultTrView::LiquidityPoolWithdraw(value) => { + Self::LiquidityPoolWithdraw(value.clone()) + } + OperationResultTrView::InvokeHostFunction(value) => { + Self::InvokeHostFunction(value.clone()) + } + OperationResultTrView::ExtendFootprintTtl(value) => { + Self::ExtendFootprintTtl(value.clone()) + } + OperationResultTrView::RestoreFootprint(value) => Self::RestoreFootprint(value.clone()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for OperationResultTr { + #[must_use] + fn from(v: OperationResultTrView<'_>) -> Self { + Self::from(&v) + } +} + +impl OperationResultTrView<'_> { + #[must_use] + pub const fn discriminant(&self) -> OperationType { + #[allow(clippy::match_same_arms)] + match self { + Self::CreateAccount(_) => OperationType::CreateAccount, + Self::Payment(_) => OperationType::Payment, + Self::PathPaymentStrictReceive(_) => OperationType::PathPaymentStrictReceive, + Self::ManageSellOffer(_) => OperationType::ManageSellOffer, + Self::CreatePassiveSellOffer(_) => OperationType::CreatePassiveSellOffer, + Self::SetOptions(_) => OperationType::SetOptions, + Self::ChangeTrust(_) => OperationType::ChangeTrust, + Self::AllowTrust(_) => OperationType::AllowTrust, + Self::AccountMerge(_) => OperationType::AccountMerge, + Self::Inflation(_) => OperationType::Inflation, + Self::ManageData(_) => OperationType::ManageData, + Self::BumpSequence(_) => OperationType::BumpSequence, + Self::ManageBuyOffer(_) => OperationType::ManageBuyOffer, + Self::PathPaymentStrictSend(_) => OperationType::PathPaymentStrictSend, + Self::CreateClaimableBalance(_) => OperationType::CreateClaimableBalance, + Self::ClaimClaimableBalance(_) => OperationType::ClaimClaimableBalance, + Self::BeginSponsoringFutureReserves(_) => OperationType::BeginSponsoringFutureReserves, + Self::EndSponsoringFutureReserves(_) => OperationType::EndSponsoringFutureReserves, + Self::RevokeSponsorship(_) => OperationType::RevokeSponsorship, + Self::Clawback(_) => OperationType::Clawback, + Self::ClawbackClaimableBalance(_) => OperationType::ClawbackClaimableBalance, + Self::SetTrustLineFlags(_) => OperationType::SetTrustLineFlags, + Self::LiquidityPoolDeposit(_) => OperationType::LiquidityPoolDeposit, + Self::LiquidityPoolWithdraw(_) => OperationType::LiquidityPoolWithdraw, + Self::InvokeHostFunction(_) => OperationType::InvokeHostFunction, + Self::ExtendFootprintTtl(_) => OperationType::ExtendFootprintTtl, + Self::RestoreFootprint(_) => OperationType::RestoreFootprint, + } + } +} + +impl WriteXdr for OperationResultTrView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::CreateAccount(v) => v.write_xdr(w)?, + Self::Payment(v) => v.write_xdr(w)?, + Self::PathPaymentStrictReceive(v) => v.write_xdr(w)?, + Self::ManageSellOffer(v) => v.write_xdr(w)?, + Self::CreatePassiveSellOffer(v) => v.write_xdr(w)?, + Self::SetOptions(v) => v.write_xdr(w)?, + Self::ChangeTrust(v) => v.write_xdr(w)?, + Self::AllowTrust(v) => v.write_xdr(w)?, + Self::AccountMerge(v) => v.write_xdr(w)?, + Self::Inflation(v) => v.write_xdr(w)?, + Self::ManageData(v) => v.write_xdr(w)?, + Self::BumpSequence(v) => v.write_xdr(w)?, + Self::ManageBuyOffer(v) => v.write_xdr(w)?, + Self::PathPaymentStrictSend(v) => v.write_xdr(w)?, + Self::CreateClaimableBalance(v) => v.write_xdr(w)?, + Self::ClaimClaimableBalance(v) => v.write_xdr(w)?, + Self::BeginSponsoringFutureReserves(v) => v.write_xdr(w)?, + Self::EndSponsoringFutureReserves(v) => v.write_xdr(w)?, + Self::RevokeSponsorship(v) => v.write_xdr(w)?, + Self::Clawback(v) => v.write_xdr(w)?, + Self::ClawbackClaimableBalance(v) => v.write_xdr(w)?, + Self::SetTrustLineFlags(v) => v.write_xdr(w)?, + Self::LiquidityPoolDeposit(v) => v.write_xdr(w)?, + Self::LiquidityPoolWithdraw(v) => v.write_xdr(w)?, + Self::InvokeHostFunction(v) => v.write_xdr(w)?, + Self::ExtendFootprintTtl(v) => v.write_xdr(w)?, + Self::RestoreFootprint(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/parallel_tx_execution_stage.rs b/src/generated/parallel_tx_execution_stage.rs index 659f95c24..5919b3a53 100644 --- a/src/generated/parallel_tx_execution_stage.rs +++ b/src/generated/parallel_tx_execution_stage.rs @@ -107,3 +107,31 @@ impl AsRef<[DependentTxCluster]> for ParallelTxExecutionStage { self.0 .0 } } + +/// ParallelTxExecutionStageView is a borrowing equivalent of [`ParallelTxExecutionStage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ParallelTxExecutionStageView<'a>(pub VecMView<'a, DependentTxClusterView<'a>>); + +#[cfg(feature = "alloc")] +impl From<&ParallelTxExecutionStageView<'_>> for ParallelTxExecutionStage { + #[must_use] + fn from(v: &ParallelTxExecutionStageView<'_>) -> Self { + Self(v.0.to_vecm_from()) + } +} + +#[cfg(feature = "alloc")] +impl From> for ParallelTxExecutionStage { + #[must_use] + fn from(v: ParallelTxExecutionStageView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ParallelTxExecutionStageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/parallel_txs_component.rs b/src/generated/parallel_txs_component.rs index 64d5a95b6..d35980e03 100644 --- a/src/generated/parallel_txs_component.rs +++ b/src/generated/parallel_txs_component.rs @@ -56,3 +56,41 @@ impl WriteXdr for ParallelTxsComponent { }) } } + +/// ParallelTxsComponentView is a borrowing equivalent of [`ParallelTxsComponent`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ParallelTxsComponentView<'a> { + pub base_fee: Option, + pub execution_stages: VecMView<'a, ParallelTxExecutionStageView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&ParallelTxsComponentView<'_>> for ParallelTxsComponent { + #[must_use] + fn from(v: &ParallelTxsComponentView<'_>) -> Self { + Self { + base_fee: v.base_fee, + execution_stages: v.execution_stages.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ParallelTxsComponent { + #[must_use] + fn from(v: ParallelTxsComponentView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ParallelTxsComponentView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.base_fee.write_xdr(w)?; + self.execution_stages.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/path_payment_strict_receive_op.rs b/src/generated/path_payment_strict_receive_op.rs index e28ccef9f..0a64deb78 100644 --- a/src/generated/path_payment_strict_receive_op.rs +++ b/src/generated/path_payment_strict_receive_op.rs @@ -77,3 +77,53 @@ impl WriteXdr for PathPaymentStrictReceiveOp { }) } } + +/// PathPaymentStrictReceiveOpView is a borrowing equivalent of [`PathPaymentStrictReceiveOp`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct PathPaymentStrictReceiveOpView<'a> { + pub send_asset: Asset, + pub send_max: i64, + pub destination: MuxedAccount, + pub dest_asset: Asset, + pub dest_amount: i64, + pub path: VecMView<'a, Asset, 5>, +} + +#[cfg(feature = "alloc")] +impl From<&PathPaymentStrictReceiveOpView<'_>> for PathPaymentStrictReceiveOp { + #[must_use] + fn from(v: &PathPaymentStrictReceiveOpView<'_>) -> Self { + Self { + send_asset: v.send_asset.clone(), + send_max: v.send_max, + destination: v.destination.clone(), + dest_asset: v.dest_asset.clone(), + dest_amount: v.dest_amount, + path: v.path.to_vecm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PathPaymentStrictReceiveOp { + #[must_use] + fn from(v: PathPaymentStrictReceiveOpView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for PathPaymentStrictReceiveOpView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.send_asset.write_xdr(w)?; + self.send_max.write_xdr(w)?; + self.destination.write_xdr(w)?; + self.dest_asset.write_xdr(w)?; + self.dest_amount.write_xdr(w)?; + self.path.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/path_payment_strict_receive_result.rs b/src/generated/path_payment_strict_receive_result.rs index 1b7fa0473..b61a01c38 100644 --- a/src/generated/path_payment_strict_receive_result.rs +++ b/src/generated/path_payment_strict_receive_result.rs @@ -239,3 +239,102 @@ impl WriteXdr for PathPaymentStrictReceiveResult { }) } } + +/// PathPaymentStrictReceiveResultView is a borrowing equivalent of [`PathPaymentStrictReceiveResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum PathPaymentStrictReceiveResultView<'a> { + Success(PathPaymentStrictReceiveResultSuccessView<'a>), + Malformed, + Underfunded, + SrcNoTrust, + SrcNotAuthorized, + NoDestination, + NoTrust, + NotAuthorized, + LineFull, + NoIssuer(Asset), + TooFewOffers, + OfferCrossSelf, + OverSendmax, +} + +#[cfg(feature = "alloc")] +impl From<&PathPaymentStrictReceiveResultView<'_>> for PathPaymentStrictReceiveResult { + #[must_use] + fn from(v: &PathPaymentStrictReceiveResultView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + PathPaymentStrictReceiveResultView::Success(value) => Self::Success(value.into()), + PathPaymentStrictReceiveResultView::Malformed => Self::Malformed, + PathPaymentStrictReceiveResultView::Underfunded => Self::Underfunded, + PathPaymentStrictReceiveResultView::SrcNoTrust => Self::SrcNoTrust, + PathPaymentStrictReceiveResultView::SrcNotAuthorized => Self::SrcNotAuthorized, + PathPaymentStrictReceiveResultView::NoDestination => Self::NoDestination, + PathPaymentStrictReceiveResultView::NoTrust => Self::NoTrust, + PathPaymentStrictReceiveResultView::NotAuthorized => Self::NotAuthorized, + PathPaymentStrictReceiveResultView::LineFull => Self::LineFull, + PathPaymentStrictReceiveResultView::NoIssuer(value) => Self::NoIssuer(value.clone()), + PathPaymentStrictReceiveResultView::TooFewOffers => Self::TooFewOffers, + PathPaymentStrictReceiveResultView::OfferCrossSelf => Self::OfferCrossSelf, + PathPaymentStrictReceiveResultView::OverSendmax => Self::OverSendmax, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PathPaymentStrictReceiveResult { + #[must_use] + fn from(v: PathPaymentStrictReceiveResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl PathPaymentStrictReceiveResultView<'_> { + #[must_use] + pub const fn discriminant(&self) -> PathPaymentStrictReceiveResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => PathPaymentStrictReceiveResultCode::Success, + Self::Malformed => PathPaymentStrictReceiveResultCode::Malformed, + Self::Underfunded => PathPaymentStrictReceiveResultCode::Underfunded, + Self::SrcNoTrust => PathPaymentStrictReceiveResultCode::SrcNoTrust, + Self::SrcNotAuthorized => PathPaymentStrictReceiveResultCode::SrcNotAuthorized, + Self::NoDestination => PathPaymentStrictReceiveResultCode::NoDestination, + Self::NoTrust => PathPaymentStrictReceiveResultCode::NoTrust, + Self::NotAuthorized => PathPaymentStrictReceiveResultCode::NotAuthorized, + Self::LineFull => PathPaymentStrictReceiveResultCode::LineFull, + Self::NoIssuer(_) => PathPaymentStrictReceiveResultCode::NoIssuer, + Self::TooFewOffers => PathPaymentStrictReceiveResultCode::TooFewOffers, + Self::OfferCrossSelf => PathPaymentStrictReceiveResultCode::OfferCrossSelf, + Self::OverSendmax => PathPaymentStrictReceiveResultCode::OverSendmax, + } + } +} + +impl WriteXdr for PathPaymentStrictReceiveResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Success(v) => v.write_xdr(w)?, + Self::Malformed => ().write_xdr(w)?, + Self::Underfunded => ().write_xdr(w)?, + Self::SrcNoTrust => ().write_xdr(w)?, + Self::SrcNotAuthorized => ().write_xdr(w)?, + Self::NoDestination => ().write_xdr(w)?, + Self::NoTrust => ().write_xdr(w)?, + Self::NotAuthorized => ().write_xdr(w)?, + Self::LineFull => ().write_xdr(w)?, + Self::NoIssuer(v) => v.write_xdr(w)?, + Self::TooFewOffers => ().write_xdr(w)?, + Self::OfferCrossSelf => ().write_xdr(w)?, + Self::OverSendmax => ().write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/path_payment_strict_receive_result_success.rs b/src/generated/path_payment_strict_receive_result_success.rs index 6f48e1e2d..c97023bb7 100644 --- a/src/generated/path_payment_strict_receive_result_success.rs +++ b/src/generated/path_payment_strict_receive_result_success.rs @@ -49,3 +49,43 @@ impl WriteXdr for PathPaymentStrictReceiveResultSuccess { }) } } + +/// PathPaymentStrictReceiveResultSuccessView is a borrowing equivalent of [`PathPaymentStrictReceiveResultSuccess`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct PathPaymentStrictReceiveResultSuccessView<'a> { + pub offers: VecMView<'a, ClaimAtom>, + pub last: SimplePaymentResult, +} + +#[cfg(feature = "alloc")] +impl From<&PathPaymentStrictReceiveResultSuccessView<'_>> + for PathPaymentStrictReceiveResultSuccess +{ + #[must_use] + fn from(v: &PathPaymentStrictReceiveResultSuccessView<'_>) -> Self { + Self { + offers: v.offers.to_vecm(), + last: v.last.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PathPaymentStrictReceiveResultSuccess { + #[must_use] + fn from(v: PathPaymentStrictReceiveResultSuccessView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for PathPaymentStrictReceiveResultSuccessView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.offers.write_xdr(w)?; + self.last.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/path_payment_strict_send_op.rs b/src/generated/path_payment_strict_send_op.rs index 7d66c2c42..d01c0cb67 100644 --- a/src/generated/path_payment_strict_send_op.rs +++ b/src/generated/path_payment_strict_send_op.rs @@ -77,3 +77,53 @@ impl WriteXdr for PathPaymentStrictSendOp { }) } } + +/// PathPaymentStrictSendOpView is a borrowing equivalent of [`PathPaymentStrictSendOp`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct PathPaymentStrictSendOpView<'a> { + pub send_asset: Asset, + pub send_amount: i64, + pub destination: MuxedAccount, + pub dest_asset: Asset, + pub dest_min: i64, + pub path: VecMView<'a, Asset, 5>, +} + +#[cfg(feature = "alloc")] +impl From<&PathPaymentStrictSendOpView<'_>> for PathPaymentStrictSendOp { + #[must_use] + fn from(v: &PathPaymentStrictSendOpView<'_>) -> Self { + Self { + send_asset: v.send_asset.clone(), + send_amount: v.send_amount, + destination: v.destination.clone(), + dest_asset: v.dest_asset.clone(), + dest_min: v.dest_min, + path: v.path.to_vecm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PathPaymentStrictSendOp { + #[must_use] + fn from(v: PathPaymentStrictSendOpView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for PathPaymentStrictSendOpView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.send_asset.write_xdr(w)?; + self.send_amount.write_xdr(w)?; + self.destination.write_xdr(w)?; + self.dest_asset.write_xdr(w)?; + self.dest_min.write_xdr(w)?; + self.path.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/path_payment_strict_send_result.rs b/src/generated/path_payment_strict_send_result.rs index 02345dca7..ce3ddc81f 100644 --- a/src/generated/path_payment_strict_send_result.rs +++ b/src/generated/path_payment_strict_send_result.rs @@ -238,3 +238,102 @@ impl WriteXdr for PathPaymentStrictSendResult { }) } } + +/// PathPaymentStrictSendResultView is a borrowing equivalent of [`PathPaymentStrictSendResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum PathPaymentStrictSendResultView<'a> { + Success(PathPaymentStrictSendResultSuccessView<'a>), + Malformed, + Underfunded, + SrcNoTrust, + SrcNotAuthorized, + NoDestination, + NoTrust, + NotAuthorized, + LineFull, + NoIssuer(Asset), + TooFewOffers, + OfferCrossSelf, + UnderDestmin, +} + +#[cfg(feature = "alloc")] +impl From<&PathPaymentStrictSendResultView<'_>> for PathPaymentStrictSendResult { + #[must_use] + fn from(v: &PathPaymentStrictSendResultView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + PathPaymentStrictSendResultView::Success(value) => Self::Success(value.into()), + PathPaymentStrictSendResultView::Malformed => Self::Malformed, + PathPaymentStrictSendResultView::Underfunded => Self::Underfunded, + PathPaymentStrictSendResultView::SrcNoTrust => Self::SrcNoTrust, + PathPaymentStrictSendResultView::SrcNotAuthorized => Self::SrcNotAuthorized, + PathPaymentStrictSendResultView::NoDestination => Self::NoDestination, + PathPaymentStrictSendResultView::NoTrust => Self::NoTrust, + PathPaymentStrictSendResultView::NotAuthorized => Self::NotAuthorized, + PathPaymentStrictSendResultView::LineFull => Self::LineFull, + PathPaymentStrictSendResultView::NoIssuer(value) => Self::NoIssuer(value.clone()), + PathPaymentStrictSendResultView::TooFewOffers => Self::TooFewOffers, + PathPaymentStrictSendResultView::OfferCrossSelf => Self::OfferCrossSelf, + PathPaymentStrictSendResultView::UnderDestmin => Self::UnderDestmin, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PathPaymentStrictSendResult { + #[must_use] + fn from(v: PathPaymentStrictSendResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl PathPaymentStrictSendResultView<'_> { + #[must_use] + pub const fn discriminant(&self) -> PathPaymentStrictSendResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::Success(_) => PathPaymentStrictSendResultCode::Success, + Self::Malformed => PathPaymentStrictSendResultCode::Malformed, + Self::Underfunded => PathPaymentStrictSendResultCode::Underfunded, + Self::SrcNoTrust => PathPaymentStrictSendResultCode::SrcNoTrust, + Self::SrcNotAuthorized => PathPaymentStrictSendResultCode::SrcNotAuthorized, + Self::NoDestination => PathPaymentStrictSendResultCode::NoDestination, + Self::NoTrust => PathPaymentStrictSendResultCode::NoTrust, + Self::NotAuthorized => PathPaymentStrictSendResultCode::NotAuthorized, + Self::LineFull => PathPaymentStrictSendResultCode::LineFull, + Self::NoIssuer(_) => PathPaymentStrictSendResultCode::NoIssuer, + Self::TooFewOffers => PathPaymentStrictSendResultCode::TooFewOffers, + Self::OfferCrossSelf => PathPaymentStrictSendResultCode::OfferCrossSelf, + Self::UnderDestmin => PathPaymentStrictSendResultCode::UnderDestmin, + } + } +} + +impl WriteXdr for PathPaymentStrictSendResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Success(v) => v.write_xdr(w)?, + Self::Malformed => ().write_xdr(w)?, + Self::Underfunded => ().write_xdr(w)?, + Self::SrcNoTrust => ().write_xdr(w)?, + Self::SrcNotAuthorized => ().write_xdr(w)?, + Self::NoDestination => ().write_xdr(w)?, + Self::NoTrust => ().write_xdr(w)?, + Self::NotAuthorized => ().write_xdr(w)?, + Self::LineFull => ().write_xdr(w)?, + Self::NoIssuer(v) => v.write_xdr(w)?, + Self::TooFewOffers => ().write_xdr(w)?, + Self::OfferCrossSelf => ().write_xdr(w)?, + Self::UnderDestmin => ().write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/path_payment_strict_send_result_success.rs b/src/generated/path_payment_strict_send_result_success.rs index e443a54b9..908a940fe 100644 --- a/src/generated/path_payment_strict_send_result_success.rs +++ b/src/generated/path_payment_strict_send_result_success.rs @@ -49,3 +49,41 @@ impl WriteXdr for PathPaymentStrictSendResultSuccess { }) } } + +/// PathPaymentStrictSendResultSuccessView is a borrowing equivalent of [`PathPaymentStrictSendResultSuccess`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct PathPaymentStrictSendResultSuccessView<'a> { + pub offers: VecMView<'a, ClaimAtom>, + pub last: SimplePaymentResult, +} + +#[cfg(feature = "alloc")] +impl From<&PathPaymentStrictSendResultSuccessView<'_>> for PathPaymentStrictSendResultSuccess { + #[must_use] + fn from(v: &PathPaymentStrictSendResultSuccessView<'_>) -> Self { + Self { + offers: v.offers.to_vecm(), + last: v.last.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PathPaymentStrictSendResultSuccess { + #[must_use] + fn from(v: PathPaymentStrictSendResultSuccessView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for PathPaymentStrictSendResultSuccessView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.offers.write_xdr(w)?; + self.last.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/peer_stats.rs b/src/generated/peer_stats.rs index 0d6a78041..ce08fe7fc 100644 --- a/src/generated/peer_stats.rs +++ b/src/generated/peer_stats.rs @@ -155,3 +155,80 @@ impl WriteXdr for PeerStats { }) } } + +/// PeerStatsView is a borrowing equivalent of [`PeerStats`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct PeerStatsView<'a> { + pub id: NodeId, + pub version_str: StringMView<'a, 100>, + pub messages_read: u64, + pub messages_written: u64, + pub bytes_read: u64, + pub bytes_written: u64, + pub seconds_connected: u64, + pub unique_flood_bytes_recv: u64, + pub duplicate_flood_bytes_recv: u64, + pub unique_fetch_bytes_recv: u64, + pub duplicate_fetch_bytes_recv: u64, + pub unique_flood_message_recv: u64, + pub duplicate_flood_message_recv: u64, + pub unique_fetch_message_recv: u64, + pub duplicate_fetch_message_recv: u64, +} + +#[cfg(feature = "alloc")] +impl From<&PeerStatsView<'_>> for PeerStats { + #[must_use] + fn from(v: &PeerStatsView<'_>) -> Self { + Self { + id: v.id.clone(), + version_str: v.version_str.to_stringm(), + messages_read: v.messages_read, + messages_written: v.messages_written, + bytes_read: v.bytes_read, + bytes_written: v.bytes_written, + seconds_connected: v.seconds_connected, + unique_flood_bytes_recv: v.unique_flood_bytes_recv, + duplicate_flood_bytes_recv: v.duplicate_flood_bytes_recv, + unique_fetch_bytes_recv: v.unique_fetch_bytes_recv, + duplicate_fetch_bytes_recv: v.duplicate_fetch_bytes_recv, + unique_flood_message_recv: v.unique_flood_message_recv, + duplicate_flood_message_recv: v.duplicate_flood_message_recv, + unique_fetch_message_recv: v.unique_fetch_message_recv, + duplicate_fetch_message_recv: v.duplicate_fetch_message_recv, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PeerStats { + #[must_use] + fn from(v: PeerStatsView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for PeerStatsView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.id.write_xdr(w)?; + self.version_str.write_xdr(w)?; + self.messages_read.write_xdr(w)?; + self.messages_written.write_xdr(w)?; + self.bytes_read.write_xdr(w)?; + self.bytes_written.write_xdr(w)?; + self.seconds_connected.write_xdr(w)?; + self.unique_flood_bytes_recv.write_xdr(w)?; + self.duplicate_flood_bytes_recv.write_xdr(w)?; + self.unique_fetch_bytes_recv.write_xdr(w)?; + self.duplicate_fetch_bytes_recv.write_xdr(w)?; + self.unique_flood_message_recv.write_xdr(w)?; + self.duplicate_flood_message_recv.write_xdr(w)?; + self.unique_fetch_message_recv.write_xdr(w)?; + self.duplicate_fetch_message_recv.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/persisted_scp_state.rs b/src/generated/persisted_scp_state.rs index f1c4bdc76..5da7084f7 100644 --- a/src/generated/persisted_scp_state.rs +++ b/src/generated/persisted_scp_state.rs @@ -135,3 +135,58 @@ impl WriteXdr for PersistedScpState { }) } } + +/// PersistedScpStateView is a borrowing equivalent of [`PersistedScpState`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum PersistedScpStateView<'a> { + V0(PersistedScpStateV0View<'a>), + V1(PersistedScpStateV1View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&PersistedScpStateView<'_>> for PersistedScpState { + #[must_use] + fn from(v: &PersistedScpStateView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + PersistedScpStateView::V0(value) => Self::V0(value.into()), + PersistedScpStateView::V1(value) => Self::V1(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PersistedScpState { + #[must_use] + fn from(v: PersistedScpStateView<'_>) -> Self { + Self::from(&v) + } +} + +impl PersistedScpStateView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + } + } +} + +impl WriteXdr for PersistedScpStateView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0(v) => v.write_xdr(w)?, + Self::V1(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/persisted_scp_state_v0.rs b/src/generated/persisted_scp_state_v0.rs index fea147e5d..b5a6be584 100644 --- a/src/generated/persisted_scp_state_v0.rs +++ b/src/generated/persisted_scp_state_v0.rs @@ -53,3 +53,44 @@ impl WriteXdr for PersistedScpStateV0 { }) } } + +/// PersistedScpStateV0View is a borrowing equivalent of [`PersistedScpStateV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct PersistedScpStateV0View<'a> { + pub scp_envelopes: VecMView<'a, ScpEnvelopeView<'a>>, + pub quorum_sets: VecMView<'a, ScpQuorumSetView<'a>>, + pub tx_sets: VecMView<'a, StoredTransactionSetView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&PersistedScpStateV0View<'_>> for PersistedScpStateV0 { + #[must_use] + fn from(v: &PersistedScpStateV0View<'_>) -> Self { + Self { + scp_envelopes: v.scp_envelopes.to_vecm_from(), + quorum_sets: v.quorum_sets.to_vecm_from(), + tx_sets: v.tx_sets.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PersistedScpStateV0 { + #[must_use] + fn from(v: PersistedScpStateV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for PersistedScpStateV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.scp_envelopes.write_xdr(w)?; + self.quorum_sets.write_xdr(w)?; + self.tx_sets.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/persisted_scp_state_v1.rs b/src/generated/persisted_scp_state_v1.rs index 732ec1bb7..8bc8c354c 100644 --- a/src/generated/persisted_scp_state_v1.rs +++ b/src/generated/persisted_scp_state_v1.rs @@ -50,3 +50,41 @@ impl WriteXdr for PersistedScpStateV1 { }) } } + +/// PersistedScpStateV1View is a borrowing equivalent of [`PersistedScpStateV1`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct PersistedScpStateV1View<'a> { + pub scp_envelopes: VecMView<'a, ScpEnvelopeView<'a>>, + pub quorum_sets: VecMView<'a, ScpQuorumSetView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&PersistedScpStateV1View<'_>> for PersistedScpStateV1 { + #[must_use] + fn from(v: &PersistedScpStateV1View<'_>) -> Self { + Self { + scp_envelopes: v.scp_envelopes.to_vecm_from(), + quorum_sets: v.quorum_sets.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PersistedScpStateV1 { + #[must_use] + fn from(v: PersistedScpStateV1View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for PersistedScpStateV1View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.scp_envelopes.write_xdr(w)?; + self.quorum_sets.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/preconditions.rs b/src/generated/preconditions.rs index 98525d856..4b97a5057 100644 --- a/src/generated/preconditions.rs +++ b/src/generated/preconditions.rs @@ -146,3 +146,62 @@ impl WriteXdr for Preconditions { }) } } + +/// PreconditionsView is a borrowing equivalent of [`Preconditions`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum PreconditionsView<'a> { + None, + Time(TimeBounds), + V2(PreconditionsV2View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&PreconditionsView<'_>> for Preconditions { + #[must_use] + fn from(v: &PreconditionsView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + PreconditionsView::None => Self::None, + PreconditionsView::Time(value) => Self::Time(value.clone()), + PreconditionsView::V2(value) => Self::V2(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for Preconditions { + #[must_use] + fn from(v: PreconditionsView<'_>) -> Self { + Self::from(&v) + } +} + +impl PreconditionsView<'_> { + #[must_use] + pub const fn discriminant(&self) -> PreconditionType { + #[allow(clippy::match_same_arms)] + match self { + Self::None => PreconditionType::None, + Self::Time(_) => PreconditionType::Time, + Self::V2(_) => PreconditionType::V2, + } + } +} + +impl WriteXdr for PreconditionsView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::None => ().write_xdr(w)?, + Self::Time(v) => v.write_xdr(w)?, + Self::V2(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/preconditions_v2.rs b/src/generated/preconditions_v2.rs index f4f3f4aeb..2edecd13a 100644 --- a/src/generated/preconditions_v2.rs +++ b/src/generated/preconditions_v2.rs @@ -88,3 +88,53 @@ impl WriteXdr for PreconditionsV2 { }) } } + +/// PreconditionsV2View is a borrowing equivalent of [`PreconditionsV2`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct PreconditionsV2View<'a> { + pub time_bounds: Option, + pub ledger_bounds: Option, + pub min_seq_num: Option, + pub min_seq_age: Duration, + pub min_seq_ledger_gap: u32, + pub extra_signers: VecMView<'a, SignerKeyView<'a>, 2>, +} + +#[cfg(feature = "alloc")] +impl From<&PreconditionsV2View<'_>> for PreconditionsV2 { + #[must_use] + fn from(v: &PreconditionsV2View<'_>) -> Self { + Self { + time_bounds: v.time_bounds.clone(), + ledger_bounds: v.ledger_bounds.clone(), + min_seq_num: v.min_seq_num.clone(), + min_seq_age: v.min_seq_age.clone(), + min_seq_ledger_gap: v.min_seq_ledger_gap, + extra_signers: v.extra_signers.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for PreconditionsV2 { + #[must_use] + fn from(v: PreconditionsV2View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for PreconditionsV2View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.time_bounds.write_xdr(w)?; + self.ledger_bounds.write_xdr(w)?; + self.min_seq_num.write_xdr(w)?; + self.min_seq_age.write_xdr(w)?; + self.min_seq_ledger_gap.write_xdr(w)?; + self.extra_signers.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/revoke_sponsorship_op.rs b/src/generated/revoke_sponsorship_op.rs index 3a3a091cf..fa9a093fc 100644 --- a/src/generated/revoke_sponsorship_op.rs +++ b/src/generated/revoke_sponsorship_op.rs @@ -144,3 +144,58 @@ impl WriteXdr for RevokeSponsorshipOp { }) } } + +/// RevokeSponsorshipOpView is a borrowing equivalent of [`RevokeSponsorshipOp`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum RevokeSponsorshipOpView<'a> { + LedgerEntry(LedgerKeyView<'a>), + Signer(RevokeSponsorshipOpSignerView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&RevokeSponsorshipOpView<'_>> for RevokeSponsorshipOp { + #[must_use] + fn from(v: &RevokeSponsorshipOpView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + RevokeSponsorshipOpView::LedgerEntry(value) => Self::LedgerEntry(value.into()), + RevokeSponsorshipOpView::Signer(value) => Self::Signer(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for RevokeSponsorshipOp { + #[must_use] + fn from(v: RevokeSponsorshipOpView<'_>) -> Self { + Self::from(&v) + } +} + +impl RevokeSponsorshipOpView<'_> { + #[must_use] + pub const fn discriminant(&self) -> RevokeSponsorshipType { + #[allow(clippy::match_same_arms)] + match self { + Self::LedgerEntry(_) => RevokeSponsorshipType::LedgerEntry, + Self::Signer(_) => RevokeSponsorshipType::Signer, + } + } +} + +impl WriteXdr for RevokeSponsorshipOpView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::LedgerEntry(v) => v.write_xdr(w)?, + Self::Signer(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/revoke_sponsorship_op_signer.rs b/src/generated/revoke_sponsorship_op_signer.rs index b7353ddf2..1aacfde69 100644 --- a/src/generated/revoke_sponsorship_op_signer.rs +++ b/src/generated/revoke_sponsorship_op_signer.rs @@ -49,3 +49,41 @@ impl WriteXdr for RevokeSponsorshipOpSigner { }) } } + +/// RevokeSponsorshipOpSignerView is a borrowing equivalent of [`RevokeSponsorshipOpSigner`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct RevokeSponsorshipOpSignerView<'a> { + pub account_id: AccountId, + pub signer_key: SignerKeyView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&RevokeSponsorshipOpSignerView<'_>> for RevokeSponsorshipOpSigner { + #[must_use] + fn from(v: &RevokeSponsorshipOpSignerView<'_>) -> Self { + Self { + account_id: v.account_id.clone(), + signer_key: (&v.signer_key).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for RevokeSponsorshipOpSigner { + #[must_use] + fn from(v: RevokeSponsorshipOpSignerView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for RevokeSponsorshipOpSignerView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.account_id.write_xdr(w)?; + self.signer_key.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/s_error.rs b/src/generated/s_error.rs index d192da513..9f1f6055d 100644 --- a/src/generated/s_error.rs +++ b/src/generated/s_error.rs @@ -49,3 +49,41 @@ impl WriteXdr for SError { }) } } + +/// SErrorView is a borrowing equivalent of [`SError`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SErrorView<'a> { + pub code: ErrorCode, + pub msg: StringMView<'a, 100>, +} + +#[cfg(feature = "alloc")] +impl From<&SErrorView<'_>> for SError { + #[must_use] + fn from(v: &SErrorView<'_>) -> Self { + Self { + code: v.code, + msg: v.msg.to_stringm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SError { + #[must_use] + fn from(v: SErrorView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SErrorView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.code.write_xdr(w)?; + self.msg.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_bytes.rs b/src/generated/sc_bytes.rs index 69185c53d..41d28e1a5 100644 --- a/src/generated/sc_bytes.rs +++ b/src/generated/sc_bytes.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for ScBytes { self.0 .0 } } + +/// ScBytesView is a borrowing equivalent of [`ScBytes`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScBytesView<'a>(pub BytesMView<'a>); + +#[cfg(feature = "alloc")] +impl From<&ScBytesView<'_>> for ScBytes { + #[must_use] + fn from(v: &ScBytesView<'_>) -> Self { + Self(v.0.to_bytesm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for ScBytes { + #[must_use] + fn from(v: ScBytesView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScBytesView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/sc_contract_instance.rs b/src/generated/sc_contract_instance.rs index b59a56909..ae502a6d5 100644 --- a/src/generated/sc_contract_instance.rs +++ b/src/generated/sc_contract_instance.rs @@ -48,3 +48,41 @@ impl WriteXdr for ScContractInstance { }) } } + +/// ScContractInstanceView is a borrowing equivalent of [`ScContractInstance`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScContractInstanceView<'a> { + pub executable: ContractExecutableView<'a>, + pub storage: Option>, +} + +#[cfg(feature = "alloc")] +impl From<&ScContractInstanceView<'_>> for ScContractInstance { + #[must_use] + fn from(v: &ScContractInstanceView<'_>) -> Self { + Self { + executable: (&v.executable).into(), + storage: v.storage.as_ref().map(Into::into), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScContractInstance { + #[must_use] + fn from(v: ScContractInstanceView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScContractInstanceView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.executable.write_xdr(w)?; + self.storage.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_map.rs b/src/generated/sc_map.rs index 4d31a0d5b..7459b1423 100644 --- a/src/generated/sc_map.rs +++ b/src/generated/sc_map.rs @@ -107,3 +107,31 @@ impl AsRef<[ScMapEntry]> for ScMap { self.0 .0 } } + +/// ScMapView is a borrowing equivalent of [`ScMap`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScMapView<'a>(pub VecMView<'a, ScMapEntryView<'a>>); + +#[cfg(feature = "alloc")] +impl From<&ScMapView<'_>> for ScMap { + #[must_use] + fn from(v: &ScMapView<'_>) -> Self { + Self(v.0.to_vecm_from()) + } +} + +#[cfg(feature = "alloc")] +impl From> for ScMap { + #[must_use] + fn from(v: ScMapView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScMapView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/sc_map_entry.rs b/src/generated/sc_map_entry.rs index ea3fcc4e9..e0abb5c94 100644 --- a/src/generated/sc_map_entry.rs +++ b/src/generated/sc_map_entry.rs @@ -49,3 +49,41 @@ impl WriteXdr for ScMapEntry { }) } } + +/// ScMapEntryView is a borrowing equivalent of [`ScMapEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScMapEntryView<'a> { + pub key: ScValView<'a>, + pub val: ScValView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScMapEntryView<'_>> for ScMapEntry { + #[must_use] + fn from(v: &ScMapEntryView<'_>) -> Self { + Self { + key: (&v.key).into(), + val: (&v.val).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScMapEntry { + #[must_use] + fn from(v: ScMapEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScMapEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.key.write_xdr(w)?; + self.val.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_meta_entry.rs b/src/generated/sc_meta_entry.rs index 2b31be76c..0307882a3 100644 --- a/src/generated/sc_meta_entry.rs +++ b/src/generated/sc_meta_entry.rs @@ -128,3 +128,54 @@ impl WriteXdr for ScMetaEntry { }) } } + +/// ScMetaEntryView is a borrowing equivalent of [`ScMetaEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ScMetaEntryView<'a> { + ScMetaV0(ScMetaV0View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ScMetaEntryView<'_>> for ScMetaEntry { + #[must_use] + fn from(v: &ScMetaEntryView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ScMetaEntryView::ScMetaV0(value) => Self::ScMetaV0(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScMetaEntry { + #[must_use] + fn from(v: ScMetaEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl ScMetaEntryView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ScMetaKind { + #[allow(clippy::match_same_arms)] + match self { + Self::ScMetaV0(_) => ScMetaKind::ScMetaV0, + } + } +} + +impl WriteXdr for ScMetaEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::ScMetaV0(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/sc_meta_v0.rs b/src/generated/sc_meta_v0.rs index 730f4317e..bb3016324 100644 --- a/src/generated/sc_meta_v0.rs +++ b/src/generated/sc_meta_v0.rs @@ -49,3 +49,41 @@ impl WriteXdr for ScMetaV0 { }) } } + +/// ScMetaV0View is a borrowing equivalent of [`ScMetaV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScMetaV0View<'a> { + pub key: StringMView<'a>, + pub val: StringMView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScMetaV0View<'_>> for ScMetaV0 { + #[must_use] + fn from(v: &ScMetaV0View<'_>) -> Self { + Self { + key: v.key.to_stringm(), + val: v.val.to_stringm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScMetaV0 { + #[must_use] + fn from(v: ScMetaV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScMetaV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.key.write_xdr(w)?; + self.val.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_entry.rs b/src/generated/sc_spec_entry.rs index fabc830be..eb8f7b23d 100644 --- a/src/generated/sc_spec_entry.rs +++ b/src/generated/sc_spec_entry.rs @@ -179,3 +179,74 @@ impl WriteXdr for ScSpecEntry { }) } } + +/// ScSpecEntryView is a borrowing equivalent of [`ScSpecEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ScSpecEntryView<'a> { + FunctionV0(ScSpecFunctionV0View<'a>), + UdtStructV0(ScSpecUdtStructV0View<'a>), + UdtUnionV0(ScSpecUdtUnionV0View<'a>), + UdtEnumV0(ScSpecUdtEnumV0View<'a>), + UdtErrorEnumV0(ScSpecUdtErrorEnumV0View<'a>), + EventV0(ScSpecEventV0View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecEntryView<'_>> for ScSpecEntry { + #[must_use] + fn from(v: &ScSpecEntryView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ScSpecEntryView::FunctionV0(value) => Self::FunctionV0(value.into()), + ScSpecEntryView::UdtStructV0(value) => Self::UdtStructV0(value.into()), + ScSpecEntryView::UdtUnionV0(value) => Self::UdtUnionV0(value.into()), + ScSpecEntryView::UdtEnumV0(value) => Self::UdtEnumV0(value.into()), + ScSpecEntryView::UdtErrorEnumV0(value) => Self::UdtErrorEnumV0(value.into()), + ScSpecEntryView::EventV0(value) => Self::EventV0(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecEntry { + #[must_use] + fn from(v: ScSpecEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl ScSpecEntryView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ScSpecEntryKind { + #[allow(clippy::match_same_arms)] + match self { + Self::FunctionV0(_) => ScSpecEntryKind::FunctionV0, + Self::UdtStructV0(_) => ScSpecEntryKind::UdtStructV0, + Self::UdtUnionV0(_) => ScSpecEntryKind::UdtUnionV0, + Self::UdtEnumV0(_) => ScSpecEntryKind::UdtEnumV0, + Self::UdtErrorEnumV0(_) => ScSpecEntryKind::UdtErrorEnumV0, + Self::EventV0(_) => ScSpecEntryKind::EventV0, + } + } +} + +impl WriteXdr for ScSpecEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::FunctionV0(v) => v.write_xdr(w)?, + Self::UdtStructV0(v) => v.write_xdr(w)?, + Self::UdtUnionV0(v) => v.write_xdr(w)?, + Self::UdtEnumV0(v) => v.write_xdr(w)?, + Self::UdtErrorEnumV0(v) => v.write_xdr(w)?, + Self::EventV0(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_event_param_v0.rs b/src/generated/sc_spec_event_param_v0.rs index a3009fa33..a2df0c288 100644 --- a/src/generated/sc_spec_event_param_v0.rs +++ b/src/generated/sc_spec_event_param_v0.rs @@ -62,3 +62,47 @@ impl WriteXdr for ScSpecEventParamV0 { }) } } + +/// ScSpecEventParamV0View is a borrowing equivalent of [`ScSpecEventParamV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecEventParamV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub name: StringMView<'a, 30>, + pub type_: ScSpecTypeDefView<'a>, + pub location: ScSpecEventParamLocationV0, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecEventParamV0View<'_>> for ScSpecEventParamV0 { + #[must_use] + fn from(v: &ScSpecEventParamV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + name: v.name.to_stringm(), + type_: (&v.type_).into(), + location: v.location, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecEventParamV0 { + #[must_use] + fn from(v: ScSpecEventParamV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecEventParamV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.name.write_xdr(w)?; + self.type_.write_xdr(w)?; + self.location.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_event_v0.rs b/src/generated/sc_spec_event_v0.rs index f8b0af7c5..b88bb3980 100644 --- a/src/generated/sc_spec_event_v0.rs +++ b/src/generated/sc_spec_event_v0.rs @@ -65,3 +65,53 @@ impl WriteXdr for ScSpecEventV0 { }) } } + +/// ScSpecEventV0View is a borrowing equivalent of [`ScSpecEventV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecEventV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub lib: StringMView<'a, 80>, + pub name: ScSymbolView<'a>, + pub prefix_topics: VecMView<'a, ScSymbolView<'a>, 2>, + pub params: VecMView<'a, ScSpecEventParamV0View<'a>>, + pub data_format: ScSpecEventDataFormat, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecEventV0View<'_>> for ScSpecEventV0 { + #[must_use] + fn from(v: &ScSpecEventV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + lib: v.lib.to_stringm(), + name: (&v.name).into(), + prefix_topics: v.prefix_topics.to_vecm_from(), + params: v.params.to_vecm_from(), + data_format: v.data_format, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecEventV0 { + #[must_use] + fn from(v: ScSpecEventV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecEventV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.lib.write_xdr(w)?; + self.name.write_xdr(w)?; + self.prefix_topics.write_xdr(w)?; + self.params.write_xdr(w)?; + self.data_format.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_function_input_v0.rs b/src/generated/sc_spec_function_input_v0.rs index 41fc340d4..73e02b282 100644 --- a/src/generated/sc_spec_function_input_v0.rs +++ b/src/generated/sc_spec_function_input_v0.rs @@ -58,3 +58,44 @@ impl WriteXdr for ScSpecFunctionInputV0 { }) } } + +/// ScSpecFunctionInputV0View is a borrowing equivalent of [`ScSpecFunctionInputV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecFunctionInputV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub name: StringMView<'a, 30>, + pub type_: ScSpecTypeDefView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecFunctionInputV0View<'_>> for ScSpecFunctionInputV0 { + #[must_use] + fn from(v: &ScSpecFunctionInputV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + name: v.name.to_stringm(), + type_: (&v.type_).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecFunctionInputV0 { + #[must_use] + fn from(v: ScSpecFunctionInputV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecFunctionInputV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.name.write_xdr(w)?; + self.type_.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_function_v0.rs b/src/generated/sc_spec_function_v0.rs index ec2e7f812..e069dfe0d 100644 --- a/src/generated/sc_spec_function_v0.rs +++ b/src/generated/sc_spec_function_v0.rs @@ -57,3 +57,47 @@ impl WriteXdr for ScSpecFunctionV0 { }) } } + +/// ScSpecFunctionV0View is a borrowing equivalent of [`ScSpecFunctionV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecFunctionV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub name: ScSymbolView<'a>, + pub inputs: VecMView<'a, ScSpecFunctionInputV0View<'a>>, + pub outputs: VecMView<'a, ScSpecTypeDefView<'a>, 1>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecFunctionV0View<'_>> for ScSpecFunctionV0 { + #[must_use] + fn from(v: &ScSpecFunctionV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + name: (&v.name).into(), + inputs: v.inputs.to_vecm_from(), + outputs: v.outputs.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecFunctionV0 { + #[must_use] + fn from(v: ScSpecFunctionV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecFunctionV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.name.write_xdr(w)?; + self.inputs.write_xdr(w)?; + self.outputs.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_type_def.rs b/src/generated/sc_spec_type_def.rs index 82810ecf9..2e90cef0f 100644 --- a/src/generated/sc_spec_type_def.rs +++ b/src/generated/sc_spec_type_def.rs @@ -339,3 +339,154 @@ impl WriteXdr for ScSpecTypeDef { }) } } + +/// ScSpecTypeDefView is a borrowing equivalent of [`ScSpecTypeDef`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ScSpecTypeDefView<'a> { + Val, + Bool, + Void, + Error, + U32, + I32, + U64, + I64, + Timepoint, + Duration, + U128, + I128, + U256, + I256, + Bytes, + String, + Symbol, + Address, + MuxedAddress, + Option(&'a ScSpecTypeOptionView<'a>), + Result(&'a ScSpecTypeResultView<'a>), + Vec(&'a ScSpecTypeVecView<'a>), + Map(&'a ScSpecTypeMapView<'a>), + Tuple(&'a ScSpecTypeTupleView<'a>), + BytesN(ScSpecTypeBytesN), + Udt(ScSpecTypeUdtView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecTypeDefView<'_>> for ScSpecTypeDef { + #[must_use] + fn from(v: &ScSpecTypeDefView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ScSpecTypeDefView::Val => Self::Val, + ScSpecTypeDefView::Bool => Self::Bool, + ScSpecTypeDefView::Void => Self::Void, + ScSpecTypeDefView::Error => Self::Error, + ScSpecTypeDefView::U32 => Self::U32, + ScSpecTypeDefView::I32 => Self::I32, + ScSpecTypeDefView::U64 => Self::U64, + ScSpecTypeDefView::I64 => Self::I64, + ScSpecTypeDefView::Timepoint => Self::Timepoint, + ScSpecTypeDefView::Duration => Self::Duration, + ScSpecTypeDefView::U128 => Self::U128, + ScSpecTypeDefView::I128 => Self::I128, + ScSpecTypeDefView::U256 => Self::U256, + ScSpecTypeDefView::I256 => Self::I256, + ScSpecTypeDefView::Bytes => Self::Bytes, + ScSpecTypeDefView::String => Self::String, + ScSpecTypeDefView::Symbol => Self::Symbol, + ScSpecTypeDefView::Address => Self::Address, + ScSpecTypeDefView::MuxedAddress => Self::MuxedAddress, + ScSpecTypeDefView::Option(value) => Self::Option(Box::new((*value).into())), + ScSpecTypeDefView::Result(value) => Self::Result(Box::new((*value).into())), + ScSpecTypeDefView::Vec(value) => Self::Vec(Box::new((*value).into())), + ScSpecTypeDefView::Map(value) => Self::Map(Box::new((*value).into())), + ScSpecTypeDefView::Tuple(value) => Self::Tuple(Box::new((*value).into())), + ScSpecTypeDefView::BytesN(value) => Self::BytesN(value.clone()), + ScSpecTypeDefView::Udt(value) => Self::Udt(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecTypeDef { + #[must_use] + fn from(v: ScSpecTypeDefView<'_>) -> Self { + Self::from(&v) + } +} + +impl ScSpecTypeDefView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ScSpecType { + #[allow(clippy::match_same_arms)] + match self { + Self::Val => ScSpecType::Val, + Self::Bool => ScSpecType::Bool, + Self::Void => ScSpecType::Void, + Self::Error => ScSpecType::Error, + Self::U32 => ScSpecType::U32, + Self::I32 => ScSpecType::I32, + Self::U64 => ScSpecType::U64, + Self::I64 => ScSpecType::I64, + Self::Timepoint => ScSpecType::Timepoint, + Self::Duration => ScSpecType::Duration, + Self::U128 => ScSpecType::U128, + Self::I128 => ScSpecType::I128, + Self::U256 => ScSpecType::U256, + Self::I256 => ScSpecType::I256, + Self::Bytes => ScSpecType::Bytes, + Self::String => ScSpecType::String, + Self::Symbol => ScSpecType::Symbol, + Self::Address => ScSpecType::Address, + Self::MuxedAddress => ScSpecType::MuxedAddress, + Self::Option(_) => ScSpecType::Option, + Self::Result(_) => ScSpecType::Result, + Self::Vec(_) => ScSpecType::Vec, + Self::Map(_) => ScSpecType::Map, + Self::Tuple(_) => ScSpecType::Tuple, + Self::BytesN(_) => ScSpecType::BytesN, + Self::Udt(_) => ScSpecType::Udt, + } + } +} + +impl WriteXdr for ScSpecTypeDefView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Val => ().write_xdr(w)?, + Self::Bool => ().write_xdr(w)?, + Self::Void => ().write_xdr(w)?, + Self::Error => ().write_xdr(w)?, + Self::U32 => ().write_xdr(w)?, + Self::I32 => ().write_xdr(w)?, + Self::U64 => ().write_xdr(w)?, + Self::I64 => ().write_xdr(w)?, + Self::Timepoint => ().write_xdr(w)?, + Self::Duration => ().write_xdr(w)?, + Self::U128 => ().write_xdr(w)?, + Self::I128 => ().write_xdr(w)?, + Self::U256 => ().write_xdr(w)?, + Self::I256 => ().write_xdr(w)?, + Self::Bytes => ().write_xdr(w)?, + Self::String => ().write_xdr(w)?, + Self::Symbol => ().write_xdr(w)?, + Self::Address => ().write_xdr(w)?, + Self::MuxedAddress => ().write_xdr(w)?, + Self::Option(v) => v.write_xdr(w)?, + Self::Result(v) => v.write_xdr(w)?, + Self::Vec(v) => v.write_xdr(w)?, + Self::Map(v) => v.write_xdr(w)?, + Self::Tuple(v) => v.write_xdr(w)?, + Self::BytesN(v) => v.write_xdr(w)?, + Self::Udt(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_type_map.rs b/src/generated/sc_spec_type_map.rs index a078929ae..fd5b8463e 100644 --- a/src/generated/sc_spec_type_map.rs +++ b/src/generated/sc_spec_type_map.rs @@ -49,3 +49,41 @@ impl WriteXdr for ScSpecTypeMap { }) } } + +/// ScSpecTypeMapView is a borrowing equivalent of [`ScSpecTypeMap`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecTypeMapView<'a> { + pub key_type: &'a ScSpecTypeDefView<'a>, + pub value_type: &'a ScSpecTypeDefView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecTypeMapView<'_>> for ScSpecTypeMap { + #[must_use] + fn from(v: &ScSpecTypeMapView<'_>) -> Self { + Self { + key_type: Box::new(v.key_type.into()), + value_type: Box::new(v.value_type.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecTypeMap { + #[must_use] + fn from(v: ScSpecTypeMapView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecTypeMapView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.key_type.write_xdr(w)?; + self.value_type.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_type_option.rs b/src/generated/sc_spec_type_option.rs index f8cb6748e..1dd325b76 100644 --- a/src/generated/sc_spec_type_option.rs +++ b/src/generated/sc_spec_type_option.rs @@ -45,3 +45,38 @@ impl WriteXdr for ScSpecTypeOption { }) } } + +/// ScSpecTypeOptionView is a borrowing equivalent of [`ScSpecTypeOption`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecTypeOptionView<'a> { + pub value_type: &'a ScSpecTypeDefView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecTypeOptionView<'_>> for ScSpecTypeOption { + #[must_use] + fn from(v: &ScSpecTypeOptionView<'_>) -> Self { + Self { + value_type: Box::new(v.value_type.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecTypeOption { + #[must_use] + fn from(v: ScSpecTypeOptionView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecTypeOptionView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.value_type.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_type_result.rs b/src/generated/sc_spec_type_result.rs index ffd6a7395..8696c6d26 100644 --- a/src/generated/sc_spec_type_result.rs +++ b/src/generated/sc_spec_type_result.rs @@ -49,3 +49,41 @@ impl WriteXdr for ScSpecTypeResult { }) } } + +/// ScSpecTypeResultView is a borrowing equivalent of [`ScSpecTypeResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecTypeResultView<'a> { + pub ok_type: &'a ScSpecTypeDefView<'a>, + pub error_type: &'a ScSpecTypeDefView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecTypeResultView<'_>> for ScSpecTypeResult { + #[must_use] + fn from(v: &ScSpecTypeResultView<'_>) -> Self { + Self { + ok_type: Box::new(v.ok_type.into()), + error_type: Box::new(v.error_type.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecTypeResult { + #[must_use] + fn from(v: ScSpecTypeResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecTypeResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ok_type.write_xdr(w)?; + self.error_type.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_type_tuple.rs b/src/generated/sc_spec_type_tuple.rs index fb2488e48..88295279d 100644 --- a/src/generated/sc_spec_type_tuple.rs +++ b/src/generated/sc_spec_type_tuple.rs @@ -45,3 +45,38 @@ impl WriteXdr for ScSpecTypeTuple { }) } } + +/// ScSpecTypeTupleView is a borrowing equivalent of [`ScSpecTypeTuple`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecTypeTupleView<'a> { + pub value_types: VecMView<'a, ScSpecTypeDefView<'a>, 12>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecTypeTupleView<'_>> for ScSpecTypeTuple { + #[must_use] + fn from(v: &ScSpecTypeTupleView<'_>) -> Self { + Self { + value_types: v.value_types.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecTypeTuple { + #[must_use] + fn from(v: ScSpecTypeTupleView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecTypeTupleView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.value_types.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_type_udt.rs b/src/generated/sc_spec_type_udt.rs index 9a9830cb5..271ef5318 100644 --- a/src/generated/sc_spec_type_udt.rs +++ b/src/generated/sc_spec_type_udt.rs @@ -45,3 +45,38 @@ impl WriteXdr for ScSpecTypeUdt { }) } } + +/// ScSpecTypeUdtView is a borrowing equivalent of [`ScSpecTypeUdt`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecTypeUdtView<'a> { + pub name: StringMView<'a, 60>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecTypeUdtView<'_>> for ScSpecTypeUdt { + #[must_use] + fn from(v: &ScSpecTypeUdtView<'_>) -> Self { + Self { + name: v.name.to_stringm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecTypeUdt { + #[must_use] + fn from(v: ScSpecTypeUdtView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecTypeUdtView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.name.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_type_vec.rs b/src/generated/sc_spec_type_vec.rs index 0f55076a5..f57987ea4 100644 --- a/src/generated/sc_spec_type_vec.rs +++ b/src/generated/sc_spec_type_vec.rs @@ -45,3 +45,38 @@ impl WriteXdr for ScSpecTypeVec { }) } } + +/// ScSpecTypeVecView is a borrowing equivalent of [`ScSpecTypeVec`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecTypeVecView<'a> { + pub element_type: &'a ScSpecTypeDefView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecTypeVecView<'_>> for ScSpecTypeVec { + #[must_use] + fn from(v: &ScSpecTypeVecView<'_>) -> Self { + Self { + element_type: Box::new(v.element_type.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecTypeVec { + #[must_use] + fn from(v: ScSpecTypeVecView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecTypeVecView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.element_type.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_enum_case_v0.rs b/src/generated/sc_spec_udt_enum_case_v0.rs index 0da24ca63..f21984247 100644 --- a/src/generated/sc_spec_udt_enum_case_v0.rs +++ b/src/generated/sc_spec_udt_enum_case_v0.rs @@ -53,3 +53,44 @@ impl WriteXdr for ScSpecUdtEnumCaseV0 { }) } } + +/// ScSpecUdtEnumCaseV0View is a borrowing equivalent of [`ScSpecUdtEnumCaseV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecUdtEnumCaseV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub name: StringMView<'a, 60>, + pub value: u32, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtEnumCaseV0View<'_>> for ScSpecUdtEnumCaseV0 { + #[must_use] + fn from(v: &ScSpecUdtEnumCaseV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + name: v.name.to_stringm(), + value: v.value, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtEnumCaseV0 { + #[must_use] + fn from(v: ScSpecUdtEnumCaseV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecUdtEnumCaseV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.name.write_xdr(w)?; + self.value.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_enum_v0.rs b/src/generated/sc_spec_udt_enum_v0.rs index 423b65c3b..77b1a743e 100644 --- a/src/generated/sc_spec_udt_enum_v0.rs +++ b/src/generated/sc_spec_udt_enum_v0.rs @@ -57,3 +57,47 @@ impl WriteXdr for ScSpecUdtEnumV0 { }) } } + +/// ScSpecUdtEnumV0View is a borrowing equivalent of [`ScSpecUdtEnumV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecUdtEnumV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub lib: StringMView<'a, 80>, + pub name: StringMView<'a, 60>, + pub cases: VecMView<'a, ScSpecUdtEnumCaseV0View<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtEnumV0View<'_>> for ScSpecUdtEnumV0 { + #[must_use] + fn from(v: &ScSpecUdtEnumV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + lib: v.lib.to_stringm(), + name: v.name.to_stringm(), + cases: v.cases.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtEnumV0 { + #[must_use] + fn from(v: ScSpecUdtEnumV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecUdtEnumV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.lib.write_xdr(w)?; + self.name.write_xdr(w)?; + self.cases.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_error_enum_case_v0.rs b/src/generated/sc_spec_udt_error_enum_case_v0.rs index d4269b73b..8de20e680 100644 --- a/src/generated/sc_spec_udt_error_enum_case_v0.rs +++ b/src/generated/sc_spec_udt_error_enum_case_v0.rs @@ -53,3 +53,44 @@ impl WriteXdr for ScSpecUdtErrorEnumCaseV0 { }) } } + +/// ScSpecUdtErrorEnumCaseV0View is a borrowing equivalent of [`ScSpecUdtErrorEnumCaseV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecUdtErrorEnumCaseV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub name: StringMView<'a, 60>, + pub value: u32, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtErrorEnumCaseV0View<'_>> for ScSpecUdtErrorEnumCaseV0 { + #[must_use] + fn from(v: &ScSpecUdtErrorEnumCaseV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + name: v.name.to_stringm(), + value: v.value, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtErrorEnumCaseV0 { + #[must_use] + fn from(v: ScSpecUdtErrorEnumCaseV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecUdtErrorEnumCaseV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.name.write_xdr(w)?; + self.value.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_error_enum_v0.rs b/src/generated/sc_spec_udt_error_enum_v0.rs index c707150cd..5ff545aa1 100644 --- a/src/generated/sc_spec_udt_error_enum_v0.rs +++ b/src/generated/sc_spec_udt_error_enum_v0.rs @@ -57,3 +57,47 @@ impl WriteXdr for ScSpecUdtErrorEnumV0 { }) } } + +/// ScSpecUdtErrorEnumV0View is a borrowing equivalent of [`ScSpecUdtErrorEnumV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecUdtErrorEnumV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub lib: StringMView<'a, 80>, + pub name: StringMView<'a, 60>, + pub cases: VecMView<'a, ScSpecUdtErrorEnumCaseV0View<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtErrorEnumV0View<'_>> for ScSpecUdtErrorEnumV0 { + #[must_use] + fn from(v: &ScSpecUdtErrorEnumV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + lib: v.lib.to_stringm(), + name: v.name.to_stringm(), + cases: v.cases.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtErrorEnumV0 { + #[must_use] + fn from(v: ScSpecUdtErrorEnumV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecUdtErrorEnumV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.lib.write_xdr(w)?; + self.name.write_xdr(w)?; + self.cases.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_struct_field_v0.rs b/src/generated/sc_spec_udt_struct_field_v0.rs index 532922608..c5f203f20 100644 --- a/src/generated/sc_spec_udt_struct_field_v0.rs +++ b/src/generated/sc_spec_udt_struct_field_v0.rs @@ -58,3 +58,44 @@ impl WriteXdr for ScSpecUdtStructFieldV0 { }) } } + +/// ScSpecUdtStructFieldV0View is a borrowing equivalent of [`ScSpecUdtStructFieldV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecUdtStructFieldV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub name: StringMView<'a, 30>, + pub type_: ScSpecTypeDefView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtStructFieldV0View<'_>> for ScSpecUdtStructFieldV0 { + #[must_use] + fn from(v: &ScSpecUdtStructFieldV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + name: v.name.to_stringm(), + type_: (&v.type_).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtStructFieldV0 { + #[must_use] + fn from(v: ScSpecUdtStructFieldV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecUdtStructFieldV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.name.write_xdr(w)?; + self.type_.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_struct_v0.rs b/src/generated/sc_spec_udt_struct_v0.rs index 2e275ea98..ebffaa8c3 100644 --- a/src/generated/sc_spec_udt_struct_v0.rs +++ b/src/generated/sc_spec_udt_struct_v0.rs @@ -57,3 +57,47 @@ impl WriteXdr for ScSpecUdtStructV0 { }) } } + +/// ScSpecUdtStructV0View is a borrowing equivalent of [`ScSpecUdtStructV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecUdtStructV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub lib: StringMView<'a, 80>, + pub name: StringMView<'a, 60>, + pub fields: VecMView<'a, ScSpecUdtStructFieldV0View<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtStructV0View<'_>> for ScSpecUdtStructV0 { + #[must_use] + fn from(v: &ScSpecUdtStructV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + lib: v.lib.to_stringm(), + name: v.name.to_stringm(), + fields: v.fields.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtStructV0 { + #[must_use] + fn from(v: ScSpecUdtStructV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecUdtStructV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.lib.write_xdr(w)?; + self.name.write_xdr(w)?; + self.fields.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_union_case_tuple_v0.rs b/src/generated/sc_spec_udt_union_case_tuple_v0.rs index 3b12a5b63..9c4530e46 100644 --- a/src/generated/sc_spec_udt_union_case_tuple_v0.rs +++ b/src/generated/sc_spec_udt_union_case_tuple_v0.rs @@ -58,3 +58,44 @@ impl WriteXdr for ScSpecUdtUnionCaseTupleV0 { }) } } + +/// ScSpecUdtUnionCaseTupleV0View is a borrowing equivalent of [`ScSpecUdtUnionCaseTupleV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecUdtUnionCaseTupleV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub name: StringMView<'a, 60>, + pub type_: VecMView<'a, ScSpecTypeDefView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtUnionCaseTupleV0View<'_>> for ScSpecUdtUnionCaseTupleV0 { + #[must_use] + fn from(v: &ScSpecUdtUnionCaseTupleV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + name: v.name.to_stringm(), + type_: v.type_.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtUnionCaseTupleV0 { + #[must_use] + fn from(v: ScSpecUdtUnionCaseTupleV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecUdtUnionCaseTupleV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.name.write_xdr(w)?; + self.type_.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_union_case_v0.rs b/src/generated/sc_spec_udt_union_case_v0.rs index 6c91eebae..e558debf6 100644 --- a/src/generated/sc_spec_udt_union_case_v0.rs +++ b/src/generated/sc_spec_udt_union_case_v0.rs @@ -142,3 +142,58 @@ impl WriteXdr for ScSpecUdtUnionCaseV0 { }) } } + +/// ScSpecUdtUnionCaseV0View is a borrowing equivalent of [`ScSpecUdtUnionCaseV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ScSpecUdtUnionCaseV0View<'a> { + VoidV0(ScSpecUdtUnionCaseVoidV0View<'a>), + TupleV0(ScSpecUdtUnionCaseTupleV0View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtUnionCaseV0View<'_>> for ScSpecUdtUnionCaseV0 { + #[must_use] + fn from(v: &ScSpecUdtUnionCaseV0View<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ScSpecUdtUnionCaseV0View::VoidV0(value) => Self::VoidV0(value.into()), + ScSpecUdtUnionCaseV0View::TupleV0(value) => Self::TupleV0(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtUnionCaseV0 { + #[must_use] + fn from(v: ScSpecUdtUnionCaseV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl ScSpecUdtUnionCaseV0View<'_> { + #[must_use] + pub const fn discriminant(&self) -> ScSpecUdtUnionCaseV0Kind { + #[allow(clippy::match_same_arms)] + match self { + Self::VoidV0(_) => ScSpecUdtUnionCaseV0Kind::VoidV0, + Self::TupleV0(_) => ScSpecUdtUnionCaseV0Kind::TupleV0, + } + } +} + +impl WriteXdr for ScSpecUdtUnionCaseV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::VoidV0(v) => v.write_xdr(w)?, + Self::TupleV0(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_union_case_void_v0.rs b/src/generated/sc_spec_udt_union_case_void_v0.rs index 2a85d2fa2..4e8320a20 100644 --- a/src/generated/sc_spec_udt_union_case_void_v0.rs +++ b/src/generated/sc_spec_udt_union_case_void_v0.rs @@ -49,3 +49,41 @@ impl WriteXdr for ScSpecUdtUnionCaseVoidV0 { }) } } + +/// ScSpecUdtUnionCaseVoidV0View is a borrowing equivalent of [`ScSpecUdtUnionCaseVoidV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecUdtUnionCaseVoidV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub name: StringMView<'a, 60>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtUnionCaseVoidV0View<'_>> for ScSpecUdtUnionCaseVoidV0 { + #[must_use] + fn from(v: &ScSpecUdtUnionCaseVoidV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + name: v.name.to_stringm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtUnionCaseVoidV0 { + #[must_use] + fn from(v: ScSpecUdtUnionCaseVoidV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecUdtUnionCaseVoidV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.name.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_spec_udt_union_v0.rs b/src/generated/sc_spec_udt_union_v0.rs index 3d962323b..cb009adbf 100644 --- a/src/generated/sc_spec_udt_union_v0.rs +++ b/src/generated/sc_spec_udt_union_v0.rs @@ -57,3 +57,47 @@ impl WriteXdr for ScSpecUdtUnionV0 { }) } } + +/// ScSpecUdtUnionV0View is a borrowing equivalent of [`ScSpecUdtUnionV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSpecUdtUnionV0View<'a> { + pub doc: StringMView<'a, 1024>, + pub lib: StringMView<'a, 80>, + pub name: StringMView<'a, 60>, + pub cases: VecMView<'a, ScSpecUdtUnionCaseV0View<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&ScSpecUdtUnionV0View<'_>> for ScSpecUdtUnionV0 { + #[must_use] + fn from(v: &ScSpecUdtUnionV0View<'_>) -> Self { + Self { + doc: v.doc.to_stringm(), + lib: v.lib.to_stringm(), + name: v.name.to_stringm(), + cases: v.cases.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSpecUdtUnionV0 { + #[must_use] + fn from(v: ScSpecUdtUnionV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSpecUdtUnionV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.doc.write_xdr(w)?; + self.lib.write_xdr(w)?; + self.name.write_xdr(w)?; + self.cases.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/sc_string.rs b/src/generated/sc_string.rs index 8ba82e412..5540106c1 100644 --- a/src/generated/sc_string.rs +++ b/src/generated/sc_string.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for ScString { self.0 .0 } } + +/// ScStringView is a borrowing equivalent of [`ScString`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScStringView<'a>(pub StringMView<'a>); + +#[cfg(feature = "alloc")] +impl From<&ScStringView<'_>> for ScString { + #[must_use] + fn from(v: &ScStringView<'_>) -> Self { + Self(v.0.to_stringm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for ScString { + #[must_use] + fn from(v: ScStringView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScStringView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/sc_symbol.rs b/src/generated/sc_symbol.rs index 8b41b8209..5dc112d45 100644 --- a/src/generated/sc_symbol.rs +++ b/src/generated/sc_symbol.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for ScSymbol { self.0 .0 } } + +/// ScSymbolView is a borrowing equivalent of [`ScSymbol`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScSymbolView<'a>(pub StringMView<'a, 32>); + +#[cfg(feature = "alloc")] +impl From<&ScSymbolView<'_>> for ScSymbol { + #[must_use] + fn from(v: &ScSymbolView<'_>) -> Self { + Self(v.0.to_stringm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for ScSymbol { + #[must_use] + fn from(v: ScSymbolView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScSymbolView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/sc_val.rs b/src/generated/sc_val.rs index 5f729159e..9e0bacc8b 100644 --- a/src/generated/sc_val.rs +++ b/src/generated/sc_val.rs @@ -358,3 +358,142 @@ impl WriteXdr for ScVal { }) } } + +/// ScValView is a borrowing equivalent of [`ScVal`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ScValView<'a> { + Bool(bool), + Void, + Error(ScError), + U32(u32), + I32(i32), + U64(u64), + I64(i64), + Timepoint(TimePoint), + Duration(Duration), + U128(UInt128Parts), + I128(Int128Parts), + U256(UInt256Parts), + I256(Int256Parts), + Bytes(ScBytesView<'a>), + String(ScStringView<'a>), + Symbol(ScSymbolView<'a>), + Vec(Option>), + Map(Option>), + Address(ScAddress), + ContractInstance(ScContractInstanceView<'a>), + LedgerKeyContractInstance, + LedgerKeyNonce(ScNonceKey), + ExecutableTag(ScStringView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ScValView<'_>> for ScVal { + #[must_use] + fn from(v: &ScValView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ScValView::Bool(value) => Self::Bool(*value), + ScValView::Void => Self::Void, + ScValView::Error(value) => Self::Error(value.clone()), + ScValView::U32(value) => Self::U32(*value), + ScValView::I32(value) => Self::I32(*value), + ScValView::U64(value) => Self::U64(*value), + ScValView::I64(value) => Self::I64(*value), + ScValView::Timepoint(value) => Self::Timepoint(value.clone()), + ScValView::Duration(value) => Self::Duration(value.clone()), + ScValView::U128(value) => Self::U128(value.clone()), + ScValView::I128(value) => Self::I128(value.clone()), + ScValView::U256(value) => Self::U256(value.clone()), + ScValView::I256(value) => Self::I256(value.clone()), + ScValView::Bytes(value) => Self::Bytes(value.into()), + ScValView::String(value) => Self::String(value.into()), + ScValView::Symbol(value) => Self::Symbol(value.into()), + ScValView::Vec(value) => Self::Vec(value.as_ref().map(Into::into)), + ScValView::Map(value) => Self::Map(value.as_ref().map(Into::into)), + ScValView::Address(value) => Self::Address(value.clone()), + ScValView::ContractInstance(value) => Self::ContractInstance(value.into()), + ScValView::LedgerKeyContractInstance => Self::LedgerKeyContractInstance, + ScValView::LedgerKeyNonce(value) => Self::LedgerKeyNonce(value.clone()), + ScValView::ExecutableTag(value) => Self::ExecutableTag(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScVal { + #[must_use] + fn from(v: ScValView<'_>) -> Self { + Self::from(&v) + } +} + +impl ScValView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ScValType { + #[allow(clippy::match_same_arms)] + match self { + Self::Bool(_) => ScValType::Bool, + Self::Void => ScValType::Void, + Self::Error(_) => ScValType::Error, + Self::U32(_) => ScValType::U32, + Self::I32(_) => ScValType::I32, + Self::U64(_) => ScValType::U64, + Self::I64(_) => ScValType::I64, + Self::Timepoint(_) => ScValType::Timepoint, + Self::Duration(_) => ScValType::Duration, + Self::U128(_) => ScValType::U128, + Self::I128(_) => ScValType::I128, + Self::U256(_) => ScValType::U256, + Self::I256(_) => ScValType::I256, + Self::Bytes(_) => ScValType::Bytes, + Self::String(_) => ScValType::String, + Self::Symbol(_) => ScValType::Symbol, + Self::Vec(_) => ScValType::Vec, + Self::Map(_) => ScValType::Map, + Self::Address(_) => ScValType::Address, + Self::ContractInstance(_) => ScValType::ContractInstance, + Self::LedgerKeyContractInstance => ScValType::LedgerKeyContractInstance, + Self::LedgerKeyNonce(_) => ScValType::LedgerKeyNonce, + Self::ExecutableTag(_) => ScValType::ExecutableTag, + } + } +} + +impl WriteXdr for ScValView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Bool(v) => v.write_xdr(w)?, + Self::Void => ().write_xdr(w)?, + Self::Error(v) => v.write_xdr(w)?, + Self::U32(v) => v.write_xdr(w)?, + Self::I32(v) => v.write_xdr(w)?, + Self::U64(v) => v.write_xdr(w)?, + Self::I64(v) => v.write_xdr(w)?, + Self::Timepoint(v) => v.write_xdr(w)?, + Self::Duration(v) => v.write_xdr(w)?, + Self::U128(v) => v.write_xdr(w)?, + Self::I128(v) => v.write_xdr(w)?, + Self::U256(v) => v.write_xdr(w)?, + Self::I256(v) => v.write_xdr(w)?, + Self::Bytes(v) => v.write_xdr(w)?, + Self::String(v) => v.write_xdr(w)?, + Self::Symbol(v) => v.write_xdr(w)?, + Self::Vec(v) => v.write_xdr(w)?, + Self::Map(v) => v.write_xdr(w)?, + Self::Address(v) => v.write_xdr(w)?, + Self::ContractInstance(v) => v.write_xdr(w)?, + Self::LedgerKeyContractInstance => ().write_xdr(w)?, + Self::LedgerKeyNonce(v) => v.write_xdr(w)?, + Self::ExecutableTag(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/sc_vec.rs b/src/generated/sc_vec.rs index 6f4cfe7d1..66ac76843 100644 --- a/src/generated/sc_vec.rs +++ b/src/generated/sc_vec.rs @@ -107,3 +107,31 @@ impl AsRef<[ScVal]> for ScVec { self.0 .0 } } + +/// ScVecView is a borrowing equivalent of [`ScVec`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScVecView<'a>(pub VecMView<'a, ScValView<'a>>); + +#[cfg(feature = "alloc")] +impl From<&ScVecView<'_>> for ScVec { + #[must_use] + fn from(v: &ScVecView<'_>) -> Self { + Self(v.0.to_vecm_from()) + } +} + +#[cfg(feature = "alloc")] +impl From> for ScVec { + #[must_use] + fn from(v: ScVecView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScVecView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/scp_ballot.rs b/src/generated/scp_ballot.rs index 7c20c1206..035d9af16 100644 --- a/src/generated/scp_ballot.rs +++ b/src/generated/scp_ballot.rs @@ -49,3 +49,41 @@ impl WriteXdr for ScpBallot { }) } } + +/// ScpBallotView is a borrowing equivalent of [`ScpBallot`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScpBallotView<'a> { + pub counter: u32, + pub value: ValueView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScpBallotView<'_>> for ScpBallot { + #[must_use] + fn from(v: &ScpBallotView<'_>) -> Self { + Self { + counter: v.counter, + value: (&v.value).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpBallot { + #[must_use] + fn from(v: ScpBallotView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScpBallotView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.counter.write_xdr(w)?; + self.value.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/scp_envelope.rs b/src/generated/scp_envelope.rs index c886a2e7a..2dacb9e11 100644 --- a/src/generated/scp_envelope.rs +++ b/src/generated/scp_envelope.rs @@ -49,3 +49,41 @@ impl WriteXdr for ScpEnvelope { }) } } + +/// ScpEnvelopeView is a borrowing equivalent of [`ScpEnvelope`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScpEnvelopeView<'a> { + pub statement: ScpStatementView<'a>, + pub signature: SignatureView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScpEnvelopeView<'_>> for ScpEnvelope { + #[must_use] + fn from(v: &ScpEnvelopeView<'_>) -> Self { + Self { + statement: (&v.statement).into(), + signature: (&v.signature).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpEnvelope { + #[must_use] + fn from(v: ScpEnvelopeView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScpEnvelopeView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.statement.write_xdr(w)?; + self.signature.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/scp_history_entry.rs b/src/generated/scp_history_entry.rs index 68ff88cc2..8e09cd853 100644 --- a/src/generated/scp_history_entry.rs +++ b/src/generated/scp_history_entry.rs @@ -128,3 +128,54 @@ impl WriteXdr for ScpHistoryEntry { }) } } + +/// ScpHistoryEntryView is a borrowing equivalent of [`ScpHistoryEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ScpHistoryEntryView<'a> { + V0(ScpHistoryEntryV0View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ScpHistoryEntryView<'_>> for ScpHistoryEntry { + #[must_use] + fn from(v: &ScpHistoryEntryView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ScpHistoryEntryView::V0(value) => Self::V0(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpHistoryEntry { + #[must_use] + fn from(v: ScpHistoryEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl ScpHistoryEntryView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + } + } +} + +impl WriteXdr for ScpHistoryEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/scp_history_entry_v0.rs b/src/generated/scp_history_entry_v0.rs index 45dee8be4..9f14f0100 100644 --- a/src/generated/scp_history_entry_v0.rs +++ b/src/generated/scp_history_entry_v0.rs @@ -49,3 +49,41 @@ impl WriteXdr for ScpHistoryEntryV0 { }) } } + +/// ScpHistoryEntryV0View is a borrowing equivalent of [`ScpHistoryEntryV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScpHistoryEntryV0View<'a> { + pub quorum_sets: VecMView<'a, ScpQuorumSetView<'a>>, + pub ledger_messages: LedgerScpMessagesView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScpHistoryEntryV0View<'_>> for ScpHistoryEntryV0 { + #[must_use] + fn from(v: &ScpHistoryEntryV0View<'_>) -> Self { + Self { + quorum_sets: v.quorum_sets.to_vecm_from(), + ledger_messages: (&v.ledger_messages).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpHistoryEntryV0 { + #[must_use] + fn from(v: ScpHistoryEntryV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScpHistoryEntryV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.quorum_sets.write_xdr(w)?; + self.ledger_messages.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/scp_nomination.rs b/src/generated/scp_nomination.rs index cb7e4af51..6dda33f8a 100644 --- a/src/generated/scp_nomination.rs +++ b/src/generated/scp_nomination.rs @@ -53,3 +53,44 @@ impl WriteXdr for ScpNomination { }) } } + +/// ScpNominationView is a borrowing equivalent of [`ScpNomination`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScpNominationView<'a> { + pub quorum_set_hash: Hash, + pub votes: VecMView<'a, ValueView<'a>>, + pub accepted: VecMView<'a, ValueView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&ScpNominationView<'_>> for ScpNomination { + #[must_use] + fn from(v: &ScpNominationView<'_>) -> Self { + Self { + quorum_set_hash: v.quorum_set_hash.clone(), + votes: v.votes.to_vecm_from(), + accepted: v.accepted.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpNomination { + #[must_use] + fn from(v: ScpNominationView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScpNominationView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.quorum_set_hash.write_xdr(w)?; + self.votes.write_xdr(w)?; + self.accepted.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/scp_quorum_set.rs b/src/generated/scp_quorum_set.rs index 86bb71c75..6eb861a57 100644 --- a/src/generated/scp_quorum_set.rs +++ b/src/generated/scp_quorum_set.rs @@ -53,3 +53,44 @@ impl WriteXdr for ScpQuorumSet { }) } } + +/// ScpQuorumSetView is a borrowing equivalent of [`ScpQuorumSet`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScpQuorumSetView<'a> { + pub threshold: u32, + pub validators: VecMView<'a, NodeId>, + pub inner_sets: VecMView<'a, ScpQuorumSetView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&ScpQuorumSetView<'_>> for ScpQuorumSet { + #[must_use] + fn from(v: &ScpQuorumSetView<'_>) -> Self { + Self { + threshold: v.threshold, + validators: v.validators.to_vecm(), + inner_sets: v.inner_sets.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpQuorumSet { + #[must_use] + fn from(v: ScpQuorumSetView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScpQuorumSetView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.threshold.write_xdr(w)?; + self.validators.write_xdr(w)?; + self.inner_sets.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/scp_statement.rs b/src/generated/scp_statement.rs index c077adbaf..fe09f7f60 100644 --- a/src/generated/scp_statement.rs +++ b/src/generated/scp_statement.rs @@ -89,3 +89,44 @@ impl WriteXdr for ScpStatement { }) } } + +/// ScpStatementView is a borrowing equivalent of [`ScpStatement`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScpStatementView<'a> { + pub node_id: NodeId, + pub slot_index: u64, + pub pledges: ScpStatementPledgesView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&ScpStatementView<'_>> for ScpStatement { + #[must_use] + fn from(v: &ScpStatementView<'_>) -> Self { + Self { + node_id: v.node_id.clone(), + slot_index: v.slot_index, + pledges: (&v.pledges).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpStatement { + #[must_use] + fn from(v: ScpStatementView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScpStatementView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.node_id.write_xdr(w)?; + self.slot_index.write_xdr(w)?; + self.pledges.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/scp_statement_confirm.rs b/src/generated/scp_statement_confirm.rs index b11690a02..7ac3d75bb 100644 --- a/src/generated/scp_statement_confirm.rs +++ b/src/generated/scp_statement_confirm.rs @@ -61,3 +61,50 @@ impl WriteXdr for ScpStatementConfirm { }) } } + +/// ScpStatementConfirmView is a borrowing equivalent of [`ScpStatementConfirm`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScpStatementConfirmView<'a> { + pub ballot: ScpBallotView<'a>, + pub n_prepared: u32, + pub n_commit: u32, + pub n_h: u32, + pub quorum_set_hash: Hash, +} + +#[cfg(feature = "alloc")] +impl From<&ScpStatementConfirmView<'_>> for ScpStatementConfirm { + #[must_use] + fn from(v: &ScpStatementConfirmView<'_>) -> Self { + Self { + ballot: (&v.ballot).into(), + n_prepared: v.n_prepared, + n_commit: v.n_commit, + n_h: v.n_h, + quorum_set_hash: v.quorum_set_hash.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpStatementConfirm { + #[must_use] + fn from(v: ScpStatementConfirmView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScpStatementConfirmView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ballot.write_xdr(w)?; + self.n_prepared.write_xdr(w)?; + self.n_commit.write_xdr(w)?; + self.n_h.write_xdr(w)?; + self.quorum_set_hash.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/scp_statement_externalize.rs b/src/generated/scp_statement_externalize.rs index 4f5c95056..194d76005 100644 --- a/src/generated/scp_statement_externalize.rs +++ b/src/generated/scp_statement_externalize.rs @@ -53,3 +53,44 @@ impl WriteXdr for ScpStatementExternalize { }) } } + +/// ScpStatementExternalizeView is a borrowing equivalent of [`ScpStatementExternalize`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScpStatementExternalizeView<'a> { + pub commit: ScpBallotView<'a>, + pub n_h: u32, + pub commit_quorum_set_hash: Hash, +} + +#[cfg(feature = "alloc")] +impl From<&ScpStatementExternalizeView<'_>> for ScpStatementExternalize { + #[must_use] + fn from(v: &ScpStatementExternalizeView<'_>) -> Self { + Self { + commit: (&v.commit).into(), + n_h: v.n_h, + commit_quorum_set_hash: v.commit_quorum_set_hash.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpStatementExternalize { + #[must_use] + fn from(v: ScpStatementExternalizeView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScpStatementExternalizeView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.commit.write_xdr(w)?; + self.n_h.write_xdr(w)?; + self.commit_quorum_set_hash.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/scp_statement_pledges.rs b/src/generated/scp_statement_pledges.rs index 628f7f7fe..313a99733 100644 --- a/src/generated/scp_statement_pledges.rs +++ b/src/generated/scp_statement_pledges.rs @@ -176,3 +176,66 @@ impl WriteXdr for ScpStatementPledges { }) } } + +/// ScpStatementPledgesView is a borrowing equivalent of [`ScpStatementPledges`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum ScpStatementPledgesView<'a> { + Prepare(ScpStatementPrepareView<'a>), + Confirm(ScpStatementConfirmView<'a>), + Externalize(ScpStatementExternalizeView<'a>), + Nominate(ScpNominationView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&ScpStatementPledgesView<'_>> for ScpStatementPledges { + #[must_use] + fn from(v: &ScpStatementPledgesView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + ScpStatementPledgesView::Prepare(value) => Self::Prepare(value.into()), + ScpStatementPledgesView::Confirm(value) => Self::Confirm(value.into()), + ScpStatementPledgesView::Externalize(value) => Self::Externalize(value.into()), + ScpStatementPledgesView::Nominate(value) => Self::Nominate(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpStatementPledges { + #[must_use] + fn from(v: ScpStatementPledgesView<'_>) -> Self { + Self::from(&v) + } +} + +impl ScpStatementPledgesView<'_> { + #[must_use] + pub const fn discriminant(&self) -> ScpStatementType { + #[allow(clippy::match_same_arms)] + match self { + Self::Prepare(_) => ScpStatementType::Prepare, + Self::Confirm(_) => ScpStatementType::Confirm, + Self::Externalize(_) => ScpStatementType::Externalize, + Self::Nominate(_) => ScpStatementType::Nominate, + } + } +} + +impl WriteXdr for ScpStatementPledgesView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Prepare(v) => v.write_xdr(w)?, + Self::Confirm(v) => v.write_xdr(w)?, + Self::Externalize(v) => v.write_xdr(w)?, + Self::Nominate(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/scp_statement_prepare.rs b/src/generated/scp_statement_prepare.rs index a6df99b3b..60a3d6876 100644 --- a/src/generated/scp_statement_prepare.rs +++ b/src/generated/scp_statement_prepare.rs @@ -65,3 +65,53 @@ impl WriteXdr for ScpStatementPrepare { }) } } + +/// ScpStatementPrepareView is a borrowing equivalent of [`ScpStatementPrepare`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ScpStatementPrepareView<'a> { + pub quorum_set_hash: Hash, + pub ballot: ScpBallotView<'a>, + pub prepared: Option>, + pub prepared_prime: Option>, + pub n_c: u32, + pub n_h: u32, +} + +#[cfg(feature = "alloc")] +impl From<&ScpStatementPrepareView<'_>> for ScpStatementPrepare { + #[must_use] + fn from(v: &ScpStatementPrepareView<'_>) -> Self { + Self { + quorum_set_hash: v.quorum_set_hash.clone(), + ballot: (&v.ballot).into(), + prepared: v.prepared.as_ref().map(Into::into), + prepared_prime: v.prepared_prime.as_ref().map(Into::into), + n_c: v.n_c, + n_h: v.n_h, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for ScpStatementPrepare { + #[must_use] + fn from(v: ScpStatementPrepareView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ScpStatementPrepareView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.quorum_set_hash.write_xdr(w)?; + self.ballot.write_xdr(w)?; + self.prepared.write_xdr(w)?; + self.prepared_prime.write_xdr(w)?; + self.n_c.write_xdr(w)?; + self.n_h.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/serialized_binary_fuse_filter.rs b/src/generated/serialized_binary_fuse_filter.rs index e594bda22..d427aa1a1 100644 --- a/src/generated/serialized_binary_fuse_filter.rs +++ b/src/generated/serialized_binary_fuse_filter.rs @@ -88,3 +88,62 @@ impl WriteXdr for SerializedBinaryFuseFilter { }) } } + +/// SerializedBinaryFuseFilterView is a borrowing equivalent of [`SerializedBinaryFuseFilter`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SerializedBinaryFuseFilterView<'a> { + pub type_: BinaryFuseFilterType, + pub input_hash_seed: ShortHashSeed, + pub filter_seed: ShortHashSeed, + pub segment_length: u32, + pub segement_length_mask: u32, + pub segment_count: u32, + pub segment_count_length: u32, + pub fingerprint_length: u32, + pub fingerprints: BytesMView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&SerializedBinaryFuseFilterView<'_>> for SerializedBinaryFuseFilter { + #[must_use] + fn from(v: &SerializedBinaryFuseFilterView<'_>) -> Self { + Self { + type_: v.type_, + input_hash_seed: v.input_hash_seed.clone(), + filter_seed: v.filter_seed.clone(), + segment_length: v.segment_length, + segement_length_mask: v.segement_length_mask, + segment_count: v.segment_count, + segment_count_length: v.segment_count_length, + fingerprint_length: v.fingerprint_length, + fingerprints: v.fingerprints.to_bytesm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SerializedBinaryFuseFilter { + #[must_use] + fn from(v: SerializedBinaryFuseFilterView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SerializedBinaryFuseFilterView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.type_.write_xdr(w)?; + self.input_hash_seed.write_xdr(w)?; + self.filter_seed.write_xdr(w)?; + self.segment_length.write_xdr(w)?; + self.segement_length_mask.write_xdr(w)?; + self.segment_count.write_xdr(w)?; + self.segment_count_length.write_xdr(w)?; + self.fingerprint_length.write_xdr(w)?; + self.fingerprints.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/set_options_op.rs b/src/generated/set_options_op.rs index 6402301f0..bfd56579e 100644 --- a/src/generated/set_options_op.rs +++ b/src/generated/set_options_op.rs @@ -84,3 +84,62 @@ impl WriteXdr for SetOptionsOp { }) } } + +/// SetOptionsOpView is a borrowing equivalent of [`SetOptionsOp`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SetOptionsOpView<'a> { + pub inflation_dest: Option, + pub clear_flags: Option, + pub set_flags: Option, + pub master_weight: Option, + pub low_threshold: Option, + pub med_threshold: Option, + pub high_threshold: Option, + pub home_domain: Option>, + pub signer: Option>, +} + +#[cfg(feature = "alloc")] +impl From<&SetOptionsOpView<'_>> for SetOptionsOp { + #[must_use] + fn from(v: &SetOptionsOpView<'_>) -> Self { + Self { + inflation_dest: v.inflation_dest.clone(), + clear_flags: v.clear_flags, + set_flags: v.set_flags, + master_weight: v.master_weight, + low_threshold: v.low_threshold, + med_threshold: v.med_threshold, + high_threshold: v.high_threshold, + home_domain: v.home_domain.as_ref().map(Into::into), + signer: v.signer.as_ref().map(Into::into), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SetOptionsOp { + #[must_use] + fn from(v: SetOptionsOpView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SetOptionsOpView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.inflation_dest.write_xdr(w)?; + self.clear_flags.write_xdr(w)?; + self.set_flags.write_xdr(w)?; + self.master_weight.write_xdr(w)?; + self.low_threshold.write_xdr(w)?; + self.med_threshold.write_xdr(w)?; + self.high_threshold.write_xdr(w)?; + self.home_domain.write_xdr(w)?; + self.signer.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/signature.rs b/src/generated/signature.rs index dafc472e2..24f6ace01 100644 --- a/src/generated/signature.rs +++ b/src/generated/signature.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for Signature { self.0 .0 } } + +/// SignatureView is a borrowing equivalent of [`Signature`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SignatureView<'a>(pub BytesMView<'a, 64>); + +#[cfg(feature = "alloc")] +impl From<&SignatureView<'_>> for Signature { + #[must_use] + fn from(v: &SignatureView<'_>) -> Self { + Self(v.0.to_bytesm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for Signature { + #[must_use] + fn from(v: SignatureView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SignatureView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/signed_time_sliced_survey_request_message.rs b/src/generated/signed_time_sliced_survey_request_message.rs index 28752ef03..ad68a7aec 100644 --- a/src/generated/signed_time_sliced_survey_request_message.rs +++ b/src/generated/signed_time_sliced_survey_request_message.rs @@ -49,3 +49,41 @@ impl WriteXdr for SignedTimeSlicedSurveyRequestMessage { }) } } + +/// SignedTimeSlicedSurveyRequestMessageView is a borrowing equivalent of [`SignedTimeSlicedSurveyRequestMessage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SignedTimeSlicedSurveyRequestMessageView<'a> { + pub request_signature: SignatureView<'a>, + pub request: TimeSlicedSurveyRequestMessage, +} + +#[cfg(feature = "alloc")] +impl From<&SignedTimeSlicedSurveyRequestMessageView<'_>> for SignedTimeSlicedSurveyRequestMessage { + #[must_use] + fn from(v: &SignedTimeSlicedSurveyRequestMessageView<'_>) -> Self { + Self { + request_signature: (&v.request_signature).into(), + request: v.request.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SignedTimeSlicedSurveyRequestMessage { + #[must_use] + fn from(v: SignedTimeSlicedSurveyRequestMessageView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SignedTimeSlicedSurveyRequestMessageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.request_signature.write_xdr(w)?; + self.request.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/signed_time_sliced_survey_response_message.rs b/src/generated/signed_time_sliced_survey_response_message.rs index 426162032..13f7b563e 100644 --- a/src/generated/signed_time_sliced_survey_response_message.rs +++ b/src/generated/signed_time_sliced_survey_response_message.rs @@ -49,3 +49,43 @@ impl WriteXdr for SignedTimeSlicedSurveyResponseMessage { }) } } + +/// SignedTimeSlicedSurveyResponseMessageView is a borrowing equivalent of [`SignedTimeSlicedSurveyResponseMessage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SignedTimeSlicedSurveyResponseMessageView<'a> { + pub response_signature: SignatureView<'a>, + pub response: TimeSlicedSurveyResponseMessageView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&SignedTimeSlicedSurveyResponseMessageView<'_>> + for SignedTimeSlicedSurveyResponseMessage +{ + #[must_use] + fn from(v: &SignedTimeSlicedSurveyResponseMessageView<'_>) -> Self { + Self { + response_signature: (&v.response_signature).into(), + response: (&v.response).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SignedTimeSlicedSurveyResponseMessage { + #[must_use] + fn from(v: SignedTimeSlicedSurveyResponseMessageView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SignedTimeSlicedSurveyResponseMessageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.response_signature.write_xdr(w)?; + self.response.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/signed_time_sliced_survey_start_collecting_message.rs b/src/generated/signed_time_sliced_survey_start_collecting_message.rs index 60ffdb118..c8c725edd 100644 --- a/src/generated/signed_time_sliced_survey_start_collecting_message.rs +++ b/src/generated/signed_time_sliced_survey_start_collecting_message.rs @@ -49,3 +49,45 @@ impl WriteXdr for SignedTimeSlicedSurveyStartCollectingMessage { }) } } + +/// SignedTimeSlicedSurveyStartCollectingMessageView is a borrowing equivalent of [`SignedTimeSlicedSurveyStartCollectingMessage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SignedTimeSlicedSurveyStartCollectingMessageView<'a> { + pub signature: SignatureView<'a>, + pub start_collecting: TimeSlicedSurveyStartCollectingMessage, +} + +#[cfg(feature = "alloc")] +impl From<&SignedTimeSlicedSurveyStartCollectingMessageView<'_>> + for SignedTimeSlicedSurveyStartCollectingMessage +{ + #[must_use] + fn from(v: &SignedTimeSlicedSurveyStartCollectingMessageView<'_>) -> Self { + Self { + signature: (&v.signature).into(), + start_collecting: v.start_collecting.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> + for SignedTimeSlicedSurveyStartCollectingMessage +{ + #[must_use] + fn from(v: SignedTimeSlicedSurveyStartCollectingMessageView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SignedTimeSlicedSurveyStartCollectingMessageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.signature.write_xdr(w)?; + self.start_collecting.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/signed_time_sliced_survey_stop_collecting_message.rs b/src/generated/signed_time_sliced_survey_stop_collecting_message.rs index 3146583d5..7cdd4c7f9 100644 --- a/src/generated/signed_time_sliced_survey_stop_collecting_message.rs +++ b/src/generated/signed_time_sliced_survey_stop_collecting_message.rs @@ -49,3 +49,45 @@ impl WriteXdr for SignedTimeSlicedSurveyStopCollectingMessage { }) } } + +/// SignedTimeSlicedSurveyStopCollectingMessageView is a borrowing equivalent of [`SignedTimeSlicedSurveyStopCollectingMessage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SignedTimeSlicedSurveyStopCollectingMessageView<'a> { + pub signature: SignatureView<'a>, + pub stop_collecting: TimeSlicedSurveyStopCollectingMessage, +} + +#[cfg(feature = "alloc")] +impl From<&SignedTimeSlicedSurveyStopCollectingMessageView<'_>> + for SignedTimeSlicedSurveyStopCollectingMessage +{ + #[must_use] + fn from(v: &SignedTimeSlicedSurveyStopCollectingMessageView<'_>) -> Self { + Self { + signature: (&v.signature).into(), + stop_collecting: v.stop_collecting.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> + for SignedTimeSlicedSurveyStopCollectingMessage +{ + #[must_use] + fn from(v: SignedTimeSlicedSurveyStopCollectingMessageView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SignedTimeSlicedSurveyStopCollectingMessageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.signature.write_xdr(w)?; + self.stop_collecting.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/signer.rs b/src/generated/signer.rs index 27202e0d7..75c49a2f3 100644 --- a/src/generated/signer.rs +++ b/src/generated/signer.rs @@ -49,3 +49,41 @@ impl WriteXdr for Signer { }) } } + +/// SignerView is a borrowing equivalent of [`Signer`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SignerView<'a> { + pub key: SignerKeyView<'a>, + pub weight: u32, +} + +#[cfg(feature = "alloc")] +impl From<&SignerView<'_>> for Signer { + #[must_use] + fn from(v: &SignerView<'_>) -> Self { + Self { + key: (&v.key).into(), + weight: v.weight, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for Signer { + #[must_use] + fn from(v: SignerView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SignerView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.key.write_xdr(w)?; + self.weight.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/signer_key.rs b/src/generated/signer_key.rs index 1321c849c..7a7501dbc 100644 --- a/src/generated/signer_key.rs +++ b/src/generated/signer_key.rs @@ -161,3 +161,66 @@ impl WriteXdr for SignerKey { }) } } + +/// SignerKeyView is a borrowing equivalent of [`SignerKey`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum SignerKeyView<'a> { + Ed25519(Uint256), + PreAuthTx(Uint256), + HashX(Uint256), + Ed25519SignedPayload(SignerKeyEd25519SignedPayloadView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&SignerKeyView<'_>> for SignerKey { + #[must_use] + fn from(v: &SignerKeyView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + SignerKeyView::Ed25519(value) => Self::Ed25519(value.clone()), + SignerKeyView::PreAuthTx(value) => Self::PreAuthTx(value.clone()), + SignerKeyView::HashX(value) => Self::HashX(value.clone()), + SignerKeyView::Ed25519SignedPayload(value) => Self::Ed25519SignedPayload(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SignerKey { + #[must_use] + fn from(v: SignerKeyView<'_>) -> Self { + Self::from(&v) + } +} + +impl SignerKeyView<'_> { + #[must_use] + pub const fn discriminant(&self) -> SignerKeyType { + #[allow(clippy::match_same_arms)] + match self { + Self::Ed25519(_) => SignerKeyType::Ed25519, + Self::PreAuthTx(_) => SignerKeyType::PreAuthTx, + Self::HashX(_) => SignerKeyType::HashX, + Self::Ed25519SignedPayload(_) => SignerKeyType::Ed25519SignedPayload, + } + } +} + +impl WriteXdr for SignerKeyView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Ed25519(v) => v.write_xdr(w)?, + Self::PreAuthTx(v) => v.write_xdr(w)?, + Self::HashX(v) => v.write_xdr(w)?, + Self::Ed25519SignedPayload(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/signer_key_ed25519_signed_payload.rs b/src/generated/signer_key_ed25519_signed_payload.rs index b78b4d261..bbe29de96 100644 --- a/src/generated/signer_key_ed25519_signed_payload.rs +++ b/src/generated/signer_key_ed25519_signed_payload.rs @@ -80,3 +80,41 @@ impl<'de> serde::Deserialize<'de> for SignerKeyEd25519SignedPayload { } } } + +/// SignerKeyEd25519SignedPayloadView is a borrowing equivalent of [`SignerKeyEd25519SignedPayload`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SignerKeyEd25519SignedPayloadView<'a> { + pub ed25519: Uint256, + pub payload: BytesMView<'a, 64>, +} + +#[cfg(feature = "alloc")] +impl From<&SignerKeyEd25519SignedPayloadView<'_>> for SignerKeyEd25519SignedPayload { + #[must_use] + fn from(v: &SignerKeyEd25519SignedPayloadView<'_>) -> Self { + Self { + ed25519: v.ed25519.clone(), + payload: v.payload.to_bytesm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SignerKeyEd25519SignedPayload { + #[must_use] + fn from(v: SignerKeyEd25519SignedPayloadView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SignerKeyEd25519SignedPayloadView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ed25519.write_xdr(w)?; + self.payload.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_address_credentials.rs b/src/generated/soroban_address_credentials.rs index 1f25180ec..b25cebec5 100644 --- a/src/generated/soroban_address_credentials.rs +++ b/src/generated/soroban_address_credentials.rs @@ -61,3 +61,47 @@ impl WriteXdr for SorobanAddressCredentials { }) } } + +/// SorobanAddressCredentialsView is a borrowing equivalent of [`SorobanAddressCredentials`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanAddressCredentialsView<'a> { + pub address: ScAddress, + pub nonce: i64, + pub signature_expiration_ledger: u32, + pub signature: ScValView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanAddressCredentialsView<'_>> for SorobanAddressCredentials { + #[must_use] + fn from(v: &SorobanAddressCredentialsView<'_>) -> Self { + Self { + address: v.address.clone(), + nonce: v.nonce, + signature_expiration_ledger: v.signature_expiration_ledger, + signature: (&v.signature).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanAddressCredentials { + #[must_use] + fn from(v: SorobanAddressCredentialsView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanAddressCredentialsView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.address.write_xdr(w)?; + self.nonce.write_xdr(w)?; + self.signature_expiration_ledger.write_xdr(w)?; + self.signature.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_address_credentials_with_delegates.rs b/src/generated/soroban_address_credentials_with_delegates.rs index 99de5fcc6..bcd394955 100644 --- a/src/generated/soroban_address_credentials_with_delegates.rs +++ b/src/generated/soroban_address_credentials_with_delegates.rs @@ -49,3 +49,45 @@ impl WriteXdr for SorobanAddressCredentialsWithDelegates { }) } } + +/// SorobanAddressCredentialsWithDelegatesView is a borrowing equivalent of [`SorobanAddressCredentialsWithDelegates`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanAddressCredentialsWithDelegatesView<'a> { + pub address_credentials: SorobanAddressCredentialsView<'a>, + pub delegates: VecMView<'a, SorobanDelegateSignatureView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanAddressCredentialsWithDelegatesView<'_>> + for SorobanAddressCredentialsWithDelegates +{ + #[must_use] + fn from(v: &SorobanAddressCredentialsWithDelegatesView<'_>) -> Self { + Self { + address_credentials: (&v.address_credentials).into(), + delegates: v.delegates.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> + for SorobanAddressCredentialsWithDelegates +{ + #[must_use] + fn from(v: SorobanAddressCredentialsWithDelegatesView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanAddressCredentialsWithDelegatesView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.address_credentials.write_xdr(w)?; + self.delegates.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_authorization_entries.rs b/src/generated/soroban_authorization_entries.rs index b6faba05e..8f17ef7aa 100644 --- a/src/generated/soroban_authorization_entries.rs +++ b/src/generated/soroban_authorization_entries.rs @@ -107,3 +107,31 @@ impl AsRef<[SorobanAuthorizationEntry]> for SorobanAuthorizationEntries { self.0 .0 } } + +/// SorobanAuthorizationEntriesView is a borrowing equivalent of [`SorobanAuthorizationEntries`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanAuthorizationEntriesView<'a>(pub VecMView<'a, SorobanAuthorizationEntryView<'a>>); + +#[cfg(feature = "alloc")] +impl From<&SorobanAuthorizationEntriesView<'_>> for SorobanAuthorizationEntries { + #[must_use] + fn from(v: &SorobanAuthorizationEntriesView<'_>) -> Self { + Self(v.0.to_vecm_from()) + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanAuthorizationEntries { + #[must_use] + fn from(v: SorobanAuthorizationEntriesView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanAuthorizationEntriesView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/soroban_authorization_entry.rs b/src/generated/soroban_authorization_entry.rs index c41587a36..662f658ee 100644 --- a/src/generated/soroban_authorization_entry.rs +++ b/src/generated/soroban_authorization_entry.rs @@ -49,3 +49,41 @@ impl WriteXdr for SorobanAuthorizationEntry { }) } } + +/// SorobanAuthorizationEntryView is a borrowing equivalent of [`SorobanAuthorizationEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanAuthorizationEntryView<'a> { + pub credentials: SorobanCredentialsView<'a>, + pub root_invocation: SorobanAuthorizedInvocationView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanAuthorizationEntryView<'_>> for SorobanAuthorizationEntry { + #[must_use] + fn from(v: &SorobanAuthorizationEntryView<'_>) -> Self { + Self { + credentials: (&v.credentials).into(), + root_invocation: (&v.root_invocation).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanAuthorizationEntry { + #[must_use] + fn from(v: SorobanAuthorizationEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanAuthorizationEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.credentials.write_xdr(w)?; + self.root_invocation.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_authorized_function.rs b/src/generated/soroban_authorized_function.rs index e17e48e2d..071c58920 100644 --- a/src/generated/soroban_authorized_function.rs +++ b/src/generated/soroban_authorized_function.rs @@ -167,3 +167,68 @@ impl WriteXdr for SorobanAuthorizedFunction { }) } } + +/// SorobanAuthorizedFunctionView is a borrowing equivalent of [`SorobanAuthorizedFunction`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum SorobanAuthorizedFunctionView<'a> { + ContractFn(InvokeContractArgsView<'a>), + CreateContractHostFn(CreateContractArgsView<'a>), + CreateContractV2HostFn(CreateContractArgsV2View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&SorobanAuthorizedFunctionView<'_>> for SorobanAuthorizedFunction { + #[must_use] + fn from(v: &SorobanAuthorizedFunctionView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + SorobanAuthorizedFunctionView::ContractFn(value) => Self::ContractFn(value.into()), + SorobanAuthorizedFunctionView::CreateContractHostFn(value) => { + Self::CreateContractHostFn(value.into()) + } + SorobanAuthorizedFunctionView::CreateContractV2HostFn(value) => { + Self::CreateContractV2HostFn(value.into()) + } + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanAuthorizedFunction { + #[must_use] + fn from(v: SorobanAuthorizedFunctionView<'_>) -> Self { + Self::from(&v) + } +} + +impl SorobanAuthorizedFunctionView<'_> { + #[must_use] + pub const fn discriminant(&self) -> SorobanAuthorizedFunctionType { + #[allow(clippy::match_same_arms)] + match self { + Self::ContractFn(_) => SorobanAuthorizedFunctionType::ContractFn, + Self::CreateContractHostFn(_) => SorobanAuthorizedFunctionType::CreateContractHostFn, + Self::CreateContractV2HostFn(_) => { + SorobanAuthorizedFunctionType::CreateContractV2HostFn + } + } + } +} + +impl WriteXdr for SorobanAuthorizedFunctionView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::ContractFn(v) => v.write_xdr(w)?, + Self::CreateContractHostFn(v) => v.write_xdr(w)?, + Self::CreateContractV2HostFn(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_authorized_invocation.rs b/src/generated/soroban_authorized_invocation.rs index 0a4d12d9d..031218f59 100644 --- a/src/generated/soroban_authorized_invocation.rs +++ b/src/generated/soroban_authorized_invocation.rs @@ -49,3 +49,41 @@ impl WriteXdr for SorobanAuthorizedInvocation { }) } } + +/// SorobanAuthorizedInvocationView is a borrowing equivalent of [`SorobanAuthorizedInvocation`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanAuthorizedInvocationView<'a> { + pub function: SorobanAuthorizedFunctionView<'a>, + pub sub_invocations: VecMView<'a, SorobanAuthorizedInvocationView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanAuthorizedInvocationView<'_>> for SorobanAuthorizedInvocation { + #[must_use] + fn from(v: &SorobanAuthorizedInvocationView<'_>) -> Self { + Self { + function: (&v.function).into(), + sub_invocations: v.sub_invocations.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanAuthorizedInvocation { + #[must_use] + fn from(v: SorobanAuthorizedInvocationView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanAuthorizedInvocationView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.function.write_xdr(w)?; + self.sub_invocations.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_credentials.rs b/src/generated/soroban_credentials.rs index 8f038c8db..2f1815290 100644 --- a/src/generated/soroban_credentials.rs +++ b/src/generated/soroban_credentials.rs @@ -165,3 +165,68 @@ impl WriteXdr for SorobanCredentials { }) } } + +/// SorobanCredentialsView is a borrowing equivalent of [`SorobanCredentials`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum SorobanCredentialsView<'a> { + SourceAccount, + Address(SorobanAddressCredentialsView<'a>), + AddressV2(SorobanAddressCredentialsView<'a>), + AddressWithDelegates(SorobanAddressCredentialsWithDelegatesView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&SorobanCredentialsView<'_>> for SorobanCredentials { + #[must_use] + fn from(v: &SorobanCredentialsView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + SorobanCredentialsView::SourceAccount => Self::SourceAccount, + SorobanCredentialsView::Address(value) => Self::Address(value.into()), + SorobanCredentialsView::AddressV2(value) => Self::AddressV2(value.into()), + SorobanCredentialsView::AddressWithDelegates(value) => { + Self::AddressWithDelegates(value.into()) + } + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanCredentials { + #[must_use] + fn from(v: SorobanCredentialsView<'_>) -> Self { + Self::from(&v) + } +} + +impl SorobanCredentialsView<'_> { + #[must_use] + pub const fn discriminant(&self) -> SorobanCredentialsType { + #[allow(clippy::match_same_arms)] + match self { + Self::SourceAccount => SorobanCredentialsType::SourceAccount, + Self::Address(_) => SorobanCredentialsType::Address, + Self::AddressV2(_) => SorobanCredentialsType::AddressV2, + Self::AddressWithDelegates(_) => SorobanCredentialsType::AddressWithDelegates, + } + } +} + +impl WriteXdr for SorobanCredentialsView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::SourceAccount => ().write_xdr(w)?, + Self::Address(v) => v.write_xdr(w)?, + Self::AddressV2(v) => v.write_xdr(w)?, + Self::AddressWithDelegates(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_delegate_signature.rs b/src/generated/soroban_delegate_signature.rs index 35bf77f7e..fab8af12c 100644 --- a/src/generated/soroban_delegate_signature.rs +++ b/src/generated/soroban_delegate_signature.rs @@ -53,3 +53,44 @@ impl WriteXdr for SorobanDelegateSignature { }) } } + +/// SorobanDelegateSignatureView is a borrowing equivalent of [`SorobanDelegateSignature`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanDelegateSignatureView<'a> { + pub address: ScAddress, + pub signature: ScValView<'a>, + pub nested_delegates: VecMView<'a, SorobanDelegateSignatureView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanDelegateSignatureView<'_>> for SorobanDelegateSignature { + #[must_use] + fn from(v: &SorobanDelegateSignatureView<'_>) -> Self { + Self { + address: v.address.clone(), + signature: (&v.signature).into(), + nested_delegates: v.nested_delegates.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanDelegateSignature { + #[must_use] + fn from(v: SorobanDelegateSignatureView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanDelegateSignatureView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.address.write_xdr(w)?; + self.signature.write_xdr(w)?; + self.nested_delegates.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_resources.rs b/src/generated/soroban_resources.rs index 6a91acad6..868f1cd79 100644 --- a/src/generated/soroban_resources.rs +++ b/src/generated/soroban_resources.rs @@ -62,3 +62,47 @@ impl WriteXdr for SorobanResources { }) } } + +/// SorobanResourcesView is a borrowing equivalent of [`SorobanResources`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanResourcesView<'a> { + pub footprint: LedgerFootprintView<'a>, + pub instructions: u32, + pub disk_read_bytes: u32, + pub write_bytes: u32, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanResourcesView<'_>> for SorobanResources { + #[must_use] + fn from(v: &SorobanResourcesView<'_>) -> Self { + Self { + footprint: (&v.footprint).into(), + instructions: v.instructions, + disk_read_bytes: v.disk_read_bytes, + write_bytes: v.write_bytes, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanResources { + #[must_use] + fn from(v: SorobanResourcesView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanResourcesView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.footprint.write_xdr(w)?; + self.instructions.write_xdr(w)?; + self.disk_read_bytes.write_xdr(w)?; + self.write_bytes.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_resources_ext_v0.rs b/src/generated/soroban_resources_ext_v0.rs index 4e06acf41..258859255 100644 --- a/src/generated/soroban_resources_ext_v0.rs +++ b/src/generated/soroban_resources_ext_v0.rs @@ -48,3 +48,38 @@ impl WriteXdr for SorobanResourcesExtV0 { }) } } + +/// SorobanResourcesExtV0View is a borrowing equivalent of [`SorobanResourcesExtV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanResourcesExtV0View<'a> { + pub archived_soroban_entries: VecMView<'a, u32>, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanResourcesExtV0View<'_>> for SorobanResourcesExtV0 { + #[must_use] + fn from(v: &SorobanResourcesExtV0View<'_>) -> Self { + Self { + archived_soroban_entries: v.archived_soroban_entries.to_vecm(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanResourcesExtV0 { + #[must_use] + fn from(v: SorobanResourcesExtV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanResourcesExtV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.archived_soroban_entries.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_transaction_data.rs b/src/generated/soroban_transaction_data.rs index e7a9f727f..c51f5d2c5 100644 --- a/src/generated/soroban_transaction_data.rs +++ b/src/generated/soroban_transaction_data.rs @@ -72,3 +72,44 @@ impl WriteXdr for SorobanTransactionData { }) } } + +/// SorobanTransactionDataView is a borrowing equivalent of [`SorobanTransactionData`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanTransactionDataView<'a> { + pub ext: SorobanTransactionDataExtView<'a>, + pub resources: SorobanResourcesView<'a>, + pub resource_fee: i64, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanTransactionDataView<'_>> for SorobanTransactionData { + #[must_use] + fn from(v: &SorobanTransactionDataView<'_>) -> Self { + Self { + ext: (&v.ext).into(), + resources: (&v.resources).into(), + resource_fee: v.resource_fee, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanTransactionData { + #[must_use] + fn from(v: SorobanTransactionDataView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanTransactionDataView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.resources.write_xdr(w)?; + self.resource_fee.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_transaction_data_ext.rs b/src/generated/soroban_transaction_data_ext.rs index db49ca978..6e88ea49d 100644 --- a/src/generated/soroban_transaction_data_ext.rs +++ b/src/generated/soroban_transaction_data_ext.rs @@ -135,3 +135,58 @@ impl WriteXdr for SorobanTransactionDataExt { }) } } + +/// SorobanTransactionDataExtView is a borrowing equivalent of [`SorobanTransactionDataExt`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum SorobanTransactionDataExtView<'a> { + V0, + V1(SorobanResourcesExtV0View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&SorobanTransactionDataExtView<'_>> for SorobanTransactionDataExt { + #[must_use] + fn from(v: &SorobanTransactionDataExtView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + SorobanTransactionDataExtView::V0 => Self::V0, + SorobanTransactionDataExtView::V1(value) => Self::V1(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanTransactionDataExt { + #[must_use] + fn from(v: SorobanTransactionDataExtView<'_>) -> Self { + Self::from(&v) + } +} + +impl SorobanTransactionDataExtView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V1(_) => 1, + } + } +} + +impl WriteXdr for SorobanTransactionDataExtView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => ().write_xdr(w)?, + Self::V1(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_transaction_meta.rs b/src/generated/soroban_transaction_meta.rs index c1cae1ed8..9d8fbd2e9 100644 --- a/src/generated/soroban_transaction_meta.rs +++ b/src/generated/soroban_transaction_meta.rs @@ -63,3 +63,47 @@ impl WriteXdr for SorobanTransactionMeta { }) } } + +/// SorobanTransactionMetaView is a borrowing equivalent of [`SorobanTransactionMeta`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanTransactionMetaView<'a> { + pub ext: SorobanTransactionMetaExt, + pub events: VecMView<'a, ContractEventView<'a>>, + pub return_value: ScValView<'a>, + pub diagnostic_events: VecMView<'a, DiagnosticEventView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanTransactionMetaView<'_>> for SorobanTransactionMeta { + #[must_use] + fn from(v: &SorobanTransactionMetaView<'_>) -> Self { + Self { + ext: v.ext.clone(), + events: v.events.to_vecm_from(), + return_value: (&v.return_value).into(), + diagnostic_events: v.diagnostic_events.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanTransactionMeta { + #[must_use] + fn from(v: SorobanTransactionMetaView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanTransactionMetaView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.events.write_xdr(w)?; + self.return_value.write_xdr(w)?; + self.diagnostic_events.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/soroban_transaction_meta_v2.rs b/src/generated/soroban_transaction_meta_v2.rs index 3addfc79b..8a0db279b 100644 --- a/src/generated/soroban_transaction_meta_v2.rs +++ b/src/generated/soroban_transaction_meta_v2.rs @@ -50,3 +50,41 @@ impl WriteXdr for SorobanTransactionMetaV2 { }) } } + +/// SorobanTransactionMetaV2View is a borrowing equivalent of [`SorobanTransactionMetaV2`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SorobanTransactionMetaV2View<'a> { + pub ext: SorobanTransactionMetaExt, + pub return_value: Option>, +} + +#[cfg(feature = "alloc")] +impl From<&SorobanTransactionMetaV2View<'_>> for SorobanTransactionMetaV2 { + #[must_use] + fn from(v: &SorobanTransactionMetaV2View<'_>) -> Self { + Self { + ext: v.ext.clone(), + return_value: v.return_value.as_ref().map(Into::into), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SorobanTransactionMetaV2 { + #[must_use] + fn from(v: SorobanTransactionMetaV2View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SorobanTransactionMetaV2View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.return_value.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/stellar_message.rs b/src/generated/stellar_message.rs index 1e7ed6b9d..d11d8061f 100644 --- a/src/generated/stellar_message.rs +++ b/src/generated/stellar_message.rs @@ -341,3 +341,144 @@ impl WriteXdr for StellarMessage { }) } } + +/// StellarMessageView is a borrowing equivalent of [`StellarMessage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum StellarMessageView<'a> { + ErrorMsg(SErrorView<'a>), + Hello(HelloView<'a>), + Auth(Auth), + DontHave(DontHave), + Peers(VecMView<'a, PeerAddress, 100>), + GetTxSet(Uint256), + TxSet(TransactionSetView<'a>), + GeneralizedTxSet(GeneralizedTransactionSetView<'a>), + Transaction(TransactionEnvelopeView<'a>), + TimeSlicedSurveyRequest(SignedTimeSlicedSurveyRequestMessageView<'a>), + TimeSlicedSurveyResponse(SignedTimeSlicedSurveyResponseMessageView<'a>), + TimeSlicedSurveyStartCollecting(SignedTimeSlicedSurveyStartCollectingMessageView<'a>), + TimeSlicedSurveyStopCollecting(SignedTimeSlicedSurveyStopCollectingMessageView<'a>), + GetScpQuorumset(Uint256), + ScpQuorumset(ScpQuorumSetView<'a>), + ScpMessage(ScpEnvelopeView<'a>), + GetScpState(u32), + SendMore(SendMore), + SendMoreExtended(SendMoreExtended), + FloodAdvert(FloodAdvertView<'a>), + FloodDemand(FloodDemandView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&StellarMessageView<'_>> for StellarMessage { + #[must_use] + fn from(v: &StellarMessageView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + StellarMessageView::ErrorMsg(value) => Self::ErrorMsg(value.into()), + StellarMessageView::Hello(value) => Self::Hello(value.into()), + StellarMessageView::Auth(value) => Self::Auth(value.clone()), + StellarMessageView::DontHave(value) => Self::DontHave(value.clone()), + StellarMessageView::Peers(value) => Self::Peers(value.to_vecm()), + StellarMessageView::GetTxSet(value) => Self::GetTxSet(value.clone()), + StellarMessageView::TxSet(value) => Self::TxSet(value.into()), + StellarMessageView::GeneralizedTxSet(value) => Self::GeneralizedTxSet(value.into()), + StellarMessageView::Transaction(value) => Self::Transaction(value.into()), + StellarMessageView::TimeSlicedSurveyRequest(value) => { + Self::TimeSlicedSurveyRequest(value.into()) + } + StellarMessageView::TimeSlicedSurveyResponse(value) => { + Self::TimeSlicedSurveyResponse(value.into()) + } + StellarMessageView::TimeSlicedSurveyStartCollecting(value) => { + Self::TimeSlicedSurveyStartCollecting(value.into()) + } + StellarMessageView::TimeSlicedSurveyStopCollecting(value) => { + Self::TimeSlicedSurveyStopCollecting(value.into()) + } + StellarMessageView::GetScpQuorumset(value) => Self::GetScpQuorumset(value.clone()), + StellarMessageView::ScpQuorumset(value) => Self::ScpQuorumset(value.into()), + StellarMessageView::ScpMessage(value) => Self::ScpMessage(value.into()), + StellarMessageView::GetScpState(value) => Self::GetScpState(*value), + StellarMessageView::SendMore(value) => Self::SendMore(value.clone()), + StellarMessageView::SendMoreExtended(value) => Self::SendMoreExtended(value.clone()), + StellarMessageView::FloodAdvert(value) => Self::FloodAdvert(value.into()), + StellarMessageView::FloodDemand(value) => Self::FloodDemand(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for StellarMessage { + #[must_use] + fn from(v: StellarMessageView<'_>) -> Self { + Self::from(&v) + } +} + +impl StellarMessageView<'_> { + #[must_use] + pub const fn discriminant(&self) -> MessageType { + #[allow(clippy::match_same_arms)] + match self { + Self::ErrorMsg(_) => MessageType::ErrorMsg, + Self::Hello(_) => MessageType::Hello, + Self::Auth(_) => MessageType::Auth, + Self::DontHave(_) => MessageType::DontHave, + Self::Peers(_) => MessageType::Peers, + Self::GetTxSet(_) => MessageType::GetTxSet, + Self::TxSet(_) => MessageType::TxSet, + Self::GeneralizedTxSet(_) => MessageType::GeneralizedTxSet, + Self::Transaction(_) => MessageType::Transaction, + Self::TimeSlicedSurveyRequest(_) => MessageType::TimeSlicedSurveyRequest, + Self::TimeSlicedSurveyResponse(_) => MessageType::TimeSlicedSurveyResponse, + Self::TimeSlicedSurveyStartCollecting(_) => { + MessageType::TimeSlicedSurveyStartCollecting + } + Self::TimeSlicedSurveyStopCollecting(_) => MessageType::TimeSlicedSurveyStopCollecting, + Self::GetScpQuorumset(_) => MessageType::GetScpQuorumset, + Self::ScpQuorumset(_) => MessageType::ScpQuorumset, + Self::ScpMessage(_) => MessageType::ScpMessage, + Self::GetScpState(_) => MessageType::GetScpState, + Self::SendMore(_) => MessageType::SendMore, + Self::SendMoreExtended(_) => MessageType::SendMoreExtended, + Self::FloodAdvert(_) => MessageType::FloodAdvert, + Self::FloodDemand(_) => MessageType::FloodDemand, + } + } +} + +impl WriteXdr for StellarMessageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::ErrorMsg(v) => v.write_xdr(w)?, + Self::Hello(v) => v.write_xdr(w)?, + Self::Auth(v) => v.write_xdr(w)?, + Self::DontHave(v) => v.write_xdr(w)?, + Self::Peers(v) => v.write_xdr(w)?, + Self::GetTxSet(v) => v.write_xdr(w)?, + Self::TxSet(v) => v.write_xdr(w)?, + Self::GeneralizedTxSet(v) => v.write_xdr(w)?, + Self::Transaction(v) => v.write_xdr(w)?, + Self::TimeSlicedSurveyRequest(v) => v.write_xdr(w)?, + Self::TimeSlicedSurveyResponse(v) => v.write_xdr(w)?, + Self::TimeSlicedSurveyStartCollecting(v) => v.write_xdr(w)?, + Self::TimeSlicedSurveyStopCollecting(v) => v.write_xdr(w)?, + Self::GetScpQuorumset(v) => v.write_xdr(w)?, + Self::ScpQuorumset(v) => v.write_xdr(w)?, + Self::ScpMessage(v) => v.write_xdr(w)?, + Self::GetScpState(v) => v.write_xdr(w)?, + Self::SendMore(v) => v.write_xdr(w)?, + Self::SendMoreExtended(v) => v.write_xdr(w)?, + Self::FloodAdvert(v) => v.write_xdr(w)?, + Self::FloodDemand(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/stellar_value.rs b/src/generated/stellar_value.rs index 0c840d872..3d1f012a0 100644 --- a/src/generated/stellar_value.rs +++ b/src/generated/stellar_value.rs @@ -80,3 +80,47 @@ impl WriteXdr for StellarValue { }) } } + +/// StellarValueView is a borrowing equivalent of [`StellarValue`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct StellarValueView<'a> { + pub tx_set_hash: Hash, + pub close_time: TimePoint, + pub upgrades: VecMView<'a, UpgradeTypeView<'a>, 6>, + pub ext: StellarValueExtView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&StellarValueView<'_>> for StellarValue { + #[must_use] + fn from(v: &StellarValueView<'_>) -> Self { + Self { + tx_set_hash: v.tx_set_hash.clone(), + close_time: v.close_time.clone(), + upgrades: v.upgrades.to_vecm_from(), + ext: (&v.ext).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for StellarValue { + #[must_use] + fn from(v: StellarValueView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for StellarValueView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx_set_hash.write_xdr(w)?; + self.close_time.write_xdr(w)?; + self.upgrades.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/stellar_value_ext.rs b/src/generated/stellar_value_ext.rs index 0b4059e9a..0304b5d17 100644 --- a/src/generated/stellar_value_ext.rs +++ b/src/generated/stellar_value_ext.rs @@ -154,3 +154,62 @@ impl WriteXdr for StellarValueExt { }) } } + +/// StellarValueExtView is a borrowing equivalent of [`StellarValueExt`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum StellarValueExtView<'a> { + Basic, + Signed(LedgerCloseValueSignatureView<'a>), + EmptyTxSet(StellarValueProposedValueView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&StellarValueExtView<'_>> for StellarValueExt { + #[must_use] + fn from(v: &StellarValueExtView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + StellarValueExtView::Basic => Self::Basic, + StellarValueExtView::Signed(value) => Self::Signed(value.into()), + StellarValueExtView::EmptyTxSet(value) => Self::EmptyTxSet(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for StellarValueExt { + #[must_use] + fn from(v: StellarValueExtView<'_>) -> Self { + Self::from(&v) + } +} + +impl StellarValueExtView<'_> { + #[must_use] + pub const fn discriminant(&self) -> StellarValueType { + #[allow(clippy::match_same_arms)] + match self { + Self::Basic => StellarValueType::Basic, + Self::Signed(_) => StellarValueType::Signed, + Self::EmptyTxSet(_) => StellarValueType::EmptyTxSet, + } + } +} + +impl WriteXdr for StellarValueExtView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Basic => ().write_xdr(w)?, + Self::Signed(v) => v.write_xdr(w)?, + Self::EmptyTxSet(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/stellar_value_proposed_value.rs b/src/generated/stellar_value_proposed_value.rs index d53781eed..18fc1f14e 100644 --- a/src/generated/stellar_value_proposed_value.rs +++ b/src/generated/stellar_value_proposed_value.rs @@ -57,3 +57,47 @@ impl WriteXdr for StellarValueProposedValue { }) } } + +/// StellarValueProposedValueView is a borrowing equivalent of [`StellarValueProposedValue`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct StellarValueProposedValueView<'a> { + pub tx_set_hash: Hash, + pub previous_ledger_hash: Hash, + pub previous_ledger_version: u32, + pub lc_value_signature: LedgerCloseValueSignatureView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&StellarValueProposedValueView<'_>> for StellarValueProposedValue { + #[must_use] + fn from(v: &StellarValueProposedValueView<'_>) -> Self { + Self { + tx_set_hash: v.tx_set_hash.clone(), + previous_ledger_hash: v.previous_ledger_hash.clone(), + previous_ledger_version: v.previous_ledger_version, + lc_value_signature: (&v.lc_value_signature).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for StellarValueProposedValue { + #[must_use] + fn from(v: StellarValueProposedValueView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for StellarValueProposedValueView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx_set_hash.write_xdr(w)?; + self.previous_ledger_hash.write_xdr(w)?; + self.previous_ledger_version.write_xdr(w)?; + self.lc_value_signature.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/stored_debug_transaction_set.rs b/src/generated/stored_debug_transaction_set.rs index ce63e89c2..2853473bb 100644 --- a/src/generated/stored_debug_transaction_set.rs +++ b/src/generated/stored_debug_transaction_set.rs @@ -53,3 +53,44 @@ impl WriteXdr for StoredDebugTransactionSet { }) } } + +/// StoredDebugTransactionSetView is a borrowing equivalent of [`StoredDebugTransactionSet`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct StoredDebugTransactionSetView<'a> { + pub tx_set: StoredTransactionSetView<'a>, + pub ledger_seq: u32, + pub scp_value: StellarValueView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&StoredDebugTransactionSetView<'_>> for StoredDebugTransactionSet { + #[must_use] + fn from(v: &StoredDebugTransactionSetView<'_>) -> Self { + Self { + tx_set: (&v.tx_set).into(), + ledger_seq: v.ledger_seq, + scp_value: (&v.scp_value).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for StoredDebugTransactionSet { + #[must_use] + fn from(v: StoredDebugTransactionSetView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for StoredDebugTransactionSetView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx_set.write_xdr(w)?; + self.ledger_seq.write_xdr(w)?; + self.scp_value.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/stored_transaction_set.rs b/src/generated/stored_transaction_set.rs index 95285ef58..d7a8d6e13 100644 --- a/src/generated/stored_transaction_set.rs +++ b/src/generated/stored_transaction_set.rs @@ -135,3 +135,58 @@ impl WriteXdr for StoredTransactionSet { }) } } + +/// StoredTransactionSetView is a borrowing equivalent of [`StoredTransactionSet`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum StoredTransactionSetView<'a> { + V0(TransactionSetView<'a>), + V1(GeneralizedTransactionSetView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&StoredTransactionSetView<'_>> for StoredTransactionSet { + #[must_use] + fn from(v: &StoredTransactionSetView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + StoredTransactionSetView::V0(value) => Self::V0(value.into()), + StoredTransactionSetView::V1(value) => Self::V1(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for StoredTransactionSet { + #[must_use] + fn from(v: StoredTransactionSetView<'_>) -> Self { + Self::from(&v) + } +} + +impl StoredTransactionSetView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + } + } +} + +impl WriteXdr for StoredTransactionSetView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0(v) => v.write_xdr(w)?, + Self::V1(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/string32.rs b/src/generated/string32.rs index 7df1ac97c..d65c541e3 100644 --- a/src/generated/string32.rs +++ b/src/generated/string32.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for String32 { self.0 .0 } } + +/// String32View is a borrowing equivalent of [`String32`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct String32View<'a>(pub StringMView<'a, 32>); + +#[cfg(feature = "alloc")] +impl From<&String32View<'_>> for String32 { + #[must_use] + fn from(v: &String32View<'_>) -> Self { + Self(v.0.to_stringm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for String32 { + #[must_use] + fn from(v: String32View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for String32View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/string64.rs b/src/generated/string64.rs index 46fbc3e49..af4b19f0d 100644 --- a/src/generated/string64.rs +++ b/src/generated/string64.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for String64 { self.0 .0 } } + +/// String64View is a borrowing equivalent of [`String64`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct String64View<'a>(pub StringMView<'a, 64>); + +#[cfg(feature = "alloc")] +impl From<&String64View<'_>> for String64 { + #[must_use] + fn from(v: &String64View<'_>) -> Self { + Self(v.0.to_stringm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for String64 { + #[must_use] + fn from(v: String64View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for String64View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/survey_response_body.rs b/src/generated/survey_response_body.rs index 830fcb5a0..025e4fa71 100644 --- a/src/generated/survey_response_body.rs +++ b/src/generated/survey_response_body.rs @@ -134,3 +134,58 @@ impl WriteXdr for SurveyResponseBody { }) } } + +/// SurveyResponseBodyView is a borrowing equivalent of [`SurveyResponseBody`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum SurveyResponseBodyView<'a> { + SurveyTopologyResponseV2(TopologyResponseBodyV2View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&SurveyResponseBodyView<'_>> for SurveyResponseBody { + #[must_use] + fn from(v: &SurveyResponseBodyView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + SurveyResponseBodyView::SurveyTopologyResponseV2(value) => { + Self::SurveyTopologyResponseV2(value.into()) + } + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SurveyResponseBody { + #[must_use] + fn from(v: SurveyResponseBodyView<'_>) -> Self { + Self::from(&v) + } +} + +impl SurveyResponseBodyView<'_> { + #[must_use] + pub const fn discriminant(&self) -> SurveyMessageResponseType { + #[allow(clippy::match_same_arms)] + match self { + Self::SurveyTopologyResponseV2(_) => { + SurveyMessageResponseType::SurveyTopologyResponseV2 + } + } + } +} + +impl WriteXdr for SurveyResponseBodyView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::SurveyTopologyResponseV2(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/survey_response_message.rs b/src/generated/survey_response_message.rs index c724acec7..413e80521 100644 --- a/src/generated/survey_response_message.rs +++ b/src/generated/survey_response_message.rs @@ -61,3 +61,50 @@ impl WriteXdr for SurveyResponseMessage { }) } } + +/// SurveyResponseMessageView is a borrowing equivalent of [`SurveyResponseMessage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct SurveyResponseMessageView<'a> { + pub surveyor_peer_id: NodeId, + pub surveyed_peer_id: NodeId, + pub ledger_num: u32, + pub command_type: SurveyMessageCommandType, + pub encrypted_body: EncryptedBodyView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&SurveyResponseMessageView<'_>> for SurveyResponseMessage { + #[must_use] + fn from(v: &SurveyResponseMessageView<'_>) -> Self { + Self { + surveyor_peer_id: v.surveyor_peer_id.clone(), + surveyed_peer_id: v.surveyed_peer_id.clone(), + ledger_num: v.ledger_num, + command_type: v.command_type, + encrypted_body: (&v.encrypted_body).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for SurveyResponseMessage { + #[must_use] + fn from(v: SurveyResponseMessageView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for SurveyResponseMessageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.surveyor_peer_id.write_xdr(w)?; + self.surveyed_peer_id.write_xdr(w)?; + self.ledger_num.write_xdr(w)?; + self.command_type.write_xdr(w)?; + self.encrypted_body.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/time_sliced_peer_data.rs b/src/generated/time_sliced_peer_data.rs index 49915ecc4..090714b32 100644 --- a/src/generated/time_sliced_peer_data.rs +++ b/src/generated/time_sliced_peer_data.rs @@ -49,3 +49,41 @@ impl WriteXdr for TimeSlicedPeerData { }) } } + +/// TimeSlicedPeerDataView is a borrowing equivalent of [`TimeSlicedPeerData`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TimeSlicedPeerDataView<'a> { + pub peer_stats: PeerStatsView<'a>, + pub average_latency_ms: u32, +} + +#[cfg(feature = "alloc")] +impl From<&TimeSlicedPeerDataView<'_>> for TimeSlicedPeerData { + #[must_use] + fn from(v: &TimeSlicedPeerDataView<'_>) -> Self { + Self { + peer_stats: (&v.peer_stats).into(), + average_latency_ms: v.average_latency_ms, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TimeSlicedPeerData { + #[must_use] + fn from(v: TimeSlicedPeerDataView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TimeSlicedPeerDataView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.peer_stats.write_xdr(w)?; + self.average_latency_ms.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/time_sliced_peer_data_list.rs b/src/generated/time_sliced_peer_data_list.rs index 44bef0cce..3d9018dcb 100644 --- a/src/generated/time_sliced_peer_data_list.rs +++ b/src/generated/time_sliced_peer_data_list.rs @@ -107,3 +107,31 @@ impl AsRef<[TimeSlicedPeerData]> for TimeSlicedPeerDataList { self.0 .0 } } + +/// TimeSlicedPeerDataListView is a borrowing equivalent of [`TimeSlicedPeerDataList`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TimeSlicedPeerDataListView<'a>(pub VecMView<'a, TimeSlicedPeerDataView<'a>, 25>); + +#[cfg(feature = "alloc")] +impl From<&TimeSlicedPeerDataListView<'_>> for TimeSlicedPeerDataList { + #[must_use] + fn from(v: &TimeSlicedPeerDataListView<'_>) -> Self { + Self(v.0.to_vecm_from()) + } +} + +#[cfg(feature = "alloc")] +impl From> for TimeSlicedPeerDataList { + #[must_use] + fn from(v: TimeSlicedPeerDataListView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TimeSlicedPeerDataListView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/time_sliced_survey_response_message.rs b/src/generated/time_sliced_survey_response_message.rs index 0a66592d6..29b7a1bcd 100644 --- a/src/generated/time_sliced_survey_response_message.rs +++ b/src/generated/time_sliced_survey_response_message.rs @@ -49,3 +49,41 @@ impl WriteXdr for TimeSlicedSurveyResponseMessage { }) } } + +/// TimeSlicedSurveyResponseMessageView is a borrowing equivalent of [`TimeSlicedSurveyResponseMessage`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TimeSlicedSurveyResponseMessageView<'a> { + pub response: SurveyResponseMessageView<'a>, + pub nonce: u32, +} + +#[cfg(feature = "alloc")] +impl From<&TimeSlicedSurveyResponseMessageView<'_>> for TimeSlicedSurveyResponseMessage { + #[must_use] + fn from(v: &TimeSlicedSurveyResponseMessageView<'_>) -> Self { + Self { + response: (&v.response).into(), + nonce: v.nonce, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TimeSlicedSurveyResponseMessage { + #[must_use] + fn from(v: TimeSlicedSurveyResponseMessageView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TimeSlicedSurveyResponseMessageView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.response.write_xdr(w)?; + self.nonce.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/topology_response_body_v2.rs b/src/generated/topology_response_body_v2.rs index c87159ff5..c6dba99c3 100644 --- a/src/generated/topology_response_body_v2.rs +++ b/src/generated/topology_response_body_v2.rs @@ -53,3 +53,44 @@ impl WriteXdr for TopologyResponseBodyV2 { }) } } + +/// TopologyResponseBodyV2View is a borrowing equivalent of [`TopologyResponseBodyV2`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TopologyResponseBodyV2View<'a> { + pub inbound_peers: TimeSlicedPeerDataListView<'a>, + pub outbound_peers: TimeSlicedPeerDataListView<'a>, + pub node_data: TimeSlicedNodeData, +} + +#[cfg(feature = "alloc")] +impl From<&TopologyResponseBodyV2View<'_>> for TopologyResponseBodyV2 { + #[must_use] + fn from(v: &TopologyResponseBodyV2View<'_>) -> Self { + Self { + inbound_peers: (&v.inbound_peers).into(), + outbound_peers: (&v.outbound_peers).into(), + node_data: v.node_data.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TopologyResponseBodyV2 { + #[must_use] + fn from(v: TopologyResponseBodyV2View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TopologyResponseBodyV2View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.inbound_peers.write_xdr(w)?; + self.outbound_peers.write_xdr(w)?; + self.node_data.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction.rs b/src/generated/transaction.rs index d3c41d730..3fdd6efc8 100644 --- a/src/generated/transaction.rs +++ b/src/generated/transaction.rs @@ -86,3 +86,56 @@ impl WriteXdr for Transaction { }) } } + +/// TransactionView is a borrowing equivalent of [`Transaction`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionView<'a> { + pub source_account: MuxedAccount, + pub fee: u32, + pub seq_num: SequenceNumber, + pub cond: PreconditionsView<'a>, + pub memo: MemoView<'a>, + pub operations: VecMView<'a, OperationView<'a>, 100>, + pub ext: TransactionExtView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionView<'_>> for Transaction { + #[must_use] + fn from(v: &TransactionView<'_>) -> Self { + Self { + source_account: v.source_account.clone(), + fee: v.fee, + seq_num: v.seq_num.clone(), + cond: (&v.cond).into(), + memo: (&v.memo).into(), + operations: v.operations.to_vecm_from(), + ext: (&v.ext).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for Transaction { + #[must_use] + fn from(v: TransactionView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.source_account.write_xdr(w)?; + self.fee.write_xdr(w)?; + self.seq_num.write_xdr(w)?; + self.cond.write_xdr(w)?; + self.memo.write_xdr(w)?; + self.operations.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_envelope.rs b/src/generated/transaction_envelope.rs index 501ac55f2..663ee52a9 100644 --- a/src/generated/transaction_envelope.rs +++ b/src/generated/transaction_envelope.rs @@ -141,3 +141,62 @@ impl WriteXdr for TransactionEnvelope { }) } } + +/// TransactionEnvelopeView is a borrowing equivalent of [`TransactionEnvelope`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum TransactionEnvelopeView<'a> { + TxV0(TransactionV0EnvelopeView<'a>), + Tx(TransactionV1EnvelopeView<'a>), + TxFeeBump(FeeBumpTransactionEnvelopeView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&TransactionEnvelopeView<'_>> for TransactionEnvelope { + #[must_use] + fn from(v: &TransactionEnvelopeView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + TransactionEnvelopeView::TxV0(value) => Self::TxV0(value.into()), + TransactionEnvelopeView::Tx(value) => Self::Tx(value.into()), + TransactionEnvelopeView::TxFeeBump(value) => Self::TxFeeBump(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionEnvelope { + #[must_use] + fn from(v: TransactionEnvelopeView<'_>) -> Self { + Self::from(&v) + } +} + +impl TransactionEnvelopeView<'_> { + #[must_use] + pub const fn discriminant(&self) -> EnvelopeType { + #[allow(clippy::match_same_arms)] + match self { + Self::TxV0(_) => EnvelopeType::TxV0, + Self::Tx(_) => EnvelopeType::Tx, + Self::TxFeeBump(_) => EnvelopeType::TxFeeBump, + } + } +} + +impl WriteXdr for TransactionEnvelopeView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::TxV0(v) => v.write_xdr(w)?, + Self::Tx(v) => v.write_xdr(w)?, + Self::TxFeeBump(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_event.rs b/src/generated/transaction_event.rs index e577e3918..1972116c8 100644 --- a/src/generated/transaction_event.rs +++ b/src/generated/transaction_event.rs @@ -48,3 +48,41 @@ impl WriteXdr for TransactionEvent { }) } } + +/// TransactionEventView is a borrowing equivalent of [`TransactionEvent`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionEventView<'a> { + pub stage: TransactionEventStage, + pub event: ContractEventView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionEventView<'_>> for TransactionEvent { + #[must_use] + fn from(v: &TransactionEventView<'_>) -> Self { + Self { + stage: v.stage, + event: (&v.event).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionEvent { + #[must_use] + fn from(v: TransactionEventView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionEventView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.stage.write_xdr(w)?; + self.event.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_ext.rs b/src/generated/transaction_ext.rs index 1d6037d3c..3f921688a 100644 --- a/src/generated/transaction_ext.rs +++ b/src/generated/transaction_ext.rs @@ -135,3 +135,58 @@ impl WriteXdr for TransactionExt { }) } } + +/// TransactionExtView is a borrowing equivalent of [`TransactionExt`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum TransactionExtView<'a> { + V0, + V1(SorobanTransactionDataView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&TransactionExtView<'_>> for TransactionExt { + #[must_use] + fn from(v: &TransactionExtView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + TransactionExtView::V0 => Self::V0, + TransactionExtView::V1(value) => Self::V1(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionExt { + #[must_use] + fn from(v: TransactionExtView<'_>) -> Self { + Self::from(&v) + } +} + +impl TransactionExtView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V1(_) => 1, + } + } +} + +impl WriteXdr for TransactionExtView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => ().write_xdr(w)?, + Self::V1(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_history_entry.rs b/src/generated/transaction_history_entry.rs index 30968e6a7..5513bc54e 100644 --- a/src/generated/transaction_history_entry.rs +++ b/src/generated/transaction_history_entry.rs @@ -62,3 +62,44 @@ impl WriteXdr for TransactionHistoryEntry { }) } } + +/// TransactionHistoryEntryView is a borrowing equivalent of [`TransactionHistoryEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionHistoryEntryView<'a> { + pub ledger_seq: u32, + pub tx_set: TransactionSetView<'a>, + pub ext: TransactionHistoryEntryExtView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionHistoryEntryView<'_>> for TransactionHistoryEntry { + #[must_use] + fn from(v: &TransactionHistoryEntryView<'_>) -> Self { + Self { + ledger_seq: v.ledger_seq, + tx_set: (&v.tx_set).into(), + ext: (&v.ext).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionHistoryEntry { + #[must_use] + fn from(v: TransactionHistoryEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionHistoryEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ledger_seq.write_xdr(w)?; + self.tx_set.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_history_entry_ext.rs b/src/generated/transaction_history_entry_ext.rs index fe6641b4c..5c9d1553b 100644 --- a/src/generated/transaction_history_entry_ext.rs +++ b/src/generated/transaction_history_entry_ext.rs @@ -135,3 +135,58 @@ impl WriteXdr for TransactionHistoryEntryExt { }) } } + +/// TransactionHistoryEntryExtView is a borrowing equivalent of [`TransactionHistoryEntryExt`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum TransactionHistoryEntryExtView<'a> { + V0, + V1(GeneralizedTransactionSetView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&TransactionHistoryEntryExtView<'_>> for TransactionHistoryEntryExt { + #[must_use] + fn from(v: &TransactionHistoryEntryExtView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + TransactionHistoryEntryExtView::V0 => Self::V0, + TransactionHistoryEntryExtView::V1(value) => Self::V1(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionHistoryEntryExt { + #[must_use] + fn from(v: TransactionHistoryEntryExtView<'_>) -> Self { + Self::from(&v) + } +} + +impl TransactionHistoryEntryExtView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => 0, + Self::V1(_) => 1, + } + } +} + +impl WriteXdr for TransactionHistoryEntryExtView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0 => ().write_xdr(w)?, + Self::V1(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_history_result_entry.rs b/src/generated/transaction_history_result_entry.rs index 1c54032f4..ddba05f0c 100644 --- a/src/generated/transaction_history_result_entry.rs +++ b/src/generated/transaction_history_result_entry.rs @@ -60,3 +60,44 @@ impl WriteXdr for TransactionHistoryResultEntry { }) } } + +/// TransactionHistoryResultEntryView is a borrowing equivalent of [`TransactionHistoryResultEntry`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionHistoryResultEntryView<'a> { + pub ledger_seq: u32, + pub tx_result_set: TransactionResultSetView<'a>, + pub ext: TransactionHistoryResultEntryExt, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionHistoryResultEntryView<'_>> for TransactionHistoryResultEntry { + #[must_use] + fn from(v: &TransactionHistoryResultEntryView<'_>) -> Self { + Self { + ledger_seq: v.ledger_seq, + tx_result_set: (&v.tx_result_set).into(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionHistoryResultEntry { + #[must_use] + fn from(v: TransactionHistoryResultEntryView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionHistoryResultEntryView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ledger_seq.write_xdr(w)?; + self.tx_result_set.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_meta.rs b/src/generated/transaction_meta.rs index d486c17b1..a104bbff0 100644 --- a/src/generated/transaction_meta.rs +++ b/src/generated/transaction_meta.rs @@ -156,3 +156,70 @@ impl WriteXdr for TransactionMeta { }) } } + +/// TransactionMetaView is a borrowing equivalent of [`TransactionMeta`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum TransactionMetaView<'a> { + V0(VecMView<'a, OperationMetaView<'a>>), + V1(TransactionMetaV1View<'a>), + V2(TransactionMetaV2View<'a>), + V3(TransactionMetaV3View<'a>), + V4(TransactionMetaV4View<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&TransactionMetaView<'_>> for TransactionMeta { + #[must_use] + fn from(v: &TransactionMetaView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + TransactionMetaView::V0(value) => Self::V0(value.to_vecm_from()), + TransactionMetaView::V1(value) => Self::V1(value.into()), + TransactionMetaView::V2(value) => Self::V2(value.into()), + TransactionMetaView::V3(value) => Self::V3(value.into()), + TransactionMetaView::V4(value) => Self::V4(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionMeta { + #[must_use] + fn from(v: TransactionMetaView<'_>) -> Self { + Self::from(&v) + } +} + +impl TransactionMetaView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + Self::V2(_) => 2, + Self::V3(_) => 3, + Self::V4(_) => 4, + } + } +} + +impl WriteXdr for TransactionMetaView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0(v) => v.write_xdr(w)?, + Self::V1(v) => v.write_xdr(w)?, + Self::V2(v) => v.write_xdr(w)?, + Self::V3(v) => v.write_xdr(w)?, + Self::V4(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_meta_v1.rs b/src/generated/transaction_meta_v1.rs index 0e6d325d9..001ea9752 100644 --- a/src/generated/transaction_meta_v1.rs +++ b/src/generated/transaction_meta_v1.rs @@ -49,3 +49,41 @@ impl WriteXdr for TransactionMetaV1 { }) } } + +/// TransactionMetaV1View is a borrowing equivalent of [`TransactionMetaV1`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionMetaV1View<'a> { + pub tx_changes: LedgerEntryChangesView<'a>, + pub operations: VecMView<'a, OperationMetaView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionMetaV1View<'_>> for TransactionMetaV1 { + #[must_use] + fn from(v: &TransactionMetaV1View<'_>) -> Self { + Self { + tx_changes: (&v.tx_changes).into(), + operations: v.operations.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionMetaV1 { + #[must_use] + fn from(v: TransactionMetaV1View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionMetaV1View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx_changes.write_xdr(w)?; + self.operations.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_meta_v2.rs b/src/generated/transaction_meta_v2.rs index d1239429d..6f9c26236 100644 --- a/src/generated/transaction_meta_v2.rs +++ b/src/generated/transaction_meta_v2.rs @@ -55,3 +55,44 @@ impl WriteXdr for TransactionMetaV2 { }) } } + +/// TransactionMetaV2View is a borrowing equivalent of [`TransactionMetaV2`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionMetaV2View<'a> { + pub tx_changes_before: LedgerEntryChangesView<'a>, + pub operations: VecMView<'a, OperationMetaView<'a>>, + pub tx_changes_after: LedgerEntryChangesView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionMetaV2View<'_>> for TransactionMetaV2 { + #[must_use] + fn from(v: &TransactionMetaV2View<'_>) -> Self { + Self { + tx_changes_before: (&v.tx_changes_before).into(), + operations: v.operations.to_vecm_from(), + tx_changes_after: (&v.tx_changes_after).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionMetaV2 { + #[must_use] + fn from(v: TransactionMetaV2View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionMetaV2View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx_changes_before.write_xdr(w)?; + self.operations.write_xdr(w)?; + self.tx_changes_after.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_meta_v3.rs b/src/generated/transaction_meta_v3.rs index 4e253d7a1..a558d33df 100644 --- a/src/generated/transaction_meta_v3.rs +++ b/src/generated/transaction_meta_v3.rs @@ -65,3 +65,50 @@ impl WriteXdr for TransactionMetaV3 { }) } } + +/// TransactionMetaV3View is a borrowing equivalent of [`TransactionMetaV3`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionMetaV3View<'a> { + pub ext: ExtensionPoint, + pub tx_changes_before: LedgerEntryChangesView<'a>, + pub operations: VecMView<'a, OperationMetaView<'a>>, + pub tx_changes_after: LedgerEntryChangesView<'a>, + pub soroban_meta: Option>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionMetaV3View<'_>> for TransactionMetaV3 { + #[must_use] + fn from(v: &TransactionMetaV3View<'_>) -> Self { + Self { + ext: v.ext.clone(), + tx_changes_before: (&v.tx_changes_before).into(), + operations: v.operations.to_vecm_from(), + tx_changes_after: (&v.tx_changes_after).into(), + soroban_meta: v.soroban_meta.as_ref().map(Into::into), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionMetaV3 { + #[must_use] + fn from(v: TransactionMetaV3View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionMetaV3View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.tx_changes_before.write_xdr(w)?; + self.operations.write_xdr(w)?; + self.tx_changes_after.write_xdr(w)?; + self.soroban_meta.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_meta_v4.rs b/src/generated/transaction_meta_v4.rs index b07c7f572..2f41836e7 100644 --- a/src/generated/transaction_meta_v4.rs +++ b/src/generated/transaction_meta_v4.rs @@ -74,3 +74,56 @@ impl WriteXdr for TransactionMetaV4 { }) } } + +/// TransactionMetaV4View is a borrowing equivalent of [`TransactionMetaV4`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionMetaV4View<'a> { + pub ext: ExtensionPoint, + pub tx_changes_before: LedgerEntryChangesView<'a>, + pub operations: VecMView<'a, OperationMetaV2View<'a>>, + pub tx_changes_after: LedgerEntryChangesView<'a>, + pub soroban_meta: Option>, + pub events: VecMView<'a, TransactionEventView<'a>>, + pub diagnostic_events: VecMView<'a, DiagnosticEventView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionMetaV4View<'_>> for TransactionMetaV4 { + #[must_use] + fn from(v: &TransactionMetaV4View<'_>) -> Self { + Self { + ext: v.ext.clone(), + tx_changes_before: (&v.tx_changes_before).into(), + operations: v.operations.to_vecm_from(), + tx_changes_after: (&v.tx_changes_after).into(), + soroban_meta: v.soroban_meta.as_ref().map(Into::into), + events: v.events.to_vecm_from(), + diagnostic_events: v.diagnostic_events.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionMetaV4 { + #[must_use] + fn from(v: TransactionMetaV4View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionMetaV4View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.tx_changes_before.write_xdr(w)?; + self.operations.write_xdr(w)?; + self.tx_changes_after.write_xdr(w)?; + self.soroban_meta.write_xdr(w)?; + self.events.write_xdr(w)?; + self.diagnostic_events.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_phase.rs b/src/generated/transaction_phase.rs index 6d4b9d7da..fbe4ff71c 100644 --- a/src/generated/transaction_phase.rs +++ b/src/generated/transaction_phase.rs @@ -135,3 +135,58 @@ impl WriteXdr for TransactionPhase { }) } } + +/// TransactionPhaseView is a borrowing equivalent of [`TransactionPhase`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum TransactionPhaseView<'a> { + V0(VecMView<'a, TxSetComponentView<'a>>), + V1(ParallelTxsComponentView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&TransactionPhaseView<'_>> for TransactionPhase { + #[must_use] + fn from(v: &TransactionPhaseView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + TransactionPhaseView::V0(value) => Self::V0(value.to_vecm_from()), + TransactionPhaseView::V1(value) => Self::V1(value.into()), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionPhase { + #[must_use] + fn from(v: TransactionPhaseView<'_>) -> Self { + Self::from(&v) + } +} + +impl TransactionPhaseView<'_> { + #[must_use] + pub const fn discriminant(&self) -> i32 { + #[allow(clippy::match_same_arms)] + match self { + Self::V0(_) => 0, + Self::V1(_) => 1, + } + } +} + +impl WriteXdr for TransactionPhaseView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::V0(v) => v.write_xdr(w)?, + Self::V1(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_result.rs b/src/generated/transaction_result.rs index 19e57621d..9f813c603 100644 --- a/src/generated/transaction_result.rs +++ b/src/generated/transaction_result.rs @@ -92,3 +92,44 @@ impl WriteXdr for TransactionResult { }) } } + +/// TransactionResultView is a borrowing equivalent of [`TransactionResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionResultView<'a> { + pub fee_charged: i64, + pub result: TransactionResultResultView<'a>, + pub ext: TransactionResultExt, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionResultView<'_>> for TransactionResult { + #[must_use] + fn from(v: &TransactionResultView<'_>) -> Self { + Self { + fee_charged: v.fee_charged, + result: (&v.result).into(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionResult { + #[must_use] + fn from(v: TransactionResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.fee_charged.write_xdr(w)?; + self.result.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_result_meta.rs b/src/generated/transaction_result_meta.rs index 745910280..1aa854cc2 100644 --- a/src/generated/transaction_result_meta.rs +++ b/src/generated/transaction_result_meta.rs @@ -53,3 +53,44 @@ impl WriteXdr for TransactionResultMeta { }) } } + +/// TransactionResultMetaView is a borrowing equivalent of [`TransactionResultMeta`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionResultMetaView<'a> { + pub result: TransactionResultPairView<'a>, + pub fee_processing: LedgerEntryChangesView<'a>, + pub tx_apply_processing: TransactionMetaView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionResultMetaView<'_>> for TransactionResultMeta { + #[must_use] + fn from(v: &TransactionResultMetaView<'_>) -> Self { + Self { + result: (&v.result).into(), + fee_processing: (&v.fee_processing).into(), + tx_apply_processing: (&v.tx_apply_processing).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionResultMeta { + #[must_use] + fn from(v: TransactionResultMetaView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionResultMetaView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.result.write_xdr(w)?; + self.fee_processing.write_xdr(w)?; + self.tx_apply_processing.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_result_meta_v1.rs b/src/generated/transaction_result_meta_v1.rs index 77b2d3025..6ef501db6 100644 --- a/src/generated/transaction_result_meta_v1.rs +++ b/src/generated/transaction_result_meta_v1.rs @@ -63,3 +63,50 @@ impl WriteXdr for TransactionResultMetaV1 { }) } } + +/// TransactionResultMetaV1View is a borrowing equivalent of [`TransactionResultMetaV1`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionResultMetaV1View<'a> { + pub ext: ExtensionPoint, + pub result: TransactionResultPairView<'a>, + pub fee_processing: LedgerEntryChangesView<'a>, + pub tx_apply_processing: TransactionMetaView<'a>, + pub post_tx_apply_fee_processing: LedgerEntryChangesView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionResultMetaV1View<'_>> for TransactionResultMetaV1 { + #[must_use] + fn from(v: &TransactionResultMetaV1View<'_>) -> Self { + Self { + ext: v.ext.clone(), + result: (&v.result).into(), + fee_processing: (&v.fee_processing).into(), + tx_apply_processing: (&v.tx_apply_processing).into(), + post_tx_apply_fee_processing: (&v.post_tx_apply_fee_processing).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionResultMetaV1 { + #[must_use] + fn from(v: TransactionResultMetaV1View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionResultMetaV1View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.ext.write_xdr(w)?; + self.result.write_xdr(w)?; + self.fee_processing.write_xdr(w)?; + self.tx_apply_processing.write_xdr(w)?; + self.post_tx_apply_fee_processing.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_result_pair.rs b/src/generated/transaction_result_pair.rs index 7813858f2..98c51e7fe 100644 --- a/src/generated/transaction_result_pair.rs +++ b/src/generated/transaction_result_pair.rs @@ -49,3 +49,41 @@ impl WriteXdr for TransactionResultPair { }) } } + +/// TransactionResultPairView is a borrowing equivalent of [`TransactionResultPair`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionResultPairView<'a> { + pub transaction_hash: Hash, + pub result: TransactionResultView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionResultPairView<'_>> for TransactionResultPair { + #[must_use] + fn from(v: &TransactionResultPairView<'_>) -> Self { + Self { + transaction_hash: v.transaction_hash.clone(), + result: (&v.result).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionResultPair { + #[must_use] + fn from(v: TransactionResultPairView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionResultPairView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.transaction_hash.write_xdr(w)?; + self.result.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_result_result.rs b/src/generated/transaction_result_result.rs index ceffab3f0..5ccdb8231 100644 --- a/src/generated/transaction_result_result.rs +++ b/src/generated/transaction_result_result.rs @@ -295,3 +295,134 @@ impl WriteXdr for TransactionResultResult { }) } } + +/// TransactionResultResultView is a borrowing equivalent of [`TransactionResultResult`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum TransactionResultResultView<'a> { + TxFeeBumpInnerSuccess(InnerTransactionResultPairView<'a>), + TxFeeBumpInnerFailed(InnerTransactionResultPairView<'a>), + TxSuccess(VecMView<'a, OperationResultView<'a>>), + TxFailed(VecMView<'a, OperationResultView<'a>>), + TxTooEarly, + TxTooLate, + TxMissingOperation, + TxBadSeq, + TxBadAuth, + TxInsufficientBalance, + TxNoAccount, + TxInsufficientFee, + TxBadAuthExtra, + TxInternalError, + TxNotSupported, + TxBadSponsorship, + TxBadMinSeqAgeOrGap, + TxMalformed, + TxSorobanInvalid, + TxFrozenKeyAccessed, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionResultResultView<'_>> for TransactionResultResult { + #[must_use] + fn from(v: &TransactionResultResultView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + TransactionResultResultView::TxFeeBumpInnerSuccess(value) => { + Self::TxFeeBumpInnerSuccess(value.into()) + } + TransactionResultResultView::TxFeeBumpInnerFailed(value) => { + Self::TxFeeBumpInnerFailed(value.into()) + } + TransactionResultResultView::TxSuccess(value) => Self::TxSuccess(value.to_vecm_from()), + TransactionResultResultView::TxFailed(value) => Self::TxFailed(value.to_vecm_from()), + TransactionResultResultView::TxTooEarly => Self::TxTooEarly, + TransactionResultResultView::TxTooLate => Self::TxTooLate, + TransactionResultResultView::TxMissingOperation => Self::TxMissingOperation, + TransactionResultResultView::TxBadSeq => Self::TxBadSeq, + TransactionResultResultView::TxBadAuth => Self::TxBadAuth, + TransactionResultResultView::TxInsufficientBalance => Self::TxInsufficientBalance, + TransactionResultResultView::TxNoAccount => Self::TxNoAccount, + TransactionResultResultView::TxInsufficientFee => Self::TxInsufficientFee, + TransactionResultResultView::TxBadAuthExtra => Self::TxBadAuthExtra, + TransactionResultResultView::TxInternalError => Self::TxInternalError, + TransactionResultResultView::TxNotSupported => Self::TxNotSupported, + TransactionResultResultView::TxBadSponsorship => Self::TxBadSponsorship, + TransactionResultResultView::TxBadMinSeqAgeOrGap => Self::TxBadMinSeqAgeOrGap, + TransactionResultResultView::TxMalformed => Self::TxMalformed, + TransactionResultResultView::TxSorobanInvalid => Self::TxSorobanInvalid, + TransactionResultResultView::TxFrozenKeyAccessed => Self::TxFrozenKeyAccessed, + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionResultResult { + #[must_use] + fn from(v: TransactionResultResultView<'_>) -> Self { + Self::from(&v) + } +} + +impl TransactionResultResultView<'_> { + #[must_use] + pub const fn discriminant(&self) -> TransactionResultCode { + #[allow(clippy::match_same_arms)] + match self { + Self::TxFeeBumpInnerSuccess(_) => TransactionResultCode::TxFeeBumpInnerSuccess, + Self::TxFeeBumpInnerFailed(_) => TransactionResultCode::TxFeeBumpInnerFailed, + Self::TxSuccess(_) => TransactionResultCode::TxSuccess, + Self::TxFailed(_) => TransactionResultCode::TxFailed, + Self::TxTooEarly => TransactionResultCode::TxTooEarly, + Self::TxTooLate => TransactionResultCode::TxTooLate, + Self::TxMissingOperation => TransactionResultCode::TxMissingOperation, + Self::TxBadSeq => TransactionResultCode::TxBadSeq, + Self::TxBadAuth => TransactionResultCode::TxBadAuth, + Self::TxInsufficientBalance => TransactionResultCode::TxInsufficientBalance, + Self::TxNoAccount => TransactionResultCode::TxNoAccount, + Self::TxInsufficientFee => TransactionResultCode::TxInsufficientFee, + Self::TxBadAuthExtra => TransactionResultCode::TxBadAuthExtra, + Self::TxInternalError => TransactionResultCode::TxInternalError, + Self::TxNotSupported => TransactionResultCode::TxNotSupported, + Self::TxBadSponsorship => TransactionResultCode::TxBadSponsorship, + Self::TxBadMinSeqAgeOrGap => TransactionResultCode::TxBadMinSeqAgeOrGap, + Self::TxMalformed => TransactionResultCode::TxMalformed, + Self::TxSorobanInvalid => TransactionResultCode::TxSorobanInvalid, + Self::TxFrozenKeyAccessed => TransactionResultCode::TxFrozenKeyAccessed, + } + } +} + +impl WriteXdr for TransactionResultResultView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::TxFeeBumpInnerSuccess(v) => v.write_xdr(w)?, + Self::TxFeeBumpInnerFailed(v) => v.write_xdr(w)?, + Self::TxSuccess(v) => v.write_xdr(w)?, + Self::TxFailed(v) => v.write_xdr(w)?, + Self::TxTooEarly => ().write_xdr(w)?, + Self::TxTooLate => ().write_xdr(w)?, + Self::TxMissingOperation => ().write_xdr(w)?, + Self::TxBadSeq => ().write_xdr(w)?, + Self::TxBadAuth => ().write_xdr(w)?, + Self::TxInsufficientBalance => ().write_xdr(w)?, + Self::TxNoAccount => ().write_xdr(w)?, + Self::TxInsufficientFee => ().write_xdr(w)?, + Self::TxBadAuthExtra => ().write_xdr(w)?, + Self::TxInternalError => ().write_xdr(w)?, + Self::TxNotSupported => ().write_xdr(w)?, + Self::TxBadSponsorship => ().write_xdr(w)?, + Self::TxBadMinSeqAgeOrGap => ().write_xdr(w)?, + Self::TxMalformed => ().write_xdr(w)?, + Self::TxSorobanInvalid => ().write_xdr(w)?, + Self::TxFrozenKeyAccessed => ().write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_result_set.rs b/src/generated/transaction_result_set.rs index 72f9b01c6..fa1968a15 100644 --- a/src/generated/transaction_result_set.rs +++ b/src/generated/transaction_result_set.rs @@ -45,3 +45,38 @@ impl WriteXdr for TransactionResultSet { }) } } + +/// TransactionResultSetView is a borrowing equivalent of [`TransactionResultSet`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionResultSetView<'a> { + pub results: VecMView<'a, TransactionResultPairView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionResultSetView<'_>> for TransactionResultSet { + #[must_use] + fn from(v: &TransactionResultSetView<'_>) -> Self { + Self { + results: v.results.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionResultSet { + #[must_use] + fn from(v: TransactionResultSetView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionResultSetView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.results.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_set.rs b/src/generated/transaction_set.rs index 28e34fd41..ea0ab8b18 100644 --- a/src/generated/transaction_set.rs +++ b/src/generated/transaction_set.rs @@ -49,3 +49,41 @@ impl WriteXdr for TransactionSet { }) } } + +/// TransactionSetView is a borrowing equivalent of [`TransactionSet`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionSetView<'a> { + pub previous_ledger_hash: Hash, + pub txs: VecMView<'a, TransactionEnvelopeView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionSetView<'_>> for TransactionSet { + #[must_use] + fn from(v: &TransactionSetView<'_>) -> Self { + Self { + previous_ledger_hash: v.previous_ledger_hash.clone(), + txs: v.txs.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionSet { + #[must_use] + fn from(v: TransactionSetView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionSetView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.previous_ledger_hash.write_xdr(w)?; + self.txs.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_set_v1.rs b/src/generated/transaction_set_v1.rs index 4afaa0d99..7689e265a 100644 --- a/src/generated/transaction_set_v1.rs +++ b/src/generated/transaction_set_v1.rs @@ -49,3 +49,41 @@ impl WriteXdr for TransactionSetV1 { }) } } + +/// TransactionSetV1View is a borrowing equivalent of [`TransactionSetV1`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionSetV1View<'a> { + pub previous_ledger_hash: Hash, + pub phases: VecMView<'a, TransactionPhaseView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionSetV1View<'_>> for TransactionSetV1 { + #[must_use] + fn from(v: &TransactionSetV1View<'_>) -> Self { + Self { + previous_ledger_hash: v.previous_ledger_hash.clone(), + phases: v.phases.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionSetV1 { + #[must_use] + fn from(v: TransactionSetV1View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionSetV1View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.previous_ledger_hash.write_xdr(w)?; + self.phases.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_signature_payload.rs b/src/generated/transaction_signature_payload.rs index f40765445..5a528bf58 100644 --- a/src/generated/transaction_signature_payload.rs +++ b/src/generated/transaction_signature_payload.rs @@ -57,3 +57,41 @@ impl WriteXdr for TransactionSignaturePayload { }) } } + +/// TransactionSignaturePayloadView is a borrowing equivalent of [`TransactionSignaturePayload`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionSignaturePayloadView<'a> { + pub network_id: Hash, + pub tagged_transaction: TransactionSignaturePayloadTaggedTransactionView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionSignaturePayloadView<'_>> for TransactionSignaturePayload { + #[must_use] + fn from(v: &TransactionSignaturePayloadView<'_>) -> Self { + Self { + network_id: v.network_id.clone(), + tagged_transaction: (&v.tagged_transaction).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionSignaturePayload { + #[must_use] + fn from(v: TransactionSignaturePayloadView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionSignaturePayloadView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.network_id.write_xdr(w)?; + self.tagged_transaction.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_signature_payload_tagged_transaction.rs b/src/generated/transaction_signature_payload_tagged_transaction.rs index 6554d937b..408d70498 100644 --- a/src/generated/transaction_signature_payload_tagged_transaction.rs +++ b/src/generated/transaction_signature_payload_tagged_transaction.rs @@ -136,3 +136,64 @@ impl WriteXdr for TransactionSignaturePayloadTaggedTransaction { }) } } + +/// TransactionSignaturePayloadTaggedTransactionView is a borrowing equivalent of [`TransactionSignaturePayloadTaggedTransaction`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum TransactionSignaturePayloadTaggedTransactionView<'a> { + Tx(TransactionView<'a>), + TxFeeBump(FeeBumpTransactionView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&TransactionSignaturePayloadTaggedTransactionView<'_>> + for TransactionSignaturePayloadTaggedTransaction +{ + #[must_use] + fn from(v: &TransactionSignaturePayloadTaggedTransactionView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + TransactionSignaturePayloadTaggedTransactionView::Tx(value) => Self::Tx(value.into()), + TransactionSignaturePayloadTaggedTransactionView::TxFeeBump(value) => { + Self::TxFeeBump(value.into()) + } + } + } +} + +#[cfg(feature = "alloc")] +impl From> + for TransactionSignaturePayloadTaggedTransaction +{ + #[must_use] + fn from(v: TransactionSignaturePayloadTaggedTransactionView<'_>) -> Self { + Self::from(&v) + } +} + +impl TransactionSignaturePayloadTaggedTransactionView<'_> { + #[must_use] + pub const fn discriminant(&self) -> EnvelopeType { + #[allow(clippy::match_same_arms)] + match self { + Self::Tx(_) => EnvelopeType::Tx, + Self::TxFeeBump(_) => EnvelopeType::TxFeeBump, + } + } +} + +impl WriteXdr for TransactionSignaturePayloadTaggedTransactionView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::Tx(v) => v.write_xdr(w)?, + Self::TxFeeBump(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_v0.rs b/src/generated/transaction_v0.rs index e6b961615..91c1dc95c 100644 --- a/src/generated/transaction_v0.rs +++ b/src/generated/transaction_v0.rs @@ -74,3 +74,56 @@ impl WriteXdr for TransactionV0 { }) } } + +/// TransactionV0View is a borrowing equivalent of [`TransactionV0`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionV0View<'a> { + pub source_account_ed25519: Uint256, + pub fee: u32, + pub seq_num: SequenceNumber, + pub time_bounds: Option, + pub memo: MemoView<'a>, + pub operations: VecMView<'a, OperationView<'a>, 100>, + pub ext: TransactionV0Ext, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionV0View<'_>> for TransactionV0 { + #[must_use] + fn from(v: &TransactionV0View<'_>) -> Self { + Self { + source_account_ed25519: v.source_account_ed25519.clone(), + fee: v.fee, + seq_num: v.seq_num.clone(), + time_bounds: v.time_bounds.clone(), + memo: (&v.memo).into(), + operations: v.operations.to_vecm_from(), + ext: v.ext.clone(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionV0 { + #[must_use] + fn from(v: TransactionV0View<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionV0View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.source_account_ed25519.write_xdr(w)?; + self.fee.write_xdr(w)?; + self.seq_num.write_xdr(w)?; + self.time_bounds.write_xdr(w)?; + self.memo.write_xdr(w)?; + self.operations.write_xdr(w)?; + self.ext.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_v0_envelope.rs b/src/generated/transaction_v0_envelope.rs index 6e3a3c293..55195d2eb 100644 --- a/src/generated/transaction_v0_envelope.rs +++ b/src/generated/transaction_v0_envelope.rs @@ -51,3 +51,41 @@ impl WriteXdr for TransactionV0Envelope { }) } } + +/// TransactionV0EnvelopeView is a borrowing equivalent of [`TransactionV0Envelope`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionV0EnvelopeView<'a> { + pub tx: TransactionV0View<'a>, + pub signatures: VecMView<'a, DecoratedSignatureView<'a>, 20>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionV0EnvelopeView<'_>> for TransactionV0Envelope { + #[must_use] + fn from(v: &TransactionV0EnvelopeView<'_>) -> Self { + Self { + tx: (&v.tx).into(), + signatures: v.signatures.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionV0Envelope { + #[must_use] + fn from(v: TransactionV0EnvelopeView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionV0EnvelopeView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx.write_xdr(w)?; + self.signatures.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/transaction_v1_envelope.rs b/src/generated/transaction_v1_envelope.rs index 3f4b0916c..c394582f6 100644 --- a/src/generated/transaction_v1_envelope.rs +++ b/src/generated/transaction_v1_envelope.rs @@ -51,3 +51,41 @@ impl WriteXdr for TransactionV1Envelope { }) } } + +/// TransactionV1EnvelopeView is a borrowing equivalent of [`TransactionV1Envelope`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TransactionV1EnvelopeView<'a> { + pub tx: TransactionView<'a>, + pub signatures: VecMView<'a, DecoratedSignatureView<'a>, 20>, +} + +#[cfg(feature = "alloc")] +impl From<&TransactionV1EnvelopeView<'_>> for TransactionV1Envelope { + #[must_use] + fn from(v: &TransactionV1EnvelopeView<'_>) -> Self { + Self { + tx: (&v.tx).into(), + signatures: v.signatures.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TransactionV1Envelope { + #[must_use] + fn from(v: TransactionV1EnvelopeView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TransactionV1EnvelopeView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.tx.write_xdr(w)?; + self.signatures.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/tx_advert_vector.rs b/src/generated/tx_advert_vector.rs index 7cdc02c5e..45bb67590 100644 --- a/src/generated/tx_advert_vector.rs +++ b/src/generated/tx_advert_vector.rs @@ -107,3 +107,31 @@ impl AsRef<[Hash]> for TxAdvertVector { self.0 .0 } } + +/// TxAdvertVectorView is a borrowing equivalent of [`TxAdvertVector`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TxAdvertVectorView<'a>(pub VecMView<'a, Hash, 1000>); + +#[cfg(feature = "alloc")] +impl From<&TxAdvertVectorView<'_>> for TxAdvertVector { + #[must_use] + fn from(v: &TxAdvertVectorView<'_>) -> Self { + Self(v.0.to_vecm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for TxAdvertVector { + #[must_use] + fn from(v: TxAdvertVectorView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TxAdvertVectorView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/tx_demand_vector.rs b/src/generated/tx_demand_vector.rs index 1760bc7a1..728a28125 100644 --- a/src/generated/tx_demand_vector.rs +++ b/src/generated/tx_demand_vector.rs @@ -107,3 +107,31 @@ impl AsRef<[Hash]> for TxDemandVector { self.0 .0 } } + +/// TxDemandVectorView is a borrowing equivalent of [`TxDemandVector`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TxDemandVectorView<'a>(pub VecMView<'a, Hash, 1000>); + +#[cfg(feature = "alloc")] +impl From<&TxDemandVectorView<'_>> for TxDemandVector { + #[must_use] + fn from(v: &TxDemandVectorView<'_>) -> Self { + Self(v.0.to_vecm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for TxDemandVector { + #[must_use] + fn from(v: TxDemandVectorView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TxDemandVectorView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/tx_set_component.rs b/src/generated/tx_set_component.rs index 7fffc97c5..eb680e460 100644 --- a/src/generated/tx_set_component.rs +++ b/src/generated/tx_set_component.rs @@ -138,3 +138,58 @@ impl WriteXdr for TxSetComponent { }) } } + +/// TxSetComponentView is a borrowing equivalent of [`TxSetComponent`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum TxSetComponentView<'a> { + TxsetCompTxsMaybeDiscountedFee(TxSetComponentTxsMaybeDiscountedFeeView<'a>), +} + +#[cfg(feature = "alloc")] +impl From<&TxSetComponentView<'_>> for TxSetComponent { + #[must_use] + fn from(v: &TxSetComponentView<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { + TxSetComponentView::TxsetCompTxsMaybeDiscountedFee(value) => { + Self::TxsetCompTxsMaybeDiscountedFee(value.into()) + } + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TxSetComponent { + #[must_use] + fn from(v: TxSetComponentView<'_>) -> Self { + Self::from(&v) + } +} + +impl TxSetComponentView<'_> { + #[must_use] + pub const fn discriminant(&self) -> TxSetComponentType { + #[allow(clippy::match_same_arms)] + match self { + Self::TxsetCompTxsMaybeDiscountedFee(_) => { + TxSetComponentType::TxsetCompTxsMaybeDiscountedFee + } + } + } +} + +impl WriteXdr for TxSetComponentView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { + Self::TxsetCompTxsMaybeDiscountedFee(v) => v.write_xdr(w)?, + }; + Ok(()) + }) + } +} diff --git a/src/generated/tx_set_component_txs_maybe_discounted_fee.rs b/src/generated/tx_set_component_txs_maybe_discounted_fee.rs index 09863a3cd..e34bbed4e 100644 --- a/src/generated/tx_set_component_txs_maybe_discounted_fee.rs +++ b/src/generated/tx_set_component_txs_maybe_discounted_fee.rs @@ -53,3 +53,41 @@ impl WriteXdr for TxSetComponentTxsMaybeDiscountedFee { }) } } + +/// TxSetComponentTxsMaybeDiscountedFeeView is a borrowing equivalent of [`TxSetComponentTxsMaybeDiscountedFee`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct TxSetComponentTxsMaybeDiscountedFeeView<'a> { + pub base_fee: Option, + pub txs: VecMView<'a, TransactionEnvelopeView<'a>>, +} + +#[cfg(feature = "alloc")] +impl From<&TxSetComponentTxsMaybeDiscountedFeeView<'_>> for TxSetComponentTxsMaybeDiscountedFee { + #[must_use] + fn from(v: &TxSetComponentTxsMaybeDiscountedFeeView<'_>) -> Self { + Self { + base_fee: v.base_fee, + txs: v.txs.to_vecm_from(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for TxSetComponentTxsMaybeDiscountedFee { + #[must_use] + fn from(v: TxSetComponentTxsMaybeDiscountedFeeView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for TxSetComponentTxsMaybeDiscountedFeeView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.base_fee.write_xdr(w)?; + self.txs.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/upgrade_entry_meta.rs b/src/generated/upgrade_entry_meta.rs index 28480e5ea..6384a9316 100644 --- a/src/generated/upgrade_entry_meta.rs +++ b/src/generated/upgrade_entry_meta.rs @@ -49,3 +49,41 @@ impl WriteXdr for UpgradeEntryMeta { }) } } + +/// UpgradeEntryMetaView is a borrowing equivalent of [`UpgradeEntryMeta`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct UpgradeEntryMetaView<'a> { + pub upgrade: LedgerUpgrade, + pub changes: LedgerEntryChangesView<'a>, +} + +#[cfg(feature = "alloc")] +impl From<&UpgradeEntryMetaView<'_>> for UpgradeEntryMeta { + #[must_use] + fn from(v: &UpgradeEntryMetaView<'_>) -> Self { + Self { + upgrade: v.upgrade.clone(), + changes: (&v.changes).into(), + } + } +} + +#[cfg(feature = "alloc")] +impl From> for UpgradeEntryMeta { + #[must_use] + fn from(v: UpgradeEntryMetaView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for UpgradeEntryMetaView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.upgrade.write_xdr(w)?; + self.changes.write_xdr(w)?; + Ok(()) + }) + } +} diff --git a/src/generated/upgrade_type.rs b/src/generated/upgrade_type.rs index b6b7ffb23..18a9974a3 100644 --- a/src/generated/upgrade_type.rs +++ b/src/generated/upgrade_type.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for UpgradeType { self.0 .0 } } + +/// UpgradeTypeView is a borrowing equivalent of [`UpgradeType`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct UpgradeTypeView<'a>(pub BytesMView<'a, 128>); + +#[cfg(feature = "alloc")] +impl From<&UpgradeTypeView<'_>> for UpgradeType { + #[must_use] + fn from(v: &UpgradeTypeView<'_>) -> Self { + Self(v.0.to_bytesm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for UpgradeType { + #[must_use] + fn from(v: UpgradeTypeView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for UpgradeTypeView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/src/generated/value.rs b/src/generated/value.rs index 6f45c5035..0ab488d67 100644 --- a/src/generated/value.rs +++ b/src/generated/value.rs @@ -107,3 +107,31 @@ impl AsRef<[u8]> for Value { self.0 .0 } } + +/// ValueView is a borrowing equivalent of [`Value`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ValueView<'a>(pub BytesMView<'a>); + +#[cfg(feature = "alloc")] +impl From<&ValueView<'_>> for Value { + #[must_use] + fn from(v: &ValueView<'_>) -> Self { + Self(v.0.to_bytesm()) + } +} + +#[cfg(feature = "alloc")] +impl From> for Value { + #[must_use] + fn from(v: ValueView<'_>) -> Self { + Self::from(&v) + } +} + +impl WriteXdr for ValueView<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} diff --git a/tests/view_types.rs b/tests/view_types.rs new file mode 100644 index 000000000..64d2b41e6 --- /dev/null +++ b/tests/view_types.rs @@ -0,0 +1,277 @@ +#![allow(clippy::items_after_test_module)] + +use stellar_xdr::{ + Asset, BytesMView, ClaimPredicateView, DecoratedSignatureView, Error, MemoView, MuxedAccount, + OperationBodyView, OperationView, PaymentOp, PreconditionsView, ScBytesView, ScSymbolView, + ScValView, ScVecView, SequenceNumber, SignatureHint, SignatureView, StringMView, + TransactionEnvelopeView, TransactionExtView, TransactionV1EnvelopeView, TransactionView, + Uint256, VecMView, +}; + +// A complete transaction envelope built entirely in a const context from +// borrowed data: slices of fixed-size arrays, string literals, and references. + +const OPERATIONS: [OperationView; 2] = [ + OperationView { + source_account: None, + body: OperationBodyView::Payment(PaymentOp { + destination: MuxedAccount::Ed25519(Uint256([1; 32])), + asset: Asset::Native, + amount: 100, + }), + }, + OperationView { + source_account: Some(MuxedAccount::Ed25519(Uint256([2; 32]))), + body: OperationBodyView::Payment(PaymentOp { + destination: MuxedAccount::Ed25519(Uint256([3; 32])), + asset: Asset::Native, + amount: 200, + }), + }, +]; + +const SIGNATURES: [DecoratedSignatureView; 1] = [DecoratedSignatureView { + hint: SignatureHint([1, 2, 3, 4]), + signature: SignatureView(BytesMView::new(&[9; 64])), +}]; + +const TX: TransactionView = TransactionView { + source_account: MuxedAccount::Ed25519(Uint256([0; 32])), + fee: 100, + seq_num: SequenceNumber(7), + cond: PreconditionsView::None, + memo: MemoView::Text(StringMView::new_str("hello")), + operations: VecMView::new(&OPERATIONS), + ext: TransactionExtView::V0, +}; + +const ENVELOPE: TransactionEnvelopeView = TransactionEnvelopeView::Tx(TransactionV1EnvelopeView { + tx: TX, + signatures: VecMView::new(&SIGNATURES), +}); + +// A recursive ScVal built in a const context: a vec of vals, one of which is +// itself a vec. + +const SCVAL_LEAVES: [ScValView; 3] = [ + ScValView::I32(1), + ScValView::Symbol(ScSymbolView(StringMView::new_str("sym"))), + ScValView::Bytes(ScBytesView(BytesMView::new(b"bytes"))), +]; + +const SCVAL: ScValView = ScValView::Vec(Some(ScVecView(VecMView::new(&[ + ScValView::Vec(Some(ScVecView(VecMView::new(&SCVAL_LEAVES)))), + ScValView::Bool(true), +])))); + +// A cyclic type built in a const context: where the owned type boxes the +// cycle (`Option>`), the View type borrows instead. + +const PREDICATE: ClaimPredicateView = + ClaimPredicateView::Not(Some(&ClaimPredicateView::And(VecMView::new(&[ + ClaimPredicateView::Unconditional, + ClaimPredicateView::BeforeAbsoluteTime(123), + ])))); + +#[test] +fn const_constructed_values() { + assert!(matches!( + ENVELOPE, + TransactionEnvelopeView::Tx(TransactionV1EnvelopeView { .. }) + )); + assert_eq!(TX.fee, 100); + assert_eq!(TX.operations.len(), 2); + assert_eq!(TX.operations.as_slice().len(), 2); + assert!(matches!(TX.memo, MemoView::Text(m) if m.as_slice() == b"hello")); + assert!(matches!(SCVAL, ScValView::Vec(Some(v)) if v.0.len() == 2)); + assert!(matches!( + PREDICATE, + ClaimPredicateView::Not(Some(ClaimPredicateView::And(p))) if p.len() == 2 + )); +} + +#[test] +fn vecm_view_construction_limits() { + let elems = [1u32, 2, 3]; + let v = VecMView::::try_new(&elems).unwrap(); + assert_eq!(v.len(), 3); + assert!(!v.is_empty()); + assert_eq!(v.as_slice(), &[1, 2, 3]); + assert_eq!(v.iter().copied().sum::(), 6); + assert_eq!(v.max_len(), 3); + assert_eq!( + VecMView::::try_new(&elems), + Err(Error::LengthExceedsMax) + ); +} + +#[test] +#[should_panic(expected = "length exceeds max")] +fn vecm_view_new_panics_over_max() { + let elems = [1u32, 2, 3]; + let _ = VecMView::::new(&elems); +} + +#[test] +fn bytesm_view_construction_limits() { + let v = BytesMView::<3>::try_new(b"abc").unwrap(); + assert_eq!(v.len(), 3); + assert_eq!(v.as_slice(), b"abc"); + assert_eq!( + BytesMView::<2>::try_new(b"abc"), + Err(Error::LengthExceedsMax) + ); +} + +#[test] +fn stringm_view_construction_limits() { + let v = StringMView::<5>::try_new_str("abc").unwrap(); + assert_eq!(v.as_slice(), b"abc"); + let v = StringMView::<5>::try_new(b"abc").unwrap(); + assert_eq!(v.len(), 3); + assert_eq!( + StringMView::<2>::try_new_str("abc"), + Err(Error::LengthExceedsMax) + ); +} + +#[cfg(feature = "alloc")] +mod alloc { + use super::*; + use stellar_xdr::{ + BytesM, ClaimPredicate, DecoratedSignature, Memo, Operation, OperationBody, Preconditions, + ScBytes, ScSymbol, ScVal, ScVec, Signature, StringM, Transaction, TransactionEnvelope, + TransactionExt, TransactionV1Envelope, VecM, + }; + + fn owned_envelope() -> TransactionEnvelope { + TransactionEnvelope::Tx(TransactionV1Envelope { + tx: Transaction { + source_account: MuxedAccount::Ed25519(Uint256([0; 32])), + fee: 100, + seq_num: SequenceNumber(7), + cond: Preconditions::None, + memo: Memo::Text("hello".try_into().unwrap()), + operations: vec![ + Operation { + source_account: None, + body: OperationBody::Payment(PaymentOp { + destination: MuxedAccount::Ed25519(Uint256([1; 32])), + asset: Asset::Native, + amount: 100, + }), + }, + Operation { + source_account: Some(MuxedAccount::Ed25519(Uint256([2; 32]))), + body: OperationBody::Payment(PaymentOp { + destination: MuxedAccount::Ed25519(Uint256([3; 32])), + asset: Asset::Native, + amount: 200, + }), + }, + ] + .try_into() + .unwrap(), + ext: TransactionExt::V0, + }, + signatures: vec![DecoratedSignature { + hint: SignatureHint([1, 2, 3, 4]), + signature: Signature(vec![9u8; 64].try_into().unwrap()), + }] + .try_into() + .unwrap(), + }) + } + + #[test] + fn envelope_view_to_owned() { + let by_ref: TransactionEnvelope = (&ENVELOPE).into(); + let by_value: TransactionEnvelope = ENVELOPE.into(); + assert_eq!(by_ref, owned_envelope()); + assert_eq!(by_value, owned_envelope()); + } + + #[test] + fn scval_view_to_owned() { + let owned: ScVal = (&SCVAL).into(); + let expected = ScVal::Vec(Some(ScVec( + vec![ + ScVal::Vec(Some(ScVec( + vec![ + ScVal::I32(1), + ScVal::Symbol(ScSymbol("sym".try_into().unwrap())), + ScVal::Bytes(ScBytes(b"bytes".to_vec().try_into().unwrap())), + ] + .try_into() + .unwrap(), + ))), + ScVal::Bool(true), + ] + .try_into() + .unwrap(), + ))); + assert_eq!(owned, expected); + } + + #[test] + fn claim_predicate_view_to_owned() { + let owned: ClaimPredicate = (&PREDICATE).into(); + let expected = ClaimPredicate::Not(Some(Box::new(ClaimPredicate::And( + vec![ + ClaimPredicate::Unconditional, + ClaimPredicate::BeforeAbsoluteTime(123), + ] + .try_into() + .unwrap(), + )))); + assert_eq!(owned, expected); + } + + #[test] + fn view_types_from_owned_m_types() { + let vecm: VecM = vec![1, 2, 3].try_into().unwrap(); + let vecm_view: VecMView = (&vecm).into(); + assert_eq!(vecm_view.to_vecm(), vecm); + + let bytesm: BytesM<5> = vec![1u8, 2, 3].try_into().unwrap(); + let bytesm_view: BytesMView<5> = (&bytesm).into(); + assert_eq!(bytesm_view.to_bytesm(), bytesm); + + let stringm: StringM<5> = "abc".try_into().unwrap(); + let stringm_view: StringMView<5> = (&stringm).into(); + assert_eq!(stringm_view.to_stringm(), stringm); + } + + #[cfg(feature = "std")] + #[test] + fn envelope_view_xdr_roundtrip() { + use stellar_xdr::{Limits, ReadXdr, WriteXdr}; + let owned: TransactionEnvelope = (&ENVELOPE).into(); + let bytes = owned.to_xdr(Limits::none()).unwrap(); + assert_eq!(bytes, owned_envelope().to_xdr(Limits::none()).unwrap()); + let decoded = TransactionEnvelope::from_xdr(bytes, Limits::none()).unwrap(); + assert_eq!(owned, decoded); + } + + // View types encode directly via WriteXdr, producing bytes identical to + // the owned types'. + #[cfg(feature = "std")] + #[test] + fn view_write_xdr_matches_owned() { + use stellar_xdr::{Limits, WriteXdr}; + assert_eq!( + ENVELOPE.to_xdr(Limits::none()).unwrap(), + owned_envelope().to_xdr(Limits::none()).unwrap() + ); + assert_eq!( + SCVAL.to_xdr(Limits::none()).unwrap(), + ScVal::from(&SCVAL).to_xdr(Limits::none()).unwrap() + ); + assert_eq!( + PREDICATE.to_xdr(Limits::none()).unwrap(), + ClaimPredicate::from(&PREDICATE) + .to_xdr(Limits::none()) + .unwrap() + ); + } +} diff --git a/xdr-generator-rust/generator/header.rs b/xdr-generator-rust/generator/header.rs index 7418b9f6a..12c2a7569 100644 --- a/xdr-generator-rust/generator/header.rs +++ b/xdr-generator-rust/generator/header.rs @@ -426,7 +426,7 @@ impl Iterator for ReadXdrIter { Err(e) => return Some(Err(Error::Io(e))), // If there is data in the buf available for reading, continue. Ok([..]) => (), - }; + } // Read the buf into the type. let r = self.reader.with_limited_depth(|dlr| S::read_xdr(dlr)); match r { @@ -862,6 +862,16 @@ impl WriteXdr for Box { } } +// Gated on alloc because in no-alloc builds `Box` is an alias for +// `&'static T`, and this impl would overlap with the `Box` impl above. +#[cfg(feature = "alloc")] +impl WriteXdr for &T { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + T::write_xdr(self, w) + } +} + impl ReadXdr for () { #[cfg(feature = "std")] fn read_xdr(_r: &mut Limited) -> Result { @@ -1456,6 +1466,178 @@ impl WriteXdr for VecM { } } +// VecMView ------------------------------------------------------------------------ + +/// A borrowing equivalent of [`VecM`] that wraps a slice instead of owning a +/// `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of the generated `View` types from +/// slices of fixed-size arrays, without heap allocation. +#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct VecMView<'a, T, const MAX: u32 = { u32::MAX }>(&'a [T]); + +// Copy and Clone are implemented manually because the derived impls would +// require `T: Copy`/`T: Clone`, and the wrapped `&[T]` is copyable for any +// `T`. +impl Copy for VecMView<'_, T, MAX> {} + +#[allow(clippy::expl_impl_clone_on_copy)] +impl Clone for VecMView<'_, T, MAX> { + fn clone(&self) -> Self { + *self + } +} + +impl Deref for VecMView<'_, T, MAX> { + type Target = [T]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for VecMView<'_, T, MAX> { + fn default() -> Self { + Self(&[]) + } +} + +impl<'a, T, const MAX: u32> VecMView<'a, T, MAX> { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `VecMView` from the given slice. + /// + /// ### Panics + /// + /// Panics if the length of the slice exceeds `MAX`. In a const context + /// the panic occurs at compile time. + #[must_use] + pub const fn new(v: &'a [T]) -> Self { + assert!(v.len() <= Self::MAX_LEN, "length exceeds max"); + Self(v) + } + + /// Constructs a `VecMView` from the given slice, erroring if the length of + /// the slice exceeds `MAX`. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_new(v: &'a [T]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(Error::LengthExceedsMax) + } + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'a [T] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } + + pub fn iter(&self) -> slice::Iter<'a, T> { + self.0.iter() + } +} + +impl<'a, T, const MAX: u32> core::iter::IntoIterator for &VecMView<'a, T, MAX> { + type Item = &'a T; + type IntoIter = slice::Iter<'a, T>; + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +#[cfg(feature = "alloc")] +impl VecMView<'_, T, MAX> { + /// Converts to an owned [`VecM`], cloning the elements. + #[must_use] + pub fn to_vecm(&self) -> VecM { + VecM(self.0.to_vec()) + } +} + +#[cfg(feature = "alloc")] +impl VecMView<'_, T, MAX> { + /// Converts to an owned [`VecM`], converting each element from its + /// borrowing form to its owned form. + #[must_use] + pub fn to_vecm_from(&self) -> VecM + where + U: for<'r> From<&'r T>, + { + VecM(self.0.iter().map(U::from).collect()) + } +} + +impl<'a, T, const MAX: u32> TryFrom<&'a [T]> for VecMView<'a, T, MAX> { + type Error = Error; + + fn try_from(v: &'a [T]) -> Result { + Self::try_new(v) + } +} + +impl<'a, T, const MAX: u32> From<&'a VecM> for VecMView<'a, T, MAX> { + #[must_use] + fn from(v: &'a VecM) -> Self { + Self( as AsRef<[T]>>::as_ref(v)) + } +} + +impl WriteXdr for VecMView<'_, u8, MAX> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?; + len.write_xdr(w)?; + + w.consume_len(self.len())?; + let padding = pad_len(self.len()); + w.consume_len(padding)?; + + w.write_all(self.0)?; + + w.write_all(&[0u8; 3][..padding])?; + + Ok(()) + }) + } +} + +impl WriteXdr for VecMView<'_, T, MAX> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?; + len.write_xdr(w)?; + + for t in self.0 { + t.write_xdr(w)?; + } + + Ok(()) + }) + } +} + // BytesM ------------------------------------------------------------------------ #[cfg(feature = "alloc")] @@ -1860,6 +2042,145 @@ impl WriteXdr for BytesM { } } +// BytesMView ------------------------------------------------------------------------ + +/// A borrowing equivalent of [`BytesM`] that wraps a byte slice instead of +/// owning a `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of the generated `View` types from +/// slices of fixed-size arrays, without heap allocation. +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct BytesMView<'a, const MAX: u32 = { u32::MAX }>(&'a [u8]); + +impl core::fmt::Display for BytesMView<'_, MAX> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + for b in self.0 { + write!(f, "{b:02x}")?; + } + Ok(()) + } +} + +impl core::fmt::Debug for BytesMView<'_, MAX> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "BytesMView(")?; + for b in self.0 { + write!(f, "{b:02x}")?; + } + write!(f, ")")?; + Ok(()) + } +} + +impl Deref for BytesMView<'_, MAX> { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for BytesMView<'_, MAX> { + fn default() -> Self { + Self(&[]) + } +} + +impl<'a, const MAX: u32> BytesMView<'a, MAX> { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `BytesMView` from the given slice. + /// + /// ### Panics + /// + /// Panics if the length of the slice exceeds `MAX`. In a const context + /// the panic occurs at compile time. + #[must_use] + pub const fn new(v: &'a [u8]) -> Self { + assert!(v.len() <= Self::MAX_LEN, "length exceeds max"); + Self(v) + } + + /// Constructs a `BytesMView` from the given slice, erroring if the length + /// of the slice exceeds `MAX`. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_new(v: &'a [u8]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(Error::LengthExceedsMax) + } + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'a [u8] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +#[cfg(feature = "alloc")] +impl BytesMView<'_, MAX> { + /// Converts to an owned [`BytesM`], cloning the bytes. + #[must_use] + pub fn to_bytesm(&self) -> BytesM { + BytesM(self.0.to_vec()) + } +} + +impl<'a, const MAX: u32> TryFrom<&'a [u8]> for BytesMView<'a, MAX> { + type Error = Error; + + fn try_from(v: &'a [u8]) -> Result { + Self::try_new(v) + } +} + +impl<'a, const MAX: u32> From<&'a BytesM> for BytesMView<'a, MAX> { + #[must_use] + fn from(v: &'a BytesM) -> Self { + Self( as AsRef<[u8]>>::as_ref(v)) + } +} + +impl WriteXdr for BytesMView<'_, MAX> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?; + len.write_xdr(w)?; + + w.consume_len(self.len())?; + let padding = pad_len(self.len()); + w.consume_len(padding)?; + + w.write_all(self.0)?; + + w.write_all(&[0u8; 3][..padding])?; + + Ok(()) + }) + } +} + // StringM ------------------------------------------------------------------------ /// A string type that contains arbitrary bytes. @@ -2263,6 +2584,174 @@ impl WriteXdr for StringM { } } +// StringMView ------------------------------------------------------------------------ + +/// A borrowing equivalent of [`StringM`] that wraps a byte slice instead of +/// owning a `Vec`, enforcing the same maximum length `MAX` at construction. +/// +/// Usable in const contexts to build values of the generated `View` types from +/// slices of fixed-size arrays or string literals, without heap allocation. +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct StringMView<'a, const MAX: u32 = { u32::MAX }>(&'a [u8]); + +impl core::fmt::Display for StringMView<'_, MAX> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + for b in escape_bytes::Escape::new(self.0) { + write!(f, "{}", b as char)?; + } + Ok(()) + } +} + +impl core::fmt::Debug for StringMView<'_, MAX> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "StringMView(")?; + for b in escape_bytes::Escape::new(self.0) { + write!(f, "{}", b as char)?; + } + write!(f, ")")?; + Ok(()) + } +} + +impl Deref for StringMView<'_, MAX> { + type Target = [u8]; + + fn deref(&self) -> &Self::Target { + self.0 + } +} + +impl Default for StringMView<'_, MAX> { + fn default() -> Self { + Self(&[]) + } +} + +impl<'a, const MAX: u32> StringMView<'a, MAX> { + pub const MAX_LEN: usize = { MAX as usize }; + + /// Constructs a `StringMView` from the given slice. + /// + /// ### Panics + /// + /// Panics if the length of the slice exceeds `MAX`. In a const context + /// the panic occurs at compile time. + #[must_use] + pub const fn new(v: &'a [u8]) -> Self { + assert!(v.len() <= Self::MAX_LEN, "length exceeds max"); + Self(v) + } + + /// Constructs a `StringMView` from the UTF-8 bytes of the given str. + /// + /// ### Panics + /// + /// Panics if the length of the str exceeds `MAX`. In a const context the + /// panic occurs at compile time. + #[must_use] + pub const fn new_str(s: &'a str) -> Self { + Self::new(s.as_bytes()) + } + + /// Constructs a `StringMView` from the given slice, erroring if the length + /// of the slice exceeds `MAX`. + /// + /// ### Errors + /// + /// If the length of the slice exceeds `MAX`. + pub const fn try_new(v: &'a [u8]) -> Result { + if v.len() <= Self::MAX_LEN { + Ok(Self(v)) + } else { + Err(Error::LengthExceedsMax) + } + } + + /// Constructs a `StringMView` from the UTF-8 bytes of the given str, + /// erroring if the length of the str exceeds `MAX`. + /// + /// ### Errors + /// + /// If the length of the str exceeds `MAX`. + pub const fn try_new_str(s: &'a str) -> Result { + Self::try_new(s.as_bytes()) + } + + #[must_use] + #[allow(clippy::unused_self)] + pub const fn max_len(&self) -> usize { + Self::MAX_LEN + } + + #[must_use] + pub const fn as_slice(&self) -> &'a [u8] { + self.0 + } + + #[must_use] + pub const fn len(&self) -> usize { + self.0.len() + } + + #[must_use] + pub const fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + +#[cfg(feature = "alloc")] +impl StringMView<'_, MAX> { + /// Converts to an owned [`StringM`], cloning the bytes. + #[must_use] + pub fn to_stringm(&self) -> StringM { + StringM(self.0.to_vec()) + } +} + +impl<'a, const MAX: u32> TryFrom<&'a [u8]> for StringMView<'a, MAX> { + type Error = Error; + + fn try_from(v: &'a [u8]) -> Result { + Self::try_new(v) + } +} + +impl<'a, const MAX: u32> TryFrom<&'a str> for StringMView<'a, MAX> { + type Error = Error; + + fn try_from(s: &'a str) -> Result { + Self::try_new_str(s) + } +} + +impl<'a, const MAX: u32> From<&'a StringM> for StringMView<'a, MAX> { + #[must_use] + fn from(v: &'a StringM) -> Self { + Self( as AsRef<[u8]>>::as_ref(v)) + } +} + +impl WriteXdr for StringMView<'_, MAX> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + let len: u32 = self.len().try_into().map_err(|_| Error::LengthExceedsMax)?; + len.write_xdr(w)?; + + w.consume_len(self.len())?; + let padding = pad_len(self.len()); + w.consume_len(padding)?; + + w.write_all(self.0)?; + + w.write_all(&[0u8; 3][..padding])?; + + Ok(()) + }) + } +} + // Frame ------------------------------------------------------------------------ /// Frame wraps an XDR object with the framing defined by the Record Marking diff --git a/xdr-generator-rust/generator/src/generator.rs b/xdr-generator-rust/generator/src/generator.rs index 97dc43e9a..88e86cbb2 100644 --- a/xdr-generator-rust/generator/src/generator.rs +++ b/xdr-generator-rust/generator/src/generator.rs @@ -1,9 +1,9 @@ use std::collections::hash_map::Entry; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use askama::Template; use xdr_parser::ast::{ - Const, Definition, Enum, Struct, StructMember, Typedef, Union, UnionArm, XdrSpec, + CfgExpr, Const, Definition, Enum, Struct, StructMember, Type, Typedef, Union, UnionArm, XdrSpec, }; use xdr_parser::lexer::IntBase; use xdr_parser::types::{is_builtin_type, is_fixed_array, is_fixed_opaque, is_var_array, TypeInfo}; @@ -23,12 +23,45 @@ use crate::types::{base_type_ref, resolve_type, size_to_string, type_ref}; pub struct RustGenerator { options: RustOptions, type_info: TypeInfo, + /// Rust type names of generated types that directly or transitively + /// contain heap-allocated data (`VecM`, `BytesM`, `StringM`, or `Box` for + /// cyclic references) under some cfg, and therefore have a borrowing `View` + /// form generated for them. + view_required: HashSet, + /// Per-definition borrow conditions, keyed by Rust type name and the + /// definition's cfg, which distinguishes same-named `#ifdef`/`#else` + /// branches from one another. + def_borrow: HashMap<(String, Option), BorrowCfg>, } impl RustGenerator { pub fn new(spec: &XdrSpec, options: RustOptions) -> Self { let type_info = TypeInfo::build(spec, &type_name); - Self { options, type_info } + let mut analysis = BorrowAnalysis::build(spec); + let view_required = analysis.view_required(); + let def_borrow = spec + .all_definitions() + .map(|def| { + let key = (type_name(def.name()), def.cfg().map(CfgExpr::render)); + (key, analysis.of_def(def)) + }) + .collect(); + Self { + options, + type_info, + view_required, + def_borrow, + } + } + + /// How to emit the borrowing `View` form of a definition. + fn view_emit_for(&self, name: &str, cfg: Option<&str>) -> ViewEmit { + let borrow = self + .def_borrow + .get(&(name.to_string(), cfg.map(ToString::to_string))) + .copied() + .unwrap_or(BorrowCfg::Never); + view_emit(self.view_required.contains(name), &borrow, cfg) } /// Generate Rust code from the spec and write it to the output file. @@ -264,6 +297,7 @@ impl RustGenerator { } else { "Struct" }; + let r = self.view_emit_for(&name, cfg.as_deref()); StructOutput { name, source_comment: source_comment(&s.source, type_kind), @@ -271,6 +305,8 @@ impl RustGenerator { is_custom_str: custom_str, members, member_names, + emit_view: r.emit_view, + view_cfg: r.view_cfg, cfg, } } @@ -346,6 +382,8 @@ impl RustGenerator { .first() .and_then(|a| a.cfg.as_ref().map(|c| c.render())); + let r = self.view_emit_for(&name, cfg.as_deref()); + UnionOutput { name, source_comment: source_comment(&u.source, type_kind), @@ -353,6 +391,8 @@ impl RustGenerator { is_custom_str: custom_str, discriminant_type, arms, + emit_view: r.emit_view, + view_cfg: r.view_cfg, cfg, default_arm_cfg, } @@ -377,7 +417,15 @@ impl RustGenerator { let is_fixed_array_type = is_fixed_array(&t.type_); let is_var_array_type = is_var_array(&t.type_); - let resolved = resolve_type(&t.type_, None, &self.type_info, custom_str); + let resolved = resolve_type( + &t.type_, + None, + &self.type_info, + custom_str, + &self.view_required, + "v.0", + false, + ); let size = match &t.type_ { xdr_parser::ast::Type::OpaqueFixed(s) @@ -385,8 +433,10 @@ impl RustGenerator { _ => None, }; + let r = self.view_emit_for(&name, cfg.as_deref()); + DefinitionOutput::TypedefNewtype(TypedefNewtypeOutput { - name, + name: name.clone(), source_comment: source_comment(&t.source, "Typedef"), has_default: !custom_default, is_var_array: is_var_array_type, @@ -401,6 +451,10 @@ impl RustGenerator { custom_debug: is_fixed_opaque_type, custom_display_fromstr: is_fixed_opaque_type && !custom_str && !no_display_fromstr, custom_schemars: is_fixed_opaque_type && !custom_str && !no_display_fromstr, + emit_view: r.emit_view, + view_cfg: r.view_cfg, + view_type_ref: resolved.view_type_ref, + from_view_expr: resolved.from_view_expr, cfg, }) } @@ -427,7 +481,15 @@ impl RustGenerator { ) -> StructMemberOutput { let name = field_name(&m.name); let serde_rename = field_json_rename(&m.name); - let resolved = resolve_type(&m.type_, Some(parent), &self.type_info, custom_str); + let resolved = resolve_type( + &m.type_, + Some(parent), + &self.type_info, + custom_str, + &self.view_required, + &format!("v.{name}"), + false, + ); StructMemberOutput { name, @@ -435,6 +497,8 @@ impl RustGenerator { turbofish_type: resolved.turbofish_type, serde_as_type: resolved.serde_as_type, serde_rename, + view_type_ref: resolved.view_type_ref, + from_view_expr: resolved.from_view_expr, } } @@ -457,10 +521,17 @@ impl RustGenerator { discriminant_prefix, ); - let resolved = arm - .type_ - .as_ref() - .map(|t| resolve_type(t, Some(parent), &self.type_info, custom_str)); + let resolved = arm.type_.as_ref().map(|t| { + resolve_type( + t, + Some(parent), + &self.type_info, + custom_str, + &self.view_required, + "value", + true, + ) + }); UnionArmOutput { case_name, @@ -468,6 +539,8 @@ impl RustGenerator { is_void: arm.type_.is_none(), type_ref: resolved.as_ref().map(|r| r.type_ref.clone()), turbofish_type: resolved.as_ref().map(|r| r.turbofish_type.clone()), + view_type_ref: resolved.as_ref().map(|r| r.view_type_ref.clone()), + from_view_expr: resolved.as_ref().map(|r| r.from_view_expr.clone()), serde_as_type: resolved.and_then(|r| r.serde_as_type), cfg: arm.cfg.as_ref().map(|c| c.render()), } @@ -475,3 +548,197 @@ impl RustGenerator { .collect() } } + +// ============================================================================= +// Borrow analysis +// ============================================================================= + +/// Whether a type holds heap-allocated data, and so whether its `View` form +/// would use its `'a` lifetime. +/// +/// The distinction that matters is unconditional: only a type that borrows +/// under every cfg gets a `View` form. One that borrows under some cfgs would +/// need a cfg-gated `View`, which any unconditional container of it would name +/// unconditionally and so reference where it does not exist. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum BorrowCfg { + /// Holds no heap-allocated data under any cfg. + Never, + /// Holds heap-allocated data under every cfg. + Always, + /// Holds heap-allocated data only under some cfgs, because it sits behind a + /// cfg-gated union arm or is reached through a type that does. + Sometimes, +} + +impl BorrowCfg { + fn or(self, other: BorrowCfg) -> BorrowCfg { + match (self, other) { + (BorrowCfg::Always, _) | (_, BorrowCfg::Always) => BorrowCfg::Always, + (BorrowCfg::Never, o) | (o, BorrowCfg::Never) => o, + (BorrowCfg::Sometimes, BorrowCfg::Sometimes) => BorrowCfg::Sometimes, + } + } + + /// Restrict to also require `cfg`, as for a cfg-gated union arm. + fn and_cfg(self, cfg: Option<&str>) -> BorrowCfg { + if cfg.is_none() { + return self; + } + match self { + BorrowCfg::Never => BorrowCfg::Never, + BorrowCfg::Always | BorrowCfg::Sometimes => BorrowCfg::Sometimes, + } + } +} + +/// Borrow analysis over a whole spec, resolving type references by name. +struct BorrowAnalysis<'a> { + defs_by_name: HashMap>, + /// Memoized per-name results, keyed by Rust type name. + by_name: HashMap, + /// Names currently being resolved, for cycle detection. + stack: HashSet, +} + +impl<'a> BorrowAnalysis<'a> { + fn build(spec: &'a XdrSpec) -> Self { + let mut defs_by_name: HashMap> = HashMap::new(); + for def in spec.all_definitions() { + defs_by_name + .entry(type_name(def.name())) + .or_default() + .push(def); + } + let mut analysis = Self { + defs_by_name, + by_name: HashMap::new(), + stack: HashSet::new(), + }; + let names: Vec = analysis.defs_by_name.keys().cloned().collect(); + for name in names { + analysis.of_name(&name); + } + analysis + } + + /// The names that get a `View` form, i.e. that borrow under every cfg. + /// + /// A name that only borrows under some cfgs is excluded. Its `View` form + /// would have to be cfg-gated, and an always-borrowing type containing it + /// names that form unconditionally, so the reference would dangle wherever + /// the cfg is off. Excluding it leaves containers holding the owned type in + /// that position, which is correct under every cfg. + fn view_required(&self) -> HashSet { + self.by_name + .iter() + .filter(|(_, b)| **b == BorrowCfg::Always) + .map(|(n, _)| n.clone()) + .collect() + } + + /// The borrow condition for a name, across all of its cfg branches. + /// + /// A name already on the stack indicates a reference cycle. Valid XDR + /// breaks cycles with optional or variable-length types, both of which the + /// generator maps to heap allocations (`Box` or `VecM`), so a type on a + /// cycle always borrows. + fn of_name(&mut self, name: &str) -> BorrowCfg { + if let Some(b) = self.by_name.get(name) { + return *b; + } + if self.stack.contains(name) { + return BorrowCfg::Always; + } + let Some(defs) = self.defs_by_name.get(name).cloned() else { + return BorrowCfg::Never; + }; + self.stack.insert(name.to_string()); + let mut borrow = BorrowCfg::Never; + for def in defs { + let def_cfg = def.cfg().map(CfgExpr::render); + borrow = borrow.or(self.of_def(def).and_cfg(def_cfg.as_deref())); + } + self.stack.remove(name); + self.by_name.insert(name.to_string(), borrow); + borrow + } + + /// The borrow condition contributed by a single definition, excluding the + /// definition's own cfg, which callers apply where the type is emitted. + fn of_def(&mut self, def: &Definition) -> BorrowCfg { + let def_cfg = def.cfg().map(CfgExpr::render); + match def { + Definition::Struct(s) => s + .members + .iter() + .fold(BorrowCfg::Never, |acc, m| acc.or(self.of_type(&m.type_))), + Definition::Union(u) => u.arms.iter().fold(BorrowCfg::Never, |acc, arm| { + let Some(t) = arm.type_.as_ref() else { + return acc; + }; + // An arm cfg equal to the definition's own cfg adds no further + // condition, since the definition is already gated on it. + let arm_cfg = arm + .cfg + .as_ref() + .map(CfgExpr::render) + .filter(|c| Some(c) != def_cfg.as_ref()); + acc.or(self.of_type(t).and_cfg(arm_cfg.as_deref())) + }), + Definition::Typedef(t) => self.of_type(&t.type_), + Definition::Enum(_) | Definition::Const(_) => BorrowCfg::Never, + } + } + + fn of_type(&mut self, type_: &Type) -> BorrowCfg { + match type_ { + Type::OpaqueVar(_) | Type::String(_) | Type::VarArray { .. } => BorrowCfg::Always, + Type::Int + | Type::UnsignedInt + | Type::Hyper + | Type::UnsignedHyper + | Type::Float + | Type::Double + | Type::Bool + | Type::OpaqueFixed(_) => BorrowCfg::Never, + Type::Ident(name) => self.of_name(&type_name(name)), + Type::Optional(inner) => self.of_type(inner), + Type::Array { element_type, .. } => self.of_type(element_type), + } + } +} + +/// How a definition's borrowing `View` form is emitted. +/// +/// A `{name}View<'a>` is emitted only where the definition borrows, so its `'a` +/// is always used. Where it does not borrow, nothing is emitted: the owned type +/// is already the whole value, and a heap-free type has nothing to borrow. +struct ViewEmit { + emit_view: bool, + view_cfg: Option, +} + +/// Decide how to emit the `View` form of one definition. +/// +/// `has_view` is whether the type's name has a `View` form at all, and `borrow` +/// is this definition's borrow condition excluding its own `def_cfg`. +fn view_emit(has_view: bool, borrow: &BorrowCfg, def_cfg: Option<&str>) -> ViewEmit { + let mut emit = ViewEmit { + emit_view: false, + view_cfg: None, + }; + if !has_view { + return emit; + } + match borrow { + // Nothing to borrow in this branch, or nothing to borrow under some + // cfg. Either way this definition emits no View form. + BorrowCfg::Never | BorrowCfg::Sometimes => {} + BorrowCfg::Always => { + emit.emit_view = true; + emit.view_cfg = def_cfg.map(ToString::to_string); + } + } + emit +} diff --git a/xdr-generator-rust/generator/src/output.rs b/xdr-generator-rust/generator/src/output.rs index e9fccad8f..6b585f560 100644 --- a/xdr-generator-rust/generator/src/output.rs +++ b/xdr-generator-rust/generator/src/output.rs @@ -50,6 +50,10 @@ pub struct StructOutput { pub is_custom_str: bool, pub members: Vec, pub member_names: String, + /// True when this definition borrows and gets a real `{name}View<'a>`. + pub emit_view: bool, + /// The full cfg for the real `View` struct, gating it to where it borrows. + pub view_cfg: Option, pub cfg: Option, } @@ -61,6 +65,10 @@ pub struct StructMemberOutput { /// The correct SEP-51 JSON key when the Rust field name was keyword-escaped /// (e.g. `type_` -> JSON `type`). `None` when the name was not escaped. pub serde_rename: Option, + /// The member's type in the borrowing `View` form of the parent type. + pub view_type_ref: String, + /// Expression converting the member from `View` form to owned form. + pub from_view_expr: String, } pub struct EnumOutput { @@ -86,6 +94,12 @@ pub struct UnionOutput { pub is_custom_str: bool, pub discriminant_type: String, pub arms: Vec, + /// True when a real `{name}View<'a>` enum is emitted, i.e. some arm borrows. + pub emit_view: bool, + /// The full cfg for the real `View` enum. When every borrowing arm is behind + /// a cfg, this is the union's cfg combined with the disjunction of those + /// arm cfgs, so the enum only exists where its lifetime is actually used. + pub view_cfg: Option, pub cfg: Option, /// Cfg for the first arm, used to gate the Default impl when the /// default variant is behind a cfg. @@ -99,6 +113,11 @@ pub struct UnionArmOutput { pub type_ref: Option, pub turbofish_type: Option, pub serde_as_type: Option, + /// The arm's payload type in the borrowing `View` form of the parent type. + pub view_type_ref: Option, + /// Expression converting the payload from `View` form to owned form, with + /// the payload bound by reference to `value`. + pub from_view_expr: Option, pub cfg: Option, } @@ -125,6 +144,14 @@ pub struct TypedefNewtypeOutput { pub custom_debug: bool, pub custom_display_fromstr: bool, pub custom_schemars: bool, + /// True when this definition borrows and gets a real `{name}View<'a>`. + pub emit_view: bool, + /// The full cfg for the real `View` newtype, gating it to where it borrows. + pub view_cfg: Option, + /// The inner type in the borrowing `View` form of the newtype. + pub view_type_ref: String, + /// Expression converting the inner value from `View` form to owned form. + pub from_view_expr: String, pub cfg: Option, } diff --git a/xdr-generator-rust/generator/src/tests/generator.rs b/xdr-generator-rust/generator/src/tests/generator.rs index 5adb734b0..cafce71c4 100644 --- a/xdr-generator-rust/generator/src/tests/generator.rs +++ b/xdr-generator-rust/generator/src/tests/generator.rs @@ -23,6 +23,13 @@ fn assert_contains(output: &str, expected: &str) { ); } +fn assert_not_contains(output: &str, unexpected: &str) { + assert!( + !output.contains(unexpected), + "expected output not to contain:\n{unexpected}\n\nfull output:\n{output}" + ); +} + #[test] fn test_ifdef_generates_cfg_on_struct() { let output = generate_from_xdr( @@ -208,3 +215,111 @@ fn test_ifdef_generates_cfg_on_const() { pub const MAX_SIZE: u64 = 100;"#, ); } + +#[test] +fn test_no_view_form_when_only_one_ifdef_branch_borrows() { + // Foo holds heap data only in the FEATURE_X branch, so it borrows under + // some cfgs but not all. A cfg-gated FooView would be named unconditionally + // by any always-borrowing type holding a Foo, so no View form is emitted. + let output = generate_from_xdr( + r#" + #ifdef FEATURE_X + struct Foo { string s<10>; }; + #else + struct Foo { int y; }; + #endif + "#, + ); + assert_not_contains(&output, "FooView"); +} + +#[test] +fn test_no_view_form_when_only_one_ifdef_branch_borrows_typedef() { + let output = generate_from_xdr( + r#" + #ifdef FEATURE_X + typedef string Foo<10>; + #else + typedef opaque Foo[4]; + #endif + "#, + ); + assert_not_contains(&output, "FooView"); +} + +#[test] +fn test_no_view_form_when_only_one_ifdef_branch_borrows_union() { + let output = generate_from_xdr( + r#" + #ifdef FEATURE_X + union Foo switch (int v) { case 0: string s<10>; }; + #else + union Foo switch (int v) { case 0: int y; }; + #endif + "#, + ); + assert_not_contains(&output, "FooView"); +} + +#[test] +fn test_no_view_form_when_only_a_cfg_gated_arm_borrows() { + // The union's only heap sits behind a cfg-gated arm, so it borrows under + // some cfgs but not all and gets no View form. + let output = generate_from_xdr( + r#" + union Foo switch (int v) { + case 0: int y; + #ifdef FEATURE_X + case 1: string s<10>; + #endif + }; + "#, + ); + assert_not_contains(&output, "FooView"); +} + +#[test] +fn test_cfg_conditional_heap_leaves_containing_types_owned() { + // Exec borrows only via its cfg-gated arm, so neither it nor OnlyExec — + // whose sole heap comes from Exec — gets a View form. Parent has heap of + // its own, so it does, and holds the owned Exec in that position. That + // compiles whether or not the feature is on, which a cfg-gated ExecView + // named by the unconditional ParentView would not. + let output = generate_from_xdr( + r#" + union Exec switch (int type) + { + case 0: + void; + #ifdef FEATURE_X + case 1: + string tag<64>; + #endif + }; + struct OnlyExec { Exec exec; int n; }; + struct Parent { Exec exec; string label<32>; }; + "#, + ); + assert_not_contains(&output, "ExecView"); + assert_not_contains(&output, "OnlyExecView"); + assert_contains( + &output, + r#"#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct ParentView<'a> { + pub exec: Exec, + pub label: StringMView<'a, 32>, +}"#, + ); +} + +#[test] +fn test_no_view_form_for_heap_free_types() { + // A type with no heap under any cfg gets no View form at all, since there + // is nothing for it to borrow. + let output = generate_from_xdr( + r#" + struct Flat { int a; opaque b[4]; }; + "#, + ); + assert_not_contains(&output, "FlatView"); +} diff --git a/xdr-generator-rust/generator/src/types.rs b/xdr-generator-rust/generator/src/types.rs index 9433da290..0317e8e16 100644 --- a/xdr-generator-rust/generator/src/types.rs +++ b/xdr-generator-rust/generator/src/types.rs @@ -1,4 +1,6 @@ -use xdr_parser::ast::{Size, Type}; +use std::collections::HashSet; + +use xdr_parser::ast::{Definition, Size, Type}; use xdr_parser::types::TypeInfo; use crate::naming::type_name; @@ -9,16 +11,30 @@ pub struct ResolvedType { pub turbofish_type: String, pub serde_as_type: Option, pub element_type: String, + /// The Rust type used in the borrowing `View` variant of the containing + /// type, e.g. `VecMView<'a, OperationView<'a>, 100>` for `VecM`. + pub view_type_ref: String, + /// An expression converting `access` (a place expression of the + /// `view_type_ref` type) into the owned `type_ref` type. + pub from_view_expr: String, } /// Resolve all Rust type information for an XDR type in one call. /// /// When `custom_str` is true, `serde_as_type` is forced to `None`. +/// +/// `view_required` is the set of Rust type names that have a borrowing `View` +/// variant. `access` is the place expression used to build `from_view_expr`, +/// and `access_is_ref` is true when `access` is a reference to the value (a +/// `match` binding) rather than a place of it. pub(crate) fn resolve_type( type_: &Type, parent: Option<&str>, type_info: &TypeInfo, custom_str: bool, + view_required: &HashSet, + access: &str, + access_is_ref: bool, ) -> ResolvedType { let m = TypeMapping::new(type_, Some(type_info), parent); ResolvedType { @@ -26,6 +42,8 @@ pub(crate) fn resolve_type( turbofish_type: m.turbofish_type(), serde_as_type: if custom_str { None } else { m.serde_as_type() }, element_type: m.element_type(), + view_type_ref: m.view_type_ref(view_required), + from_view_expr: m.from_view_expr(view_required, access, access_is_ref), } } @@ -168,6 +186,236 @@ impl<'a> TypeMapping<'a> { } } + /// The Rust type used for this XDR type in a borrowing `View` type, + /// without the reference wrapping applied for cyclic types. + /// + /// Mirrors `base_type_ref`, mapping heap-owning types to their borrowing + /// equivalents: `VecM` to `VecMView`, `BytesM` to `BytesMView`, `StringM` to + /// `StringMView`, and idents of types with a `View` variant to that variant. + fn view_base_type_ref(&self, view_required: &HashSet) -> String { + match self.type_ { + Type::Int + | Type::UnsignedInt + | Type::Hyper + | Type::UnsignedHyper + | Type::Float + | Type::Double + | Type::Bool + | Type::OpaqueFixed(_) => self.base_type_ref(), + Type::OpaqueVar(max) => match max { + Some(size) => format!("BytesMView<'a, {}>", self.resolve_size(size)), + None => "BytesMView<'a>".to_string(), + }, + Type::String(max) => match max { + Some(size) => format!("StringMView<'a, {}>", self.resolve_size(size)), + None => "StringMView<'a>".to_string(), + }, + Type::Ident(_) => { + if let Some(ti) = self.type_info { + if let Some(builtin) = ti.resolve_typedef_to_builtin(self.type_) { + return self.child(builtin).view_base_type_ref(view_required); + } + } + if let Type::Ident(name) = self.type_ { + let name = type_name(name); + if view_required.contains(&name) { + format!("{name}View<'a>") + } else { + name + } + } else { + unreachable!() + } + } + Type::Optional(inner) => { + format!( + "Option<{}>", + self.child(inner).view_base_type_ref(view_required) + ) + } + Type::Array { element_type, size } => { + format!( + "[{}; {}]", + self.child(element_type).view_base_type_ref(view_required), + self.resolve_size(size) + ) + } + Type::VarArray { + element_type, + max_size, + } => { + let elem = self.child(element_type).view_base_type_ref(view_required); + match max_size { + Some(size) => format!("VecMView<'a, {elem}, {}>", self.resolve_size(size)), + None => format!("VecMView<'a, {elem}>"), + } + } + } + } + + /// The Rust type used for this XDR type in a borrowing `View` type. + /// + /// Mirrors `type_ref`: where the owned type wraps cyclic references in + /// `Box`, the `View` type uses a plain reference instead. + fn view_type_ref(&self, view_required: &HashSet) -> String { + let base = self.view_base_type_ref(view_required); + + if !self.is_cyclic() { + return base; + } + + match self.type_ { + Type::Optional(inner) => { + let inner_ref = self.child(inner).view_base_type_ref(view_required); + format!("Option<&'a {inner_ref}>") + } + Type::Array { .. } | Type::VarArray { .. } => base, + _ => format!("&'a {base}"), + } + } + + /// Whether the `View` mapping of this type borrows data (uses the `'a` + /// lifetime) rather than being the same owned type. + fn view_borrows(&self, view_required: &HashSet) -> bool { + self.view_type_ref(view_required).contains("'a") + } + + /// Whether the owned Rust form of this type is `Copy`. + /// + /// Builtins and fixed opaques are `Copy`, as are generated enums, options + /// and fixed arrays of `Copy` types, and typedef aliases of builtins. + /// Generated structs, unions, and typedef newtypes derive `Clone` but not + /// `Copy`. + fn is_copy(&self) -> bool { + if self.is_cyclic() { + // Wrapped in `Box` in the owned form. + return false; + } + match self.type_ { + Type::Int + | Type::UnsignedInt + | Type::Hyper + | Type::UnsignedHyper + | Type::Float + | Type::Double + | Type::Bool + | Type::OpaqueFixed(_) => true, + Type::OpaqueVar(_) | Type::String(_) | Type::VarArray { .. } => false, + Type::Optional(inner) => self.child(inner).is_copy(), + Type::Array { element_type, .. } => self.child(element_type).is_copy(), + Type::Ident(name) => { + if let Some(ti) = self.type_info { + if ti.resolve_typedef_to_builtin(self.type_).is_some() { + return true; + } + matches!( + ti.definitions.get(&type_name(name)), + Some(Definition::Enum(_)) + ) + } else { + false + } + } + } + } + + /// The expression for reading a `Copy` value out of `access`. + fn copy_expr(access: &str, access_is_ref: bool) -> String { + if access_is_ref { + format!("*{access}") + } else { + access.to_string() + } + } + + /// An expression converting `access` (a place expression of this type's + /// `view_type_ref` form) into the owned `type_ref` form. + /// + /// When `access_is_ref` is true, `access` is a reference to the `Ref` + /// form (a `match` binding) rather than a place of it. + fn from_view_expr( + &self, + view_required: &HashSet, + access: &str, + access_is_ref: bool, + ) -> String { + let cyclic = self.is_cyclic(); + match self.type_ { + Type::Int + | Type::UnsignedInt + | Type::Hyper + | Type::UnsignedHyper + | Type::Float + | Type::Double + | Type::Bool + | Type::OpaqueFixed(_) => Self::copy_expr(access, access_is_ref), + Type::OpaqueVar(_) => format!("{access}.to_bytesm()"), + Type::String(_) => format!("{access}.to_stringm()"), + Type::VarArray { element_type, .. } => { + if self.child(element_type).view_borrows(view_required) { + format!("{access}.to_vecm_from()") + } else { + format!("{access}.to_vecm()") + } + } + Type::Ident(_) => { + if let Some(ti) = self.type_info { + if let Some(builtin) = ti.resolve_typedef_to_builtin(self.type_) { + return self.child(builtin).from_view_expr( + view_required, + access, + access_is_ref, + ); + } + } + if let Type::Ident(name) = self.type_ { + let name = type_name(name); + if cyclic { + // View form is `&'a {name}View<'a>`, owned form is `Box<{name}>`. + if access_is_ref { + format!("Box::new((*{access}).into())") + } else { + format!("Box::new({access}.into())") + } + } else if view_required.contains(&name) { + if access_is_ref { + format!("{access}.into()") + } else { + format!("(&{access}).into()") + } + } else if self.is_copy() { + Self::copy_expr(access, access_is_ref) + } else { + format!("{access}.clone()") + } + } else { + unreachable!() + } + } + Type::Optional(inner) => { + if cyclic { + // View form is `Option<&'a TView<'a>>`, owned form is `Option>`. + format!("{access}.map(|v| Box::new(v.into()))") + } else if self.child(inner).view_borrows(view_required) { + format!("{access}.as_ref().map(Into::into)") + } else if self.is_copy() { + Self::copy_expr(access, access_is_ref) + } else { + format!("{access}.clone()") + } + } + Type::Array { element_type, .. } => { + if self.child(element_type).view_borrows(view_required) { + format!("core::array::from_fn(|i| (&{access}[i]).into())") + } else if self.is_copy() { + Self::copy_expr(access, access_is_ref) + } else { + format!("{access}.clone()") + } + } + } + } + fn turbofish_type(&self) -> String { let cyclic = self.is_cyclic(); diff --git a/xdr-generator-rust/generator/templates/struct.rs.jinja b/xdr-generator-rust/generator/templates/struct.rs.jinja index af139b438..30fd8a2ac 100644 --- a/xdr-generator-rust/generator/templates/struct.rs.jinja +++ b/xdr-generator-rust/generator/templates/struct.rs.jinja @@ -104,4 +104,59 @@ impl<'de> serde::Deserialize<'de> for {{ s.name }} { } } {%- endif %} +{%- if s.emit_view %} + +/// {{ s.name }}View is a borrowing equivalent of [`{{ s.name }}`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +{%- if let Some(cfg) = s.view_cfg %} +#[cfg({{ cfg }})] +{%- endif %} +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct {{ s.name }}View<'a> { +{%- for m in s.members %} + pub {{ m.name }}: {{ m.view_type_ref }}, +{%- endfor %} +} + +{% if let Some(cfg) = s.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +#[cfg(feature = "alloc")] +impl From<&{{ s.name }}View<'_>> for {{ s.name }} { + #[must_use] + fn from(v: &{{ s.name }}View<'_>) -> Self { + Self { +{%- for m in s.members %} + {{ m.name }}: {{ m.from_view_expr }}, +{%- endfor %} + } + } +} + +{% if let Some(cfg) = s.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +#[cfg(feature = "alloc")] +impl From<{{ s.name }}View<'_>> for {{ s.name }} { + #[must_use] + fn from(v: {{ s.name }}View<'_>) -> Self { + Self::from(&v) + } +} + +{% if let Some(cfg) = s.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +impl WriteXdr for {{ s.name }}View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { +{%- for m in s.members %} + self.{{ m.name }}.write_xdr(w)?; +{%- endfor %} + Ok(()) + }) + } +} +{%- endif %} diff --git a/xdr-generator-rust/generator/templates/typedef_newtype.rs.jinja b/xdr-generator-rust/generator/templates/typedef_newtype.rs.jinja index 39d0fd268..5bf7eea0d 100644 --- a/xdr-generator-rust/generator/templates/typedef_newtype.rs.jinja +++ b/xdr-generator-rust/generator/templates/typedef_newtype.rs.jinja @@ -296,4 +296,46 @@ impl AsRef<[{{ t.element_type }}]> for {{ t.name }} { } } {%- endif %} +{%- if t.emit_view %} + +/// {{ t.name }}View is a borrowing equivalent of [`{{ t.name }}`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +{%- if let Some(cfg) = t.view_cfg %} +#[cfg({{ cfg }})] +{%- endif %} +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct {{ t.name }}View<'a>(pub {{ t.view_type_ref }}); + +{% if let Some(cfg) = t.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +#[cfg(feature = "alloc")] +impl From<&{{ t.name }}View<'_>> for {{ t.name }} { + #[must_use] + fn from(v: &{{ t.name }}View<'_>) -> Self { + Self({{ t.from_view_expr }}) + } +} + +{% if let Some(cfg) = t.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +#[cfg(feature = "alloc")] +impl From<{{ t.name }}View<'_>> for {{ t.name }} { + #[must_use] + fn from(v: {{ t.name }}View<'_>) -> Self { + Self::from(&v) + } +} + +{% if let Some(cfg) = t.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +impl WriteXdr for {{ t.name }}View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| self.0.write_xdr(w)) + } +} +{%- endif %} diff --git a/xdr-generator-rust/generator/templates/union.rs.jinja b/xdr-generator-rust/generator/templates/union.rs.jinja index 115250cb1..b95015142 100644 --- a/xdr-generator-rust/generator/templates/union.rs.jinja +++ b/xdr-generator-rust/generator/templates/union.rs.jinja @@ -226,4 +226,108 @@ impl WriteXdr for {{ u.name }} { }) } } +{%- if u.emit_view %} + +/// {{ u.name }}View is a borrowing equivalent of [`{{ u.name }}`], usable in +/// const contexts and convertible to the owned type via [`From`]/[`Into`]. +{%- if let Some(cfg) = u.view_cfg %} +#[cfg({{ cfg }})] +{%- endif %} +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[allow(clippy::large_enum_variant)] +pub enum {{ u.name }}View<'a> { +{%- for arm in u.arms %} +{%- if let Some(cfg) = arm.cfg %} + #[cfg({{ cfg }})] +{%- endif %} +{%- if arm.is_void %} + {{ arm.case_name }}, +{%- else %} + {{ arm.case_name }}({{ arm.view_type_ref.as_ref().unwrap() }}), +{%- endif %} +{%- endfor %} +} + +{% if let Some(cfg) = u.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +#[cfg(feature = "alloc")] +impl From<&{{ u.name }}View<'_>> for {{ u.name }} { + #[must_use] + fn from(v: &{{ u.name }}View<'_>) -> Self { + #[allow(clippy::match_same_arms)] + match v { +{%- for arm in u.arms %} +{%- if let Some(cfg) = arm.cfg %} + #[cfg({{ cfg }})] +{%- endif %} +{%- if arm.is_void %} + {{ u.name }}View::{{ arm.case_name }} => Self::{{ arm.case_name }}, +{%- else %} + {{ u.name }}View::{{ arm.case_name }}(value) => Self::{{ arm.case_name }}({{ arm.from_view_expr.as_ref().unwrap() }}), +{%- endif %} +{%- endfor %} + } + } +} + +{% if let Some(cfg) = u.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +#[cfg(feature = "alloc")] +impl From<{{ u.name }}View<'_>> for {{ u.name }} { + #[must_use] + fn from(v: {{ u.name }}View<'_>) -> Self { + Self::from(&v) + } +} + +{% if let Some(cfg) = u.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +impl {{ u.name }}View<'_> { + #[must_use] + pub const fn discriminant(&self) -> {{ u.discriminant_type }} { + #[allow(clippy::match_same_arms)] + match self { +{%- for arm in u.arms %} +{%- if let Some(cfg) = arm.cfg %} + #[cfg({{ cfg }})] +{%- endif %} +{%- if arm.is_void %} + Self::{{ arm.case_name }} => {{ arm.case_value }}, +{%- else %} + Self::{{ arm.case_name }}(_) => {{ arm.case_value }}, +{%- endif %} +{%- endfor %} + } + } +} + +{% if let Some(cfg) = u.view_cfg -%} +#[cfg({{ cfg }})] +{% endif -%} +impl WriteXdr for {{ u.name }}View<'_> { + #[cfg(feature = "std")] + fn write_xdr(&self, w: &mut Limited) -> Result<(), Error> { + w.with_limited_depth(|w| { + self.discriminant().write_xdr(w)?; + #[allow(clippy::match_same_arms)] + match self { +{%- for arm in u.arms %} +{%- if let Some(cfg) = arm.cfg %} + #[cfg({{ cfg }})] +{%- endif %} +{%- if arm.is_void %} + Self::{{ arm.case_name }} => ().write_xdr(w)?, +{%- else %} + Self::{{ arm.case_name }}(v) => v.write_xdr(w)?, +{%- endif %} +{%- endfor %} + }; + Ok(()) + }) + } +} +{%- endif %}