/rust/registry/src/index.crates.io-1949cf8c6b5b557f/crypto-bigint-0.5.5/src/limb/from.rs
Line | Count | Source |
1 | | //! `From`-like conversions for [`Limb`]. |
2 | | |
3 | | use super::{Limb, WideWord, Word}; |
4 | | |
5 | | impl Limb { |
6 | | /// Create a [`Limb`] from a `u8` integer (const-friendly) |
7 | | // TODO(tarcieri): replace with `const impl From<u8>` when stable |
8 | 0 | pub const fn from_u8(n: u8) -> Self { |
9 | 0 | Limb(n as Word) |
10 | 0 | } |
11 | | |
12 | | /// Create a [`Limb`] from a `u16` integer (const-friendly) |
13 | | // TODO(tarcieri): replace with `const impl From<u16>` when stable |
14 | 0 | pub const fn from_u16(n: u16) -> Self { |
15 | 0 | Limb(n as Word) |
16 | 0 | } |
17 | | |
18 | | /// Create a [`Limb`] from a `u32` integer (const-friendly) |
19 | | // TODO(tarcieri): replace with `const impl From<u32>` when stable |
20 | 0 | pub const fn from_u32(n: u32) -> Self { |
21 | | #[allow(trivial_numeric_casts)] |
22 | 0 | Limb(n as Word) |
23 | 0 | } |
24 | | |
25 | | /// Create a [`Limb`] from a `u64` integer (const-friendly) |
26 | | // TODO(tarcieri): replace with `const impl From<u64>` when stable |
27 | | #[cfg(target_pointer_width = "64")] |
28 | 0 | pub const fn from_u64(n: u64) -> Self { |
29 | 0 | Limb(n) |
30 | 0 | } |
31 | | } |
32 | | |
33 | | impl From<u8> for Limb { |
34 | | #[inline] |
35 | 0 | fn from(n: u8) -> Limb { |
36 | 0 | Limb(n.into()) |
37 | 0 | } |
38 | | } |
39 | | |
40 | | impl From<u16> for Limb { |
41 | | #[inline] |
42 | 0 | fn from(n: u16) -> Limb { |
43 | 0 | Limb(n.into()) |
44 | 0 | } |
45 | | } |
46 | | |
47 | | impl From<u32> for Limb { |
48 | | #[inline] |
49 | 0 | fn from(n: u32) -> Limb { |
50 | 0 | Limb(n.into()) |
51 | 0 | } |
52 | | } |
53 | | |
54 | | #[cfg(target_pointer_width = "64")] |
55 | | impl From<u64> for Limb { |
56 | | #[inline] |
57 | 0 | fn from(n: u64) -> Limb { |
58 | 0 | Limb(n) |
59 | 0 | } |
60 | | } |
61 | | |
62 | | impl From<Limb> for Word { |
63 | | #[inline] |
64 | 0 | fn from(limb: Limb) -> Word { |
65 | 0 | limb.0 |
66 | 0 | } |
67 | | } |
68 | | |
69 | | impl From<Limb> for WideWord { |
70 | | #[inline] |
71 | 0 | fn from(limb: Limb) -> WideWord { |
72 | 0 | limb.0.into() |
73 | 0 | } |
74 | | } |