Skip to content

Commit

Permalink
Add prdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
dastansam committed May 4, 2024
1 parent 61a62b7 commit 37c8a6b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
36 changes: 24 additions & 12 deletions polkadot/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,37 @@ pub trait TryAs<T> {
}

macro_rules! versioned_type {
// only impl `MaxEncodedLen` for enums without generic type parameters
(@internal $n:ident, $v3:ty, ) => {
// only impl `MaxEncodedLen` for enums without generic type parameters
impl MaxEncodedLen for $n {
fn max_encoded_len() -> usize {
<$v3>::max_encoded_len()
}
}
impl IntoVersion for $n {
fn into_version(self, n: Version) -> Result<Self, ()> {
Ok(match n {
1 | 2 => Self::V2(self.try_into()?),
3 => Self::V3(self.try_into()?),
4 => Self::V4(self.try_into()?),
_ => return Err(()),
})
}
}
};
(@internal $n:ident, $v3:ty, $t:ident) => {
// `VersionedXcm` doesn't have version 1, so we don't need to handle it.
impl<$t> IntoVersion for $n<$t>{
fn into_version(self, n: Version) -> Result<Self, ()> {
Ok(match n {
2 => Self::V2(self.try_into()?),
3 => Self::V3(self.try_into()?),
4 => Self::V4(self.try_into()?),
_ => return Err(()),
})
}
}
};
(@internal $n:ident, $v3:ty, $t:ident) => {};
($(#[$attr:meta])* pub enum $n:ident {
$(#[$index3:meta])+
V3($v3:ty),
Expand Down Expand Up @@ -242,16 +264,6 @@ macro_rules! versioned_type {
}
}
}
impl$(<$($gen),+>)? IntoVersion for $n $(<$($gen),+>)?{
fn into_version(self, n: Version) -> Result<Self, ()> {
Ok(match n {
1 | 2 => Self::V2(self.try_into()?),
3 => Self::V3(self.try_into()?),
4 => Self::V4(self.try_into()?),
_ => return Err(()),
})
}
}
impl$(<$($gen),+>)? From<$v2> for $n $(<$($gen),+>)? {
fn from(x: $v2) -> Self {
$n::V2(x)
Expand Down
15 changes: 15 additions & 0 deletions prdoc/pr_4378.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "Use `versioned_type!` macro for `VersionedXcm`"

doc:
- audience: Runtime Dev
description: |
Currently, all other versioned types in the `stagin-xcm` are created using `versioned_type!` macro, except for `VersionedXcm`.
This PR adds changes `versioned_type` macro so that it can be used for `VersionedXcm` as well. This is done by adding optional
generic type param to an enum that is passed to the macro.

crates:
- name: staging-xcm
bump: minor

0 comments on commit 37c8a6b

Please sign in to comment.