vsss_rs/
primitive.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use super::*;
use core::{
    fmt::{Debug, Display},
    hash::Hash,
};
use num::{
    traits::{
        ConstOne, ConstZero, FromBytes, NumAssign, NumAssignRef, NumOps, NumRef, SaturatingAdd,
        SaturatingMul, SaturatingSub, ToBytes, ToPrimitive,
    },
    PrimInt,
};

#[cfg(feature = "zeroize")]
/// Placeholder for conditionally compiling in [`zeroize::DefaultIsZeroes`].
pub trait PrimitiveZeroize: zeroize::DefaultIsZeroes {}
#[cfg(not(feature = "zeroize"))]
/// Placeholder for conditionally compiling in [`zeroize::DefaultIsZeroes`].
pub trait PrimitiveZeroize {}

#[cfg(feature = "zeroize")]
impl<T: zeroize::DefaultIsZeroes> PrimitiveZeroize for T {}
#[cfg(not(feature = "zeroize"))]
impl<T> PrimitiveZeroize for T {}

/// An extension trait for primitive integers that are used as share identifiers.
pub trait Primitive<const BYTES: usize>:
    Sized
    + PrimInt
    + NumOps
    + NumRef
    + NumAssignRef
    + NumAssign
    + SaturatingAdd
    + SaturatingSub
    + SaturatingMul
    + ConstOne
    + ConstZero
    + FixedArray<BYTES>
    + ToBytes
    + FromBytes<Bytes = <Self as ToBytes>::Bytes>
    + ToPrimitive
    + Copy
    + Clone
    + Default
    + Debug
    + Display
    + 'static
    + Hash
    + PrimitiveZeroize
{
}

impl<
        P: Sized
            + PrimInt
            + NumOps
            + NumRef
            + NumAssignRef
            + NumAssign
            + SaturatingAdd
            + SaturatingSub
            + SaturatingMul
            + ConstOne
            + ConstZero
            + FixedArray<BYTES>
            + ToBytes
            + FromBytes<Bytes = <Self as ToBytes>::Bytes>
            + ToPrimitive
            + Copy
            + Clone
            + Default
            + Debug
            + Display
            + 'static
            + Hash
            + PrimitiveZeroize,
        const BYTES: usize,
    > Primitive<BYTES> for P
{
}