Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions humanbyte-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,34 @@ pub fn humanbyte_ops(input: TokenStream) -> TokenStream {
}
}

#[cfg(target_pointer_width = "64")]
impl core::ops::Add<#name> for usize {
type Output = #name;
#[inline(always)]
fn add(self, rhs: #name) -> #name {
#name(rhs.0 + (self as u64))
}
}


#[cfg(target_pointer_width = "64")]
impl core::ops::Sub<#name> for usize {
type Output = #name;
#[inline(always)]
fn sub(self, rhs: #name) -> #name {
#name(self as u64 - rhs.0)
}
}

#[cfg(target_pointer_width = "64")]
impl core::ops::Mul<#name> for usize {
type Output = #name;
#[inline(always)]
fn mul(self, rhs: #name) -> #name {
#name(rhs.0 * (self as u64))
}
}

impl #name {
/// Provides `HumanByteRange` with explicit lower and upper bounds.
pub fn range<I: Into<Self>>(start: I, stop: I) -> ::humanbyte::HumanByteRange<Self> {
Expand Down Expand Up @@ -340,6 +368,13 @@ pub fn humanbyte_parse(input: TokenStream) -> TokenStream {
pub const fn as_u64(&self) -> u64 {
self.0
}

/// Returns the inner value as usize.
#[cfg(target_pointer_width = "64")]
#[inline(always)]
pub const fn as_usize(&self) -> usize {
self.0 as usize
}
}
};

Expand Down
Loading