Skip to content

Commit

Permalink
allow for u8 to be used as hold/freeze reason (paritytech#5348)
Browse files Browse the repository at this point in the history
..without needing to provide your own `newtype` around it.  

This will allow `type Reason = u8` to be used as `FreezeReason` and
`HoldReason`, which I think is a nice simplification if one doens't want
to deal with the complications.

At the same time, it is a bit of an anti-pattern.

Putting it out there to check people's vibes.
  • Loading branch information
kianenigma authored Aug 15, 2024
1 parent 41a679c commit 90c91b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions prdoc/pr_5348.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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: allow for u8 to be used as hold/freeze reason

doc:
- audience: Runtime Dev
description: |
Allows for `u8` type to be configured as `HoldReason` and `FreezeReason`

crates:
- name: frame-support
bump: patch
4 changes: 4 additions & 0 deletions substrate/frame/support/src/traits/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl VariantCount for () {
const VARIANT_COUNT: u32 = 0;
}

impl VariantCount for u8 {
const VARIANT_COUNT: u32 = 256;
}

/// Adapter for `Get<u32>` to access `VARIANT_COUNT` from `trait pub trait VariantCount {`.
pub struct VariantCountOf<T: VariantCount>(core::marker::PhantomData<T>);
impl<T: VariantCount> Get<u32> for VariantCountOf<T> {
Expand Down

0 comments on commit 90c91b1

Please sign in to comment.