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>] {
5454 unsafe { & mut * ptr }
5555 }
5656}
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;
3535
3636pub use self :: autorelease:: { autoreleasepool, AutoreleasePool , AutoreleaseSafe } ;
3737pub use self :: id:: Id ;
38- pub use self :: id_traits:: { SliceId , SliceIdMut } ;
38+ pub use self :: id_traits:: { DefaultId , SliceId , SliceIdMut } ;
3939pub use self :: ownership:: { Owned , Ownership , Shared } ;
4040pub use self :: weak_id:: WeakId ;
4141
You can’t perform that action at this time.
0 commit comments