Skip to content

Commit

Permalink
tweak: Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Nov 9, 2024
1 parent b9ef857 commit 05c723e
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::*;
#[must_use]
pub struct ManifestAddressReservation(pub u32);

labelled_resolvable_with_self_impl!(ManifestAddressReservation, resolver_output: Self);
labelled_resolvable_with_identity_impl!(ManifestAddressReservation, resolver_output: Self);

//========
// error
Expand Down
2 changes: 1 addition & 1 deletion radix-common/src/data/manifest/model/manifest_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::*;
#[must_use]
pub struct ManifestBucket(pub u32);

labelled_resolvable_with_self_impl!(ManifestBucket, resolver_output: Self);
labelled_resolvable_with_identity_impl!(ManifestBucket, resolver_output: Self);

//========
// error
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/data/manifest/model/manifest_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum ManifestBucketBatch {
EntireWorktop,
}

labelled_resolvable_with_self_impl!(ManifestBucketBatch, resolver_output: ManifestBucket);
labelled_resolvable_with_identity_impl!(ManifestBucketBatch, resolver_output: ManifestBucket);

impl<T: LabelledResolve<Vec<ManifestBucket>>> LabelledResolveFrom<T> for ManifestBucketBatch {
fn labelled_resolve_from(
Expand Down Expand Up @@ -128,7 +128,7 @@ pub enum ManifestProofBatch {
EntireAuthZone,
}

labelled_resolvable_with_self_impl!(ManifestProofBatch, resolver_output: ManifestProof);
labelled_resolvable_with_identity_impl!(ManifestProofBatch, resolver_output: ManifestProof);

impl<T: LabelledResolve<Vec<ManifestProof>>> LabelledResolveFrom<T> for ManifestProofBatch {
fn labelled_resolve_from(
Expand Down
2 changes: 1 addition & 1 deletion radix-common/src/data/manifest/model/manifest_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::*;
#[must_use]
pub struct ManifestProof(pub u32);

labelled_resolvable_with_self_impl!(ManifestProof, resolver_output: Self);
labelled_resolvable_with_identity_impl!(ManifestProof, resolver_output: Self);

//========
// error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,15 +1103,15 @@ pub enum BoundAdjustmentError {
TakeCannotBeSatisfied,
}

resolvable_with_self_impl!(LowerBound);
resolvable_with_identity_impl!(LowerBound);

impl<T: Resolve<Decimal>> ResolveFrom<T> for LowerBound {
fn resolve_from(value: T) -> Self {
LowerBound::Inclusive(value.resolve())
}
}

resolvable_with_self_impl!(UpperBound);
resolvable_with_identity_impl!(UpperBound);

impl<T: Resolve<Decimal>> ResolveFrom<T> for UpperBound {
fn resolve_from(value: T) -> Self {
Expand Down
5 changes: 2 additions & 3 deletions radix-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ pub mod prelude {
pub use crate::contextual_try_from_into::*;
pub use crate::resolve::*;
pub use crate::{
labelled_resolvable_using_resolvable_impl, labelled_resolvable_with_self_impl,
labelled_resolvable_with_try_into_impls, resolvable_with_self_impl,
resolvable_with_try_into_impls,
labelled_resolvable_using_resolvable_impl, labelled_resolvable_with_identity_impl,
resolvable_with_identity_impl, resolvable_with_try_into_impls,
};

pub use crate::iterators::*;
Expand Down
49 changes: 18 additions & 31 deletions radix-rust/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ impl<X, Y: ResolveFrom<X>> Resolve<Y> for X {
/// `Resolvable` is a marker trait, mainly to make resolution opt-in and to avoid
/// polluting every type with a resolve method.
///
/// You might want to use [`resolvable_with_self_impl`] or [`resolvable_with_try_into_impls`]
/// You might want to use [`resolvable_with_identity_impl`] or [`resolvable_with_try_into_impls`]
/// to implement this trait and a reflexive or blanket impl.
pub trait Resolvable {}

#[macro_export]
macro_rules! resolvable_with_self_impl {
macro_rules! resolvable_with_identity_impl {
($ty:ty$(,)?) => {
impl Resolvable for $ty {}

Expand Down Expand Up @@ -132,7 +132,7 @@ impl<X, Y: LabelledResolveFrom<X>> LabelledResolve<Y> for X {
/// which don't have that bound).
///
/// If implementing this with [`ResolverOutput`] = `Self`, you will likely want to
/// use [`labelled_resolvable_with_self_impl`] or [`labelled_resolvable_with_try_into_impls`]
/// use [`labelled_resolvable_with_identity_impl`] or [`labelled_resolvable_with_try_into_impls`]
/// to implement this trait and a reflexive or blanket impl using `try_into`.
///
/// [`ResolverOutput`]: LabelledResolvable::ResolverOutput
Expand All @@ -148,25 +148,7 @@ pub trait LabelResolver<X> {
}

#[macro_export]
macro_rules! labelled_resolvable_using_resolvable_impl {
($ty:ty, resolver_output: $resolver_output:ty$(,)?) => {
impl LabelledResolvable for $ty {
type ResolverOutput = $resolver_output;
}

impl<T: Resolve<Self>> LabelledResolveFrom<T> for $ty {
fn labelled_resolve_from(
value: T,
_resolver: &impl LabelResolver<$resolver_output>,
) -> Self {
value.resolve()
}
}
};
}

#[macro_export]
macro_rules! labelled_resolvable_with_self_impl {
macro_rules! labelled_resolvable_with_identity_impl {
($ty:ty, resolver_output: $resolver_output:ty$(,)?) => {
impl LabelledResolvable for $ty {
type ResolverOutput = $resolver_output;
Expand All @@ -180,27 +162,25 @@ macro_rules! labelled_resolvable_with_self_impl {
value
}
}

// In future, could likely add an implementation from &$ty if $ty is Clone;
// if we can get around the "trivially true/false" bound.
};
}

#[macro_export]
macro_rules! labelled_resolvable_with_try_into_impls {
macro_rules! labelled_resolvable_using_resolvable_impl {
($ty:ty, resolver_output: $resolver_output:ty$(,)?) => {
impl LabelledResolvable for $ty {
type ResolverOutput = $resolver_output;
}

impl<T: TryInto<$ty, Error = E>, E: Debug> LabelledResolveFrom<T> for $ty {
impl<T: Resolve<Self>> LabelledResolveFrom<T> for $ty {
fn labelled_resolve_from(
value: T,
_resolver: &impl LabelResolver<$resolver_output>,
) -> Self {
value.try_into().unwrap_or_else(|err| {
panic!(
"The provided argument could not be resolved into a {}: {err:?}",
core::any::type_name::<$ty>()
)
})
value.resolve()
}
}
};
Expand All @@ -209,11 +189,18 @@ macro_rules! labelled_resolvable_with_try_into_impls {
//==============================================================
// If a type `X` has `ResolverOutput = Self` then it's a "leaf" - i.e. the thing
// that's ultimately being resolved.
// * We leave an identity resolver or try_into resolver for the macros `labelled_resolvable_with_self_impl`
// * We leave an identity resolver or try_into resolver for the macros `labelled_resolvable_with_identity_impl`
// or `labelled_resolvable_with_try_into_impls` or `labelled_resolvable_using_resolvable_impl`
// * Implement resolves form string-based labels
//==============================================================

// Ideally we'd be able to allow `ResolverOutput = TryInfo<X>`, but the
// compiler disallows this, due to clashes with other blanket implementations.
// For example, it might be possible in future for e.g. &'a str to implement
// `IntoIterator<Item = A>` (e.g. A = &'a char) and for `A` to implement
// `Resolve<X>` and so give clashing implementations of
// LabelledResolveFrom<&'a str> for Vec<char>.

impl<'a, X: LabelledResolvable<ResolverOutput = X>> LabelledResolveFrom<&'a str> for X {
fn labelled_resolve_from(value: &'a str, resolver: &impl LabelResolver<X>) -> X {
resolver.resolve_label_into(value)
Expand Down
10 changes: 5 additions & 5 deletions radix-transactions/src/builder/manifest_namer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ pub struct NamedManifestBucket {
name: String,
}

labelled_resolvable_with_self_impl!(NamedManifestBucket, resolver_output: Self);
labelled_resolvable_with_identity_impl!(NamedManifestBucket, resolver_output: Self);

impl LabelResolver<NamedManifestBucket> for ManifestNameRegistrar {
fn resolve_label_into(&self, name: &str) -> NamedManifestBucket {
Expand Down Expand Up @@ -704,7 +704,7 @@ pub struct NamedManifestProof {
name: String,
}

labelled_resolvable_with_self_impl!(NamedManifestProof, resolver_output: Self);
labelled_resolvable_with_identity_impl!(NamedManifestProof, resolver_output: Self);

impl LabelResolver<NamedManifestProof> for ManifestNameRegistrar {
fn resolve_label_into(&self, name: &str) -> NamedManifestProof {
Expand Down Expand Up @@ -775,7 +775,7 @@ pub struct NamedManifestIntent {
name: String,
}

labelled_resolvable_with_self_impl!(NamedManifestIntent, resolver_output: Self);
labelled_resolvable_with_identity_impl!(NamedManifestIntent, resolver_output: Self);

impl LabelResolver<NamedManifestIntent> for ManifestNameRegistrar {
fn resolve_label_into(&self, name: &str) -> NamedManifestIntent {
Expand Down Expand Up @@ -827,7 +827,7 @@ pub struct NamedManifestAddressReservation {
name: String,
}

labelled_resolvable_with_self_impl!(NamedManifestAddressReservation, resolver_output: Self);
labelled_resolvable_with_identity_impl!(NamedManifestAddressReservation, resolver_output: Self);

impl LabelResolver<NamedManifestAddressReservation> for ManifestNameRegistrar {
fn resolve_label_into(&self, name: &str) -> NamedManifestAddressReservation {
Expand Down Expand Up @@ -928,7 +928,7 @@ pub struct NamedManifestAddress {
name: String,
}

labelled_resolvable_with_self_impl!(NamedManifestAddress, resolver_output: Self);
labelled_resolvable_with_identity_impl!(NamedManifestAddress, resolver_output: Self);

impl LabelResolver<NamedManifestAddress> for ManifestNameRegistrar {
fn resolve_label_into(&self, name: &str) -> NamedManifestAddress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ impl NetWithdraws {
pub fn set_fungible(
mut self,
resource_address: ResourceAddress,
total_amount: impl ResolvableDecimal,
total_amount: impl Resolve<Decimal>,
) -> Self {
self.resources.insert(
resource_address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl ChildSubintentSpecifier {
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub struct ManifestNamedIntent(pub u32);

labelled_resolvable_with_self_impl!(ManifestNamedIntent, resolver_output: Self);
labelled_resolvable_with_identity_impl!(ManifestNamedIntent, resolver_output: Self);

/// This exists as an unideal serialization target for [`ManifestNamedIntent`],
/// due to our inability to add a new ManifestCustomValue for the Cuttlefish update.
Expand Down

0 comments on commit 05c723e

Please sign in to comment.