Skip to content

Commit

Permalink
Add DefaultId helper trait
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Oct 15, 2021
1 parent af9e0a0 commit 4955e5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions objc2/src/rc/id_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,18 @@ impl<T: Message> SliceIdMut for [Id<T, Owned>] {
unsafe { &mut *ptr }
}
}

/// Helper trait to implement [`Default`] on types whoose default is an `Id`.
// TODO: Remove `Sized` bound.
pub trait DefaultId: Sized {
/// Indicates whether the default value is mutable or immutable.
type Ownership: Ownership;

fn default_id() -> Id<Self, Self::Ownership>;
}

impl<T: DefaultId> Default for Id<T, T::Ownership> {
fn default() -> Self {
T::default_id()
}
}
2 changes: 1 addition & 1 deletion objc2/src/rc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod weak_id;

pub use self::autorelease::{autoreleasepool, AutoreleasePool, AutoreleaseSafe};
pub use self::id::Id;
pub use self::id_traits::{SliceId, SliceIdMut};
pub use self::id_traits::{DefaultId, SliceId, SliceIdMut};
pub use self::ownership::{Owned, Ownership, Shared};
pub use self::weak_id::WeakId;

Expand Down

0 comments on commit 4955e5c

Please sign in to comment.