Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Prev Previous commit
Next Next commit
support multiple StaticLookup
  • Loading branch information
shawntabrizi committed Oct 24, 2020
commit 535a512903fc44d4d3681281548d8b9c20154e34
17 changes: 17 additions & 0 deletions primitives/runtime/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,23 @@ impl<AccountId: Codec + Clone + PartialEq + Debug> StaticLookup for AccountIdLoo
}
}

/// Perform a StaticLookup where there are multiple lookup sources of the same type.
impl<A, B> StaticLookup for (A, B)
where
A: StaticLookup,
B: StaticLookup<Source = A::Source, Target = A::Target>,
{
type Source = A::Source;
type Target = A::Target;

fn lookup(x: Self::Source) -> Result<Self::Target, LookupError> {
A::lookup(x.clone()).or_else(|_| B::lookup(x))
}
fn unlookup(x: Self::Target) -> Self::Source {
A::unlookup(x)
}
}

/// Extensible conversion trait. Generic over both source and destination types.
pub trait Convert<A, B> {
/// Make conversion.
Expand Down