pub trait ConvertOrigin<Origin> {
// Required method
fn convert_origin(
origin: impl Into<Location>,
kind: OriginKind,
) -> Result<Origin, Location>;
}
Expand description
A converter trait
for origin types.
Can be amalgamated into tuples. If any of the tuple elements returns Ok(_)
, it short circuits.
Else, the Err(_)
of the last tuple item is returned. Each intermediate Err(_)
might return a
different origin
of type Origin
which is passed to the next convert item.
// A convertor that will bump the para id and pass it to the next one.
struct BumpParaId;
impl ConvertOrigin<u32> for BumpParaId {
fn convert_origin(origin: impl Into<Location>, _: OriginKind) -> Result<u32, Location> {
match origin.into().unpack() {
(0, [Junction::Parachain(id)]) => {
Err([Junction::Parachain(id + 1)].into())
}
_ => unreachable!()
}
}
}
struct AcceptPara7;
impl ConvertOrigin<u32> for AcceptPara7 {
fn convert_origin(origin: impl Into<Location>, _: OriginKind) -> Result<u32, Location> {
let origin = origin.into();
match origin.unpack() {
(0, [Junction::Parachain(id)]) if *id == 7 => {
Ok(7)
}
_ => Err(origin)
}
}
}
let origin: Location = [Junction::Parachain(6)].into();
assert!(
<(BumpParaId, AcceptPara7) as ConvertOrigin<u32>>::convert_origin(origin, OriginKind::Native)
.is_ok()
);
Required Methods§
Sourcefn convert_origin(
origin: impl Into<Location>,
kind: OriginKind,
) -> Result<Origin, Location>
fn convert_origin( origin: impl Into<Location>, kind: OriginKind, ) -> Result<Origin, Location>
Attempt to convert origin
to the generic Origin
whilst consuming it.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.