Skip to content

Commit

Permalink
Fix compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
danlehmann committed Aug 25, 2024
1 parent 35b1079 commit 0840c07
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ impl Display for TryNewError {
}

#[cfg_attr(feature = "const_convert_and_const_trait_impl", const_trait)]
pub trait Number: Sized {
type UnderlyingType: Copy
+ Clone
+ Number
pub trait Number: Sized + Copy + Clone {
type UnderlyingType: Number
+ Debug
+ From<u8>
+ TryFrom<u16>
Expand All @@ -68,8 +66,16 @@ pub trait Number: Sized {

fn value(self) -> Self::UnderlyingType;

#[cfg(feature = "const_convert_and_const_trait_impl")]
fn new_<T: ~const Number>(value: T) -> Self;

Check failure on line 70 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 70 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 70 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 70 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 70 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 70 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental
#[cfg(not(feature = "const_convert_and_const_trait_impl"))]
fn new_<T: Number>(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.
#[cfg(feature = "const_convert_and_const_trait_impl")]
fn masked_new<T: ~const Number>(value: T) -> Self;

Check failure on line 77 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 77 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 77 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 77 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 77 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 77 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental
#[cfg(not(feature = "const_convert_and_const_trait_impl"))]
fn masked_new<T: Number>(value: T) -> Self;

fn as_u8(&self) -> u8;
Expand All @@ -82,6 +88,13 @@ pub trait Number: Sized {

fn as_u128(&self) -> u128;

#[cfg(feature = "const_convert_and_const_trait_impl")]
#[inline]
fn as_<T: ~const Number>(self) -> T {

Check failure on line 93 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 93 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 93 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 93 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 93 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental

Check failure on line 93 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test

const trait impls are experimental
T::masked_new(self)
}

#[cfg(not(feature = "const_convert_and_const_trait_impl"))]
#[inline]
fn as_<T: Number>(self) -> T {
T::masked_new(self)
Expand All @@ -108,7 +121,7 @@ macro_rules! impl_number_native {
fn value(self) -> Self::UnderlyingType { self }

#[inline]
fn new_<T: Number>(value: T) -> Self {
fn new_<T: ~const Number>(value: T) -> Self {
match Self::BITS {
8 => value.as_u8() as Self,
16 => value.as_u16() as Self,
Expand All @@ -120,7 +133,7 @@ macro_rules! impl_number_native {
}

#[inline]
fn masked_new<T: Number>(value: T) -> Self {
fn masked_new<T: ~const Number>(value: T) -> Self {
// Primitive types don't need masking
Self::new_(value)
}
Expand Down

0 comments on commit 0840c07

Please sign in to comment.