Trait staging_xcm_builder::MatchXcm
source · pub trait MatchXcm {
type Inst;
type Loc;
type Error;
// Required methods
fn assert_remaining_insts(self, n: usize) -> Result<Self, Self::Error>
where Self: Sized;
fn match_next_inst<F>(self, f: F) -> Result<Self, Self::Error>
where Self: Sized,
F: FnMut(&mut Self::Inst) -> Result<(), Self::Error>;
fn match_next_inst_while<C, F>(
self,
cond: C,
f: F,
) -> Result<Self, Self::Error>
where Self: Sized,
C: Fn(&Self::Inst) -> bool,
F: FnMut(&mut Self::Inst) -> Result<ControlFlow<()>, Self::Error>;
// Provided method
fn skip_inst_while<C>(self, cond: C) -> Result<Self, Self::Error>
where Self: Sized,
C: Fn(&Self::Inst) -> bool { ... }
}
Expand description
API that allows to pattern-match against anything that is contained within an XCM.
The intended usage of the matcher API is to enable the ability to chain successive methods of this trait together, along with the ? operator for the purpose of facilitating the writing, maintenance and auditability of XCM barriers.
Example:
use frame_support::traits::ProcessMessageError;
use xcm::latest::Instruction;
use staging_xcm_builder::{CreateMatcher, MatchXcm};
let mut msg = [Instruction::<()>::ClearOrigin];
let res = msg
.matcher()
.assert_remaining_insts(1)?
.match_next_inst(|inst| match inst {
Instruction::<()>::ClearOrigin => Ok(()),
_ => Err(ProcessMessageError::BadFormat),
});
assert!(res.is_ok());
Ok::<(), ProcessMessageError>(())
Required Associated Types§
Required Methods§
sourcefn assert_remaining_insts(self, n: usize) -> Result<Self, Self::Error>where
Self: Sized,
fn assert_remaining_insts(self, n: usize) -> Result<Self, Self::Error>where
Self: Sized,
Returns success if the number of instructions that still have not been iterated over
equals n
, otherwise returns an error.
sourcefn match_next_inst<F>(self, f: F) -> Result<Self, Self::Error>
fn match_next_inst<F>(self, f: F) -> Result<Self, Self::Error>
Accepts a closure f
that contains an argument signifying the next instruction to be
iterated over. The closure can then be used to check whether the instruction matches a
given condition, and can also be used to mutate the fields of an instruction.
The closure f
returns success when the instruction passes the condition, otherwise it
returns an error, which will ultimately be returned by this function.
sourcefn match_next_inst_while<C, F>(self, cond: C, f: F) -> Result<Self, Self::Error>
fn match_next_inst_while<C, F>(self, cond: C, f: F) -> Result<Self, Self::Error>
Attempts to continuously iterate through the instructions while applying f
to each of
them, until either the last instruction or cond
returns false.
If f
returns an error, then iteration halts and the function returns that error.
Otherwise, f
returns a ControlFlow
which signifies whether the iteration breaks or
continues.