aboutsummaryrefslogtreecommitdiff
path: root/rust/kernel/ptr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/kernel/ptr.rs')
-rw-r--r--rust/kernel/ptr.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/rust/kernel/ptr.rs b/rust/kernel/ptr.rs
index 82acb531b17b..2c12e4fd4572 100644
--- a/rust/kernel/ptr.rs
+++ b/rust/kernel/ptr.rs
@@ -11,7 +11,10 @@ use core::mem::{
};
use core::num::NonZero;
-use crate::const_assert;
+use crate::{
+ const_assert,
+ num::FromConst, //
+};
/// Type representing an alignment, which is always a power of two.
///
@@ -166,6 +169,13 @@ impl Alignment {
}
}
+impl<const V: i128> FromConst<V> for Alignment {
+ const VALUE: Self = match Alignment::new_checked(<usize as FromConst<V>>::VALUE) {
+ Some(alignment) => alignment,
+ None => panic!("constant is not a power of two"),
+ };
+}
+
/// Trait for items that can be aligned against an [`Alignment`].
pub trait Alignable: Sized {
/// Aligns `self` down to `alignment`.