forked from M-Labs/nalgebra
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).
This commit is contained in:
parent
19c99634c3
commit
4221c44a2b
@ -22,15 +22,16 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|||||||
archive_attr(derive(bytecheck::CheckBytes))
|
archive_attr(derive(bytecheck::CheckBytes))
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
|
||||||
pub struct Dynamic {
|
pub struct Dyn(pub usize);
|
||||||
value: usize,
|
|
||||||
}
|
// TODO: Deprecate?
|
||||||
|
pub type Dynamic = Dyn;
|
||||||
|
|
||||||
impl Dynamic {
|
impl Dynamic {
|
||||||
/// A dynamic size equal to `value`.
|
/// A dynamic size equal to `value`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn new(value: usize) -> Self {
|
pub const fn new(value: usize) -> Self {
|
||||||
Self { value }
|
Self(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ impl Serialize for Dynamic {
|
|||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
self.value.serialize(serializer)
|
self.0.serialize(serializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ impl<'de> Deserialize<'de> for Dynamic {
|
|||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
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]
|
#[inline]
|
||||||
fn value(&self) -> usize {
|
fn value(&self) -> usize {
|
||||||
self.value
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ impl Add<usize> for Dynamic {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(self, rhs: usize) -> Self {
|
fn add(self, rhs: usize) -> Self {
|
||||||
Self::new(self.value + rhs)
|
Self::new(self.0 + rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ impl Sub<usize> for Dynamic {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(self, rhs: usize) -> Self {
|
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]
|
#[inline]
|
||||||
fn $op(self, other: D) -> Dynamic {
|
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]
|
#[inline]
|
||||||
fn $op(self, other: Dynamic) -> Dynamic {
|
fn $op(self, other: Dynamic) -> Dynamic {
|
||||||
Dynamic::new($op_path(self.value(), other.value))
|
Dynamic::new($op_path(self.value(), other.value()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user