Skip to content

Commit 2caa986

Browse files
Amount, Instant and Id now impl Default for relevant TraitFlags
1 parent 099d333 commit 2caa986

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

src/amount.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub struct Amount<const TF: TraitFlags, Unit, Repr>(
152152
);
153153

154154
impl<const TF: TraitFlags, Unit, Repr: Copy> Amount<TF, Unit, Repr> {
155+
// @TODO
155156
/// Returns the wrapped value.
156157
///
157158
/// ```
@@ -176,7 +177,7 @@ impl<const TF: TraitFlags, Unit, Repr> Amount<TF, Unit, Repr> {
176177
}
177178
}
178179

179-
impl<const TF: TraitFlags, Unit: Default, Repr: Copy> Amount<TF, Unit, Repr> {
180+
impl<const TF: TraitFlags, Unit: Default, Repr> Amount<TF, Unit, Repr> {
180181
// @TODO similar but without &self
181182
//
182183
/// Provides a useful shortcut to access units of an amount if
@@ -223,7 +224,7 @@ where
223224
}
224225
}
225226

226-
impl<const TF: TraitFlags, Unit, Repr: Copy> From<Repr> for Amount<TF, Unit, Repr> {
227+
impl<const TF: TraitFlags, Unit, Repr> From<Repr> for Amount<TF, Unit, Repr> {
227228
fn from(repr: Repr) -> Self {
228229
Self::new(repr)
229230
}
@@ -235,15 +236,30 @@ impl<const TF: TraitFlags, Unit, Repr: Copy> From<Repr> for Amount<TF, Unit, Rep
235236
// `PartialEq<Wrapper<T>>` require `T` to implement `PartialEq`, which
236237
// is not what we want: `T` is phantom in our case.
237238

238-
impl<const TF: TraitFlags, Unit, Repr: Copy> Clone for Amount<TF, Unit, Repr> {
239+
impl<const TF: TraitFlags, Unit, Repr: Clone> Clone for Amount<TF, Unit, Repr> {
239240
fn clone(&self) -> Self {
240-
Amount(self.0, PhantomData)
241+
Amount(self.0.clone(), PhantomData)
241242
}
242243
}
243244

244245
impl<Unit, Repr: Copy> Copy for Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr> {}
245246
impl<Unit, Repr: Copy> Copy for Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Unit, Repr> {}
246247

248+
impl<Unit, Repr: Default> Default
249+
for Amount<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
250+
{
251+
fn default() -> Self {
252+
Self(Default::default(), PhantomData)
253+
}
254+
}
255+
impl<Unit, Repr: Default> Default
256+
for Amount<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>
257+
{
258+
fn default() -> Self {
259+
Self(Default::default(), PhantomData)
260+
}
261+
}
262+
247263
impl<const TF: TraitFlags, Unit, Repr: PartialEq> PartialEq for Amount<TF, Unit, Repr> {
248264
fn eq(&self, rhs: &Self) -> bool {
249265
self.0.eq(&rhs.0)

src/id.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,21 @@ impl<const TF: TraitFlags, Entity, Repr: Clone> Clone for Id<TF, Entity, Repr> {
217217
impl<Entity, Repr: Copy> Copy for Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Entity, Repr> {}
218218
impl<Entity, Repr: Copy> Copy for Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_NO_DEFAULT }, Entity, Repr> {}
219219

220+
impl<Unit, Repr: Default> Default
221+
for Id<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
222+
{
223+
fn default() -> Self {
224+
Self(Default::default(), PhantomData)
225+
}
226+
}
227+
impl<Unit, Repr: Default> Default
228+
for Id<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>
229+
{
230+
fn default() -> Self {
231+
Self(Default::default(), PhantomData)
232+
}
233+
}
234+
220235
impl<const TF: TraitFlags, Entity, Repr: PartialEq> PartialEq for Id<TF, Entity, Repr> {
221236
fn eq(&self, rhs: &Self) -> bool {
222237
self.get().eq(&rhs.get())

src/instant.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ pub struct Instant<const TF: TraitFlags, Unit, Repr>(
148148
);
149149
//type TT<X>= core::sync::Exclusive<>
150150
impl<const TF: TraitFlags, Unit, Repr: Copy> Instant<TF, Unit, Repr> {
151+
// @TODO
152+
151153
/// Returns the wrapped value.
152154
///
153155
/// ```
@@ -172,7 +174,7 @@ impl<const TF: TraitFlags, Unit, Repr> Instant<TF, Unit, Repr> {
172174
}
173175
}
174176

175-
impl<const TF: TraitFlags, Unit: Default, Repr: Copy> Instant<TF, Unit, Repr> {
177+
impl<const TF: TraitFlags, Unit: Default, Repr> Instant<TF, Unit, Repr> {
176178
/// Provides a useful shortcut to access units of an instant if
177179
/// they implement the `Default` trait:
178180
///
@@ -217,15 +219,15 @@ where
217219
}
218220
}
219221

220-
impl<const TF: TraitFlags, Unit, Repr: Copy> From<Repr> for Instant<TF, Unit, Repr> {
222+
impl<const TF: TraitFlags, Unit, Repr> From<Repr> for Instant<TF, Unit, Repr> {
221223
fn from(repr: Repr) -> Self {
222224
Self::new(repr)
223225
}
224226
}
225227

226-
impl<const TF: TraitFlags, Unit, Repr: Copy> Clone for Instant<TF, Unit, Repr> {
228+
impl<const TF: TraitFlags, Unit, Repr: Clone> Clone for Instant<TF, Unit, Repr> {
227229
fn clone(&self) -> Self {
228-
Instant(self.0, PhantomData)
230+
Instant(self.0.clone(), PhantomData)
229231
}
230232
}
231233

@@ -238,6 +240,21 @@ impl<Unit, Repr: Copy> Copy
238240
{
239241
}
240242

243+
impl<Unit, Repr: Default> Default
244+
for Instant<{ trait_flag::TRAIT_FLAGS_IS_COPY_IS_DEFAULT }, Unit, Repr>
245+
{
246+
fn default() -> Self {
247+
Self(Default::default(), PhantomData)
248+
}
249+
}
250+
impl<Unit, Repr: Default> Default
251+
for Instant<{ trait_flag::TRAIT_FLAGS_NO_COPY_IS_DEFAULT }, Unit, Repr>
252+
{
253+
fn default() -> Self {
254+
Self(Default::default(), PhantomData)
255+
}
256+
}
257+
241258
impl<const TF: TraitFlags, Unit, Repr: PartialEq> PartialEq for Instant<TF, Unit, Repr> {
242259
fn eq(&self, rhs: &Self) -> bool {
243260
self.0.eq(&rhs.0)

0 commit comments

Comments
 (0)