Introduce EnsureOrigin::try_successul_origin (#11558)

* Introduce `EnsureOrigin::try_successul_origin`

* Formatting

* Fixes

* Add Morph

* Fixes

* Formatting
This commit is contained in:
Gavin Wood
2022-05-31 19:12:07 +01:00
committed by GitHub
parent adf0773f9d
commit 9107ae41fd
6 changed files with 221 additions and 97 deletions
@@ -274,6 +274,42 @@ where
}
}
/// Extensible conversion trait. Generic over only source type, with destination type being
/// associated.
pub trait Morph<A> {
/// The type into which `A` is mutated.
type Outcome;
/// Make conversion.
fn morph(a: A) -> Self::Outcome;
}
/// A structure that performs identity conversion.
impl<T> Morph<T> for Identity {
type Outcome = T;
fn morph(a: T) -> T {
a
}
}
/// Extensible conversion trait. Generic over only source type, with destination type being
/// associated.
pub trait TryMorph<A> {
/// The type into which `A` is mutated.
type Outcome;
/// Make conversion.
fn try_morph(a: A) -> Result<Self::Outcome, ()>;
}
/// A structure that performs identity conversion.
impl<T> TryMorph<T> for Identity {
type Outcome = T;
fn try_morph(a: T) -> Result<T, ()> {
Ok(a)
}
}
/// Extensible conversion trait. Generic over both source and destination types.
pub trait Convert<A, B> {
/// Make conversion.