From 4221c44a2b74759dc67ce397807ad73c8e6998ba Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Thu, 24 Nov 2022 13:16:59 +0100 Subject: [PATCH] Rename Dynamic -> Dyn 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). --- src/base/dimension.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/base/dimension.rs b/src/base/dimension.rs index fef44645..cf290af5 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -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) } } @@ -40,7 +41,7 @@ impl Serialize for Dynamic { where S: Serializer, { - self.value.serialize(serializer) + self.0.serialize(serializer) } } @@ -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)) } } @@ -96,7 +97,7 @@ unsafe impl Dim for Dynamic { #[inline] fn value(&self) -> usize { - self.value + self.0 } } @@ -105,7 +106,7 @@ impl Add for Dynamic { #[inline] fn add(self, rhs: usize) -> Self { - Self::new(self.value + rhs) + Self::new(self.0 + rhs) } } @@ -114,7 +115,7 @@ impl Sub for Dynamic { #[inline] fn sub(self, rhs: usize) -> Self { - Self::new(self.value - rhs) + Self::new(self.0 - rhs) } } @@ -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())) } } @@ -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())) } }