Skip to content

Commit

Permalink
Rename Dynamic -> Dyn
Browse files Browse the repository at this point in the history
Provide a type alias to avoid breaking code. Make Dyn a
tuple struct so that we can use the succinct syntax
Dyn(n) instead of Dyn::new(n).
  • Loading branch information
Andlon authored and sebcrozet committed Jan 14, 2023
1 parent 022bf1f commit ac4a2d8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/base/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
archive_attr(derive(bytecheck::CheckBytes))
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
pub struct Dynamic {
value: usize,
}
pub struct Dyn(pub usize);

// TODO: Deprecate?
pub type Dynamic = Dyn;

impl Dynamic {
/// A dynamic size equal to `value`.
#[inline]
pub const fn new(value: usize) -> Self {
Self { value }
Self(value)
}
}

Expand All @@ -40,7 +41,7 @@ impl Serialize for Dynamic {
where
S: Serializer,
{
self.value.serialize(serializer)
self.0.serialize(serializer)
}
}

Expand All @@ -50,7 +51,7 @@ impl<'de> Deserialize<'de> for Dynamic {
where
D: Deserializer<'de>,
{
usize::deserialize(deserializer).map(|x| Dynamic { value: x })
usize::deserialize(deserializer).map(|x| Dynamic(x))
}
}

Expand Down Expand Up @@ -96,7 +97,7 @@ unsafe impl Dim for Dynamic {

#[inline]
fn value(&self) -> usize {
self.value
self.0
}
}

Expand All @@ -105,7 +106,7 @@ impl Add<usize> for Dynamic {

#[inline]
fn add(self, rhs: usize) -> Self {
Self::new(self.value + rhs)
Self::new(self.0 + rhs)
}
}

Expand All @@ -114,7 +115,7 @@ impl Sub<usize> for Dynamic {

#[inline]
fn sub(self, rhs: usize) -> Self {
Self::new(self.value - rhs)
Self::new(self.0 - rhs)
}
}

Expand Down Expand Up @@ -157,7 +158,7 @@ macro_rules! dim_ops(

#[inline]
fn $op(self, other: D) -> Dynamic {
Dynamic::new($op_path(self.value, other.value()))
Dynamic::new($op_path(self.value(), other.value()))
}
}

Expand All @@ -167,7 +168,7 @@ macro_rules! dim_ops(

#[inline]
fn $op(self, other: Dynamic) -> Dynamic {
Dynamic::new($op_path(self.value(), other.value))
Dynamic::new($op_path(self.value(), other.value()))
}
}

Expand Down

0 comments on commit ac4a2d8

Please sign in to comment.