Skip to content

Commit 65ab1e6

Browse files
authored
Rename UInt => Uint (#143)
From https://rust-lang.github.io/api-guidelines/naming.html > In UpperCamelCase, acronyms and contractions of compound words count > as one word: use Uuid rather than UUID, Usize rather than USize or > Stdin rather than StdIn. Based on the `Usize` example, it's pretty clear we should be using `Uint` rather than `UInt`. This is also consistent with `num-bigint`.
1 parent 3c03a76 commit 65ab1e6

44 files changed

Lines changed: 647 additions & 647 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
//! ## Usage
2222
//!
23-
//! This crate defines a [`UInt`] type which is const generic around an inner
23+
//! This crate defines a [`Uint`] type which is const generic around an inner
2424
//! [`Limb`] array, where a [`Limb`] is a newtype for a word-sized integer.
2525
//! Thus large integers are represented as a arrays of smaller integers which
2626
//! are sized appropriately for the CPU, giving us some assurances of how
@@ -33,7 +33,7 @@
3333
//!
3434
//! ### `const fn` usage
3535
//!
36-
//! The [`UInt`] type provides a number of `const fn` inherent methods which
36+
//! The [`Uint`] type provides a number of `const fn` inherent methods which
3737
//! can be used for initializing and performing arithmetic on big integers in
3838
//! const contexts:
3939
//!
@@ -59,7 +59,7 @@
5959
//!
6060
//! ### Trait-based usage
6161
//!
62-
//! The [`UInt`] type itself does not implement the standard arithmetic traits
62+
//! The [`Uint`] type itself does not implement the standard arithmetic traits
6363
//! such as [`Add`], [`Sub`], [`Mul`], and [`Div`].
6464
//!
6565
//! To use these traits you must first pick a wrapper type which determines

src/non_zero.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Wrapper type for non-zero integers.
22
3-
use crate::{Encoding, Integer, Limb, UInt, Zero};
3+
use crate::{Encoding, Integer, Limb, Uint, Zero};
44
use core::{
55
fmt,
66
num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8},
@@ -237,9 +237,9 @@ impl From<NonZeroU64> for NonZero<Limb> {
237237
}
238238
}
239239

240-
impl<const LIMBS: usize> NonZero<UInt<LIMBS>> {
241-
/// Create a [`NonZero<UInt>`] from a [`UInt`] (const-friendly)
242-
pub const fn from_uint(n: UInt<LIMBS>) -> Self {
240+
impl<const LIMBS: usize> NonZero<Uint<LIMBS>> {
241+
/// Create a [`NonZero<Uint>`] from a [`Uint`] (const-friendly)
242+
pub const fn from_uint(n: Uint<LIMBS>) -> Self {
243243
let mut i = 0;
244244
let mut found_non_zero = false;
245245
while i < LIMBS {
@@ -252,62 +252,62 @@ impl<const LIMBS: usize> NonZero<UInt<LIMBS>> {
252252
Self(n)
253253
}
254254

255-
/// Create a [`NonZero<UInt>`] from a [`NonZeroU8`] (const-friendly)
255+
/// Create a [`NonZero<Uint>`] from a [`NonZeroU8`] (const-friendly)
256256
// TODO(tarcieri): replace with `const impl From<NonZeroU8>` when stable
257257
pub const fn from_u8(n: NonZeroU8) -> Self {
258-
Self(UInt::from_u8(n.get()))
258+
Self(Uint::from_u8(n.get()))
259259
}
260260

261-
/// Create a [`NonZero<UInt>`] from a [`NonZeroU16`] (const-friendly)
261+
/// Create a [`NonZero<Uint>`] from a [`NonZeroU16`] (const-friendly)
262262
// TODO(tarcieri): replace with `const impl From<NonZeroU16>` when stable
263263
pub const fn from_u16(n: NonZeroU16) -> Self {
264-
Self(UInt::from_u16(n.get()))
264+
Self(Uint::from_u16(n.get()))
265265
}
266266

267-
/// Create a [`NonZero<UInt>`] from a [`NonZeroU32`] (const-friendly)
267+
/// Create a [`NonZero<Uint>`] from a [`NonZeroU32`] (const-friendly)
268268
// TODO(tarcieri): replace with `const impl From<NonZeroU32>` when stable
269269
pub const fn from_u32(n: NonZeroU32) -> Self {
270-
Self(UInt::from_u32(n.get()))
270+
Self(Uint::from_u32(n.get()))
271271
}
272272

273-
/// Create a [`NonZero<UInt>`] from a [`NonZeroU64`] (const-friendly)
273+
/// Create a [`NonZero<Uint>`] from a [`NonZeroU64`] (const-friendly)
274274
// TODO(tarcieri): replace with `const impl From<NonZeroU64>` when stable
275275
pub const fn from_u64(n: NonZeroU64) -> Self {
276-
Self(UInt::from_u64(n.get()))
276+
Self(Uint::from_u64(n.get()))
277277
}
278278

279-
/// Create a [`NonZero<UInt>`] from a [`NonZeroU128`] (const-friendly)
279+
/// Create a [`NonZero<Uint>`] from a [`NonZeroU128`] (const-friendly)
280280
// TODO(tarcieri): replace with `const impl From<NonZeroU128>` when stable
281281
pub const fn from_u128(n: NonZeroU128) -> Self {
282-
Self(UInt::from_u128(n.get()))
282+
Self(Uint::from_u128(n.get()))
283283
}
284284
}
285285

286-
impl<const LIMBS: usize> From<NonZeroU8> for NonZero<UInt<LIMBS>> {
286+
impl<const LIMBS: usize> From<NonZeroU8> for NonZero<Uint<LIMBS>> {
287287
fn from(integer: NonZeroU8) -> Self {
288288
Self::from_u8(integer)
289289
}
290290
}
291291

292-
impl<const LIMBS: usize> From<NonZeroU16> for NonZero<UInt<LIMBS>> {
292+
impl<const LIMBS: usize> From<NonZeroU16> for NonZero<Uint<LIMBS>> {
293293
fn from(integer: NonZeroU16) -> Self {
294294
Self::from_u16(integer)
295295
}
296296
}
297297

298-
impl<const LIMBS: usize> From<NonZeroU32> for NonZero<UInt<LIMBS>> {
298+
impl<const LIMBS: usize> From<NonZeroU32> for NonZero<Uint<LIMBS>> {
299299
fn from(integer: NonZeroU32) -> Self {
300300
Self::from_u32(integer)
301301
}
302302
}
303303

304-
impl<const LIMBS: usize> From<NonZeroU64> for NonZero<UInt<LIMBS>> {
304+
impl<const LIMBS: usize> From<NonZeroU64> for NonZero<Uint<LIMBS>> {
305305
fn from(integer: NonZeroU64) -> Self {
306306
Self::from_u64(integer)
307307
}
308308
}
309309

310-
impl<const LIMBS: usize> From<NonZeroU128> for NonZero<UInt<LIMBS>> {
310+
impl<const LIMBS: usize> From<NonZeroU128> for NonZero<Uint<LIMBS>> {
311311
fn from(integer: NonZeroU128) -> Self {
312312
Self::from_u128(integer)
313313
}

src/uint.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ use zeroize::DefaultIsZeroes;
6060
/// # Encoding support
6161
/// This type supports many different types of encodings, either via the
6262
/// [`Encoding`][`crate::Encoding`] trait or various `const fn` decoding and
63-
/// encoding functions that can be used with [`UInt`] constants.
63+
/// encoding functions that can be used with [`Uint`] constants.
6464
///
6565
/// Optional crate features for encoding (off-by-default):
6666
/// - `generic-array`: enables [`ArrayEncoding`][`crate::ArrayEncoding`] trait which can be used to
67-
/// [`UInt`] as `GenericArray<u8, N>` and a [`ArrayDecoding`][`crate::ArrayDecoding`] trait which
68-
/// can be used to `GenericArray<u8, N>` as [`UInt`].
67+
/// [`Uint`] as `GenericArray<u8, N>` and a [`ArrayDecoding`][`crate::ArrayDecoding`] trait which
68+
/// can be used to `GenericArray<u8, N>` as [`Uint`].
6969
/// - `rlp`: support for [Recursive Length Prefix (RLP)][RLP] encoding.
7070
///
7171
/// [RLP]: https://eth.wiki/fundamentals/rlp
7272
// TODO(tarcieri): make generic around a specified number of bits.
7373
#[derive(Copy, Clone, Debug, Hash)]
74-
pub struct UInt<const LIMBS: usize> {
74+
pub struct Uint<const LIMBS: usize> {
7575
/// Inner limb array. Stored from least significant to most significant.
7676
limbs: [Limb; LIMBS],
7777
}
7878

79-
impl<const LIMBS: usize> UInt<LIMBS> {
79+
impl<const LIMBS: usize> Uint<LIMBS> {
8080
/// The value `0`.
8181
pub const ZERO: Self = Self::from_u8(0);
8282

@@ -86,17 +86,17 @@ impl<const LIMBS: usize> UInt<LIMBS> {
8686
/// The number of limbs used on this platform.
8787
pub const LIMBS: usize = LIMBS;
8888

89-
/// Maximum value this [`UInt`] can express.
89+
/// Maximum value this [`Uint`] can express.
9090
pub const MAX: Self = Self {
9191
limbs: [Limb::MAX; LIMBS],
9292
};
9393

94-
/// Const-friendly [`UInt`] constructor.
94+
/// Const-friendly [`Uint`] constructor.
9595
pub const fn new(limbs: [Limb; LIMBS]) -> Self {
9696
Self { limbs }
9797
}
9898

99-
/// Create a [`UInt`] from an array of [`Word`]s (i.e. word-sized unsigned
99+
/// Create a [`Uint`] from an array of [`Word`]s (i.e. word-sized unsigned
100100
/// integers).
101101
#[inline]
102102
pub const fn from_words(arr: [Word; LIMBS]) -> Self {
@@ -112,7 +112,7 @@ impl<const LIMBS: usize> UInt<LIMBS> {
112112
}
113113

114114
/// Create an array of [`Word`]s (i.e. word-sized unsigned integers) from
115-
/// a [`UInt`].
115+
/// a [`Uint`].
116116
#[inline]
117117
pub const fn to_words(self) -> [Word; LIMBS] {
118118
let mut arr = [0; LIMBS];
@@ -145,52 +145,52 @@ impl<const LIMBS: usize> UInt<LIMBS> {
145145
}
146146
}
147147

148-
/// Borrow the limbs of this [`UInt`].
148+
/// Borrow the limbs of this [`Uint`].
149149
// TODO(tarcieri): rename to `as_limbs` for consistency with `as_words`
150150
pub const fn limbs(&self) -> &[Limb; LIMBS] {
151151
&self.limbs
152152
}
153153

154-
/// Borrow the limbs of this [`UInt`] mutably.
154+
/// Borrow the limbs of this [`Uint`] mutably.
155155
// TODO(tarcieri): rename to `as_limbs_mut` for consistency with `as_words_mut`
156156
pub fn limbs_mut(&mut self) -> &mut [Limb; LIMBS] {
157157
&mut self.limbs
158158
}
159159

160-
/// Convert this [`UInt`] into its inner limbs.
160+
/// Convert this [`Uint`] into its inner limbs.
161161
// TODO(tarcieri): rename to `to_limbs` for consistency with `to_words`
162162
pub const fn into_limbs(self) -> [Limb; LIMBS] {
163163
self.limbs
164164
}
165165
}
166166

167-
impl<const LIMBS: usize> AsRef<[Word; LIMBS]> for UInt<LIMBS> {
167+
impl<const LIMBS: usize> AsRef<[Word; LIMBS]> for Uint<LIMBS> {
168168
fn as_ref(&self) -> &[Word; LIMBS] {
169169
self.as_words()
170170
}
171171
}
172172

173-
impl<const LIMBS: usize> AsMut<[Word; LIMBS]> for UInt<LIMBS> {
173+
impl<const LIMBS: usize> AsMut<[Word; LIMBS]> for Uint<LIMBS> {
174174
fn as_mut(&mut self) -> &mut [Word; LIMBS] {
175175
self.as_words_mut()
176176
}
177177
}
178178

179179
// TODO(tarcieri): eventually phase this out in favor of `limbs()`?
180-
impl<const LIMBS: usize> AsRef<[Limb]> for UInt<LIMBS> {
180+
impl<const LIMBS: usize> AsRef<[Limb]> for Uint<LIMBS> {
181181
fn as_ref(&self) -> &[Limb] {
182182
self.limbs()
183183
}
184184
}
185185

186186
// TODO(tarcieri): eventually phase this out in favor of `limbs_mut()`?
187-
impl<const LIMBS: usize> AsMut<[Limb]> for UInt<LIMBS> {
187+
impl<const LIMBS: usize> AsMut<[Limb]> for Uint<LIMBS> {
188188
fn as_mut(&mut self) -> &mut [Limb] {
189189
self.limbs_mut()
190190
}
191191
}
192192

193-
impl<const LIMBS: usize> ConditionallySelectable for UInt<LIMBS> {
193+
impl<const LIMBS: usize> ConditionallySelectable for Uint<LIMBS> {
194194
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
195195
let mut limbs = [Limb::ZERO; LIMBS];
196196

@@ -202,13 +202,13 @@ impl<const LIMBS: usize> ConditionallySelectable for UInt<LIMBS> {
202202
}
203203
}
204204

205-
impl<const LIMBS: usize> Default for UInt<LIMBS> {
205+
impl<const LIMBS: usize> Default for Uint<LIMBS> {
206206
fn default() -> Self {
207207
Self::ZERO
208208
}
209209
}
210210

211-
impl<const LIMBS: usize> Integer for UInt<LIMBS> {
211+
impl<const LIMBS: usize> Integer for Uint<LIMBS> {
212212
const ONE: Self = Self::ONE;
213213
const MAX: Self = Self::MAX;
214214

@@ -220,17 +220,17 @@ impl<const LIMBS: usize> Integer for UInt<LIMBS> {
220220
}
221221
}
222222

223-
impl<const LIMBS: usize> Zero for UInt<LIMBS> {
223+
impl<const LIMBS: usize> Zero for Uint<LIMBS> {
224224
const ZERO: Self = Self::ZERO;
225225
}
226226

227-
impl<const LIMBS: usize> fmt::Display for UInt<LIMBS> {
227+
impl<const LIMBS: usize> fmt::Display for Uint<LIMBS> {
228228
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
229229
fmt::UpperHex::fmt(self, f)
230230
}
231231
}
232232

233-
impl<const LIMBS: usize> fmt::LowerHex for UInt<LIMBS> {
233+
impl<const LIMBS: usize> fmt::LowerHex for Uint<LIMBS> {
234234
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
235235
for limb in self.limbs.iter().rev() {
236236
fmt::LowerHex::fmt(limb, f)?;
@@ -239,7 +239,7 @@ impl<const LIMBS: usize> fmt::LowerHex for UInt<LIMBS> {
239239
}
240240
}
241241

242-
impl<const LIMBS: usize> fmt::UpperHex for UInt<LIMBS> {
242+
impl<const LIMBS: usize> fmt::UpperHex for Uint<LIMBS> {
243243
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
244244
for limb in self.limbs.iter().rev() {
245245
fmt::UpperHex::fmt(limb, f)?;
@@ -250,9 +250,9 @@ impl<const LIMBS: usize> fmt::UpperHex for UInt<LIMBS> {
250250

251251
#[cfg(feature = "serde")]
252252
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
253-
impl<'de, const LIMBS: usize> Deserialize<'de> for UInt<LIMBS>
253+
impl<'de, const LIMBS: usize> Deserialize<'de> for Uint<LIMBS>
254254
where
255-
UInt<LIMBS>: Encoding,
255+
Uint<LIMBS>: Encoding,
256256
{
257257
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
258258
where
@@ -267,9 +267,9 @@ where
267267

268268
#[cfg(feature = "serde")]
269269
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
270-
impl<'de, const LIMBS: usize> Serialize for UInt<LIMBS>
270+
impl<'de, const LIMBS: usize> Serialize for Uint<LIMBS>
271271
where
272-
UInt<LIMBS>: Encoding,
272+
Uint<LIMBS>: Encoding,
273273
{
274274
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
275275
where
@@ -281,15 +281,15 @@ where
281281

282282
#[cfg(feature = "zeroize")]
283283
#[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))]
284-
impl<const LIMBS: usize> DefaultIsZeroes for UInt<LIMBS> {}
284+
impl<const LIMBS: usize> DefaultIsZeroes for Uint<LIMBS> {}
285285

286286
// TODO(tarcieri): use `const_evaluatable_checked` when stable to make generic around bits.
287287
macro_rules! impl_uint_aliases {
288288
($(($name:ident, $bits:expr, $doc:expr)),+) => {
289289
$(
290290
#[doc = $doc]
291291
#[doc="unsigned big integer."]
292-
pub type $name = UInt<{nlimbs!($bits)}>;
292+
pub type $name = Uint<{nlimbs!($bits)}>;
293293

294294
impl Encoding for $name {
295295
const BIT_SIZE: usize = $bits;

0 commit comments

Comments
 (0)