File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -54,3 +54,24 @@ impl<T: Message> SliceIdMut for [Id<T, Owned>] {
54
54
unsafe { & mut * ptr }
55
55
}
56
56
}
57
+
58
+ /// Helper trait to implement [`Default`] on types whoose default value is an
59
+ /// [`Id`].
60
+ // TODO: Remove `Sized` bound.
61
+ // TODO: Maybe make this `unsafe` and provide a default implementation?
62
+ pub trait DefaultId : Sized {
63
+ /// Indicates whether the default value is mutable or immutable.
64
+ type Ownership : Ownership ;
65
+
66
+ /// The default [`Id`] for a type.
67
+ ///
68
+ /// On most objects the implementation would just be sending a message to
69
+ /// the `new` selector.
70
+ fn default_id ( ) -> Id < Self , Self :: Ownership > ;
71
+ }
72
+
73
+ impl < T : DefaultId > Default for Id < T , T :: Ownership > {
74
+ fn default ( ) -> Self {
75
+ T :: default_id ( )
76
+ }
77
+ }
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ mod weak_id;
35
35
36
36
pub use self :: autorelease:: { autoreleasepool, AutoreleasePool , AutoreleaseSafe } ;
37
37
pub use self :: id:: Id ;
38
- pub use self :: id_traits:: { SliceId , SliceIdMut } ;
38
+ pub use self :: id_traits:: { DefaultId , SliceId , SliceIdMut } ;
39
39
pub use self :: ownership:: { Owned , Ownership , Shared } ;
40
40
pub use self :: weak_id:: WeakId ;
41
41
You can’t perform that action at this time.
0 commit comments