From f885cbab46ce65288c19ffc34edeaf4d6ea50241 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Wed, 4 Dec 2024 10:57:57 -0800 Subject: [PATCH] Incorporate naming feedback --- src/lib.rs | 16 ++++++++-------- tests/tests.rs | 28 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d22f151..8696c65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,7 +70,7 @@ pub trait Number: Sized + Copy + Clone + PartialOrd + Ord + PartialEq + Eq { /// Creates a number from the given value, throwing an error if the value is too large. /// This constructor is useful when the value is convertable to T. Use [`Self::new`] for literals. #[cfg(not(feature = "const_convert_and_const_trait_impl"))] - fn new_(value: T) -> Self; + fn from_(value: T) -> Self; /// Creates an instance from the given `value`. Unlike the various `new...` functions, this /// will never fail as the value is masked to the result size. @@ -157,7 +157,7 @@ macro_rules! impl_number_native { fn value(self) -> Self::UnderlyingType { self } #[inline] - fn new_(value: T) -> Self { + fn from_(value: T) -> Self { if T::BITS > Self::BITS as usize { assert!(value <= T::masked_new(Self::MAX)); } @@ -346,7 +346,7 @@ macro_rules! uint_impl_num { } #[inline] - fn new_(value: T) -> Self { + fn from_(value: T) -> Self { if Self::BITS < T::BITS { assert!(value <= Self::MAX.value.as_()); } @@ -415,7 +415,7 @@ macro_rules! uint_impl { /// Creates an instance. Panics if the given value is outside of the valid range #[inline] - pub const fn new_u8(value: u8) -> Self { + pub const fn from_u8(value: u8) -> Self { if Self::BITS < 8 { assert!(value <= Self::MAX.value as u8); } @@ -424,7 +424,7 @@ macro_rules! uint_impl { /// Creates an instance. Panics if the given value is outside of the valid range #[inline] - pub const fn new_u16(value: u16) -> Self { + pub const fn from_u16(value: u16) -> Self { if Self::BITS < 16 { assert!(value <= Self::MAX.value as u16); } @@ -433,7 +433,7 @@ macro_rules! uint_impl { /// Creates an instance. Panics if the given value is outside of the valid range #[inline] - pub const fn new_u32(value: u32) -> Self { + pub const fn from_u32(value: u32) -> Self { if Self::BITS < 32 { assert!(value <= Self::MAX.value as u32); } @@ -442,7 +442,7 @@ macro_rules! uint_impl { /// Creates an instance. Panics if the given value is outside of the valid range #[inline] - pub const fn new_u64(value: u64) -> Self { + pub const fn from_u64(value: u64) -> Self { if Self::BITS < 64 { assert!(value <= Self::MAX.value as u64); } @@ -451,7 +451,7 @@ macro_rules! uint_impl { /// Creates an instance. Panics if the given value is outside of the valid range #[inline] - pub const fn new_u128(value: u128) -> Self { + pub const fn from_u128(value: u128) -> Self { if Self::BITS < 128 { assert!(value <= Self::MAX.value as u128); } diff --git a/tests/tests.rs b/tests/tests.rs index f683630..89b97e5 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -2075,11 +2075,11 @@ fn schemars() { #[test] fn new_and_as_specific_types() { let a = u6::new(42); - let b = u6::new_u8(42); - let c = u6::new_u16(42); - let d = u6::new_u32(42); - let e = u6::new_u64(42); - let f = u6::new_u128(42); + let b = u6::from_u8(42); + let c = u6::from_u16(42); + let d = u6::from_u32(42); + let e = u6::from_u64(42); + let f = u6::from_u128(42); assert_eq!(a.as_u8(), 42); assert_eq!(a.as_u16(), 42); @@ -2098,7 +2098,7 @@ fn new_and_as_specific_types() { #[test] fn new_flexible() { let a = u10::new(1000); - let b = u11::new_(a); + let b = u11::from_(a); assert_eq!(a.as_u32(), 1000); assert_eq!(b.as_u32(), 1000); @@ -2109,7 +2109,7 @@ fn new_flexible() { #[should_panic] fn new_flexible_catches_out_of_bounds() { let a = u28::new(0x8000000); - let _b = u9::new_(a); + let _b = u9::from_(a); } #[cfg(not(feature = "const_convert_and_const_trait_impl"))] @@ -2117,7 +2117,7 @@ fn new_flexible_catches_out_of_bounds() { #[should_panic] fn new_flexible_catches_out_of_bounds_2() { let a = u28::new(0x0000200); - let _b = u9::new_(a); + let _b = u9::from_(a); } #[cfg(not(feature = "const_convert_and_const_trait_impl"))] @@ -2125,42 +2125,42 @@ fn new_flexible_catches_out_of_bounds_2() { #[should_panic] fn new_flexible_catches_out_of_bounds_primitive_type() { let a = u28::new(0x8000000); - let _b = u8::new_(a); + let _b = u8::from_(a); } #[cfg(not(feature = "const_convert_and_const_trait_impl"))] #[test] #[should_panic] fn new_constructors_catch_out_bounds_0() { - u7::new_u8(0x80u8); + u7::from_u8(0x80u8); } #[cfg(not(feature = "const_convert_and_const_trait_impl"))] #[test] #[should_panic] fn new_constructors_catch_out_bounds_1() { - u7::new_u32(0x80000060u32); + u7::from_u32(0x80000060u32); } #[cfg(not(feature = "const_convert_and_const_trait_impl"))] #[test] #[should_panic] fn new_constructors_catch_out_bounds_2() { - u7::new_u16(0x8060u16); + u7::from_u16(0x8060u16); } #[cfg(not(feature = "const_convert_and_const_trait_impl"))] #[test] #[should_panic] fn new_constructors_catch_out_bounds_3() { - u7::new_u64(0x80000000_00000060u64); + u7::from_u64(0x80000000_00000060u64); } #[cfg(not(feature = "const_convert_and_const_trait_impl"))] #[test] #[should_panic] fn new_constructors_catch_out_bounds_4() { - u7::new_u128(0x80000000_00000000_00000000_00000060u128); + u7::from_u128(0x80000000_00000000_00000000_00000060u128); } #[cfg(not(feature = "const_convert_and_const_trait_impl"))]