29 lines
846 B
Rust
29 lines
846 B
Rust
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
// See Notices.txt for copyright information
|
|
use std::{fmt::Debug, hash::Hash};
|
|
|
|
mod sealed {
|
|
pub trait Sealed {}
|
|
}
|
|
|
|
/// the only implementation is `ConstUsize<Self::VALUE>`
|
|
pub trait GenericConstUsize:
|
|
sealed::Sealed + Copy + Ord + Hash + Default + Debug + 'static + Send + Sync
|
|
{
|
|
const VALUE: usize;
|
|
}
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
|
pub struct ConstUsize<const VALUE: usize>;
|
|
|
|
impl<const VALUE: usize> Debug for ConstUsize<VALUE> {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.debug_tuple("ConstUsize").field(&Self::VALUE).finish()
|
|
}
|
|
}
|
|
|
|
impl<const VALUE: usize> sealed::Sealed for ConstUsize<VALUE> {}
|
|
|
|
impl<const VALUE: usize> GenericConstUsize for ConstUsize<VALUE> {
|
|
const VALUE: usize = VALUE;
|
|
}
|