-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add matches_prefix function to MultiLocation and Junctions
#4827
Conversation
| /// assert!(!m.matches_prefix(&X1(PalletInstance(3)))); | ||
| /// # } | ||
| /// ``` | ||
| pub fn matches_prefix(&self, prefix: &MultiLocation) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| pub fn matches_prefix(&self, prefix: &MultiLocation) -> bool { | |
| pub fn starts_with(&self, prefix: &MultiLocation) -> bool { |
Sounds more like the other methods available in rust
| if self.len() < prefix.len() { | ||
| return false | ||
| } | ||
| for i in 0..prefix.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for i in 0..prefix.len() { | |
| prefix.iter().zip(self.iter()).all(|l, r| l == r) |
This could be used to replace the rest of the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how I implemented it in Cumulus, but here I figured I'd keep to the imperative style of match_and_split 😄
Can definitely do.
| /// # Example | ||
| /// ```rust | ||
| /// # use xcm::v0::{Junction::*, MultiLocation::*}; | ||
| /// # fn main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// # fn main() { |
Rust does this automatically
| /// assert!(m.matches_prefix(&m)); | ||
| /// assert!(!m.matches_prefix(&X2(Parent, GeneralIndex(99)))); | ||
| /// assert!(!m.matches_prefix(&X1(PalletInstance(3)))); | ||
| /// # } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// # } |
KiChjang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, but was wondering if match_and_split can use match_prefix/starts_with underneath as well.
|
Code should also be made against the XCMv3 branch instead of master, i.e. against |
gavofyork
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be against XCM v3 branch. Also the various suggested by @bkchr
|
suderseded by #4835 |
What it says on the tin 😉
Motivated by paritytech/cumulus#936 (comment)
Key motivation:
match_and_splitonly allows a singleJunctionafter the prefix but it can be useful to be able to just check for a prefix and ignore what comes after.Possible extension: We could introduce a corresponding
match_and_split_tail(or similar, just a naming suggestion) to allow splitting off arbitrary suffixes.