Add doc comments for cmp traits and use unambiguius paths

This commit is contained in:
Devin Ragotzy 2020-08-03 11:21:56 -04:00 committed by Jonas Platte
parent 3f370c5f1b
commit 606f988ed8
2 changed files with 36 additions and 5 deletions

View File

@ -382,7 +382,8 @@ fn expand_eq_ord_event(input: &DeriveInput, fields: &[Field]) -> Option<TokenStr
Some(quote! { Some(quote! {
impl #impl_gen ::std::cmp::PartialEq for #ident #ty_gen #where_clause { impl #impl_gen ::std::cmp::PartialEq for #ident #ty_gen #where_clause {
fn eq(&self, other: &Self) -> bool { /// This checks if two `EventId`s are equal.
fn eq(&self, other: &Self) -> ::std::primitive::bool {
self.event_id == other.event_id self.event_id == other.event_id
} }
} }
@ -390,12 +391,14 @@ fn expand_eq_ord_event(input: &DeriveInput, fields: &[Field]) -> Option<TokenStr
impl #impl_gen ::std::cmp::Eq for #ident #ty_gen #where_clause {} impl #impl_gen ::std::cmp::Eq for #ident #ty_gen #where_clause {}
impl #impl_gen ::std::cmp::PartialOrd for #ident #ty_gen #where_clause { impl #impl_gen ::std::cmp::PartialOrd for #ident #ty_gen #where_clause {
/// This compares `EventId`s and orders them lexicographically.
fn partial_cmp(&self, other: &Self) -> ::std::option::Option<::std::cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> ::std::option::Option<::std::cmp::Ordering> {
self.event_id.partial_cmp(&other.event_id) self.event_id.partial_cmp(&other.event_id)
} }
} }
impl #impl_gen ::std::cmp::Ord for #ident #ty_gen #where_clause { impl #impl_gen ::std::cmp::Ord for #ident #ty_gen #where_clause {
/// This compares `EventId`s and orders them lexicographically.
fn cmp(&self, other: &Self) -> ::std::cmp::Ordering { fn cmp(&self, other: &Self) -> ::std::cmp::Ordering {
self.event_id.cmp(&other.event_id) self.event_id.cmp(&other.event_id)
} }

View File

@ -16,7 +16,7 @@ pub struct BasicEvent<C: BasicEventContent> {
pub content: C, pub content: C,
} }
/// Ephemeral room event. /// An ephemeral room event.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct EphemeralRoomEvent<C: EphemeralRoomEventContent> { pub struct EphemeralRoomEvent<C: EphemeralRoomEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
@ -33,9 +33,9 @@ pub struct SyncEphemeralRoomEvent<C: EphemeralRoomEventContent> {
pub content: C, pub content: C,
} }
/// Message event. /// A message event.
/// ///
/// `MessageEvent` implements the comparison trait's using only /// `MessageEvent` implements the comparison traits using only
/// the `event_id` field, a sorted list would be sorted lexicographically based on /// the `event_id` field, a sorted list would be sorted lexicographically based on
/// the event's `EventId`. /// the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
@ -60,6 +60,10 @@ pub struct MessageEvent<C: MessageEventContent> {
} }
/// A message event without a `room_id`. /// A message event without a `room_id`.
///
/// `SyncMessageEvent` implements the comparison traits using only
/// the `event_id` field, a sorted list would be sorted lexicographically based on
/// the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct SyncMessageEvent<C: MessageEventContent> { pub struct SyncMessageEvent<C: MessageEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
@ -79,6 +83,10 @@ pub struct SyncMessageEvent<C: MessageEventContent> {
} }
/// A redacted message event. /// A redacted message event.
///
/// `RedactedMessageEvent` implements the comparison traits using only
/// the `event_id` field, a sorted list would be sorted lexicographically based on
/// the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct RedactedMessageEvent<C: RedactedMessageEventContent> { pub struct RedactedMessageEvent<C: RedactedMessageEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
@ -101,6 +109,10 @@ pub struct RedactedMessageEvent<C: RedactedMessageEventContent> {
} }
/// A redacted message event without a `room_id`. /// A redacted message event without a `room_id`.
///
/// `RedactedSyncMessageEvent` implements the comparison traits using only
/// the `event_id` field, a sorted list would be sorted lexicographically based on
/// the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct RedactedSyncMessageEvent<C: RedactedMessageEventContent> { pub struct RedactedSyncMessageEvent<C: RedactedMessageEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
@ -120,7 +132,11 @@ pub struct RedactedSyncMessageEvent<C: RedactedMessageEventContent> {
pub unsigned: RedactedSyncUnsigned, pub unsigned: RedactedSyncUnsigned,
} }
/// State event. /// A state event.
///
/// `StateEvent` implements the comparison traits using only
/// the `event_id` field, a sorted list would be sorted lexicographically based on
/// the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct StateEvent<C: StateEventContent> { pub struct StateEvent<C: StateEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
@ -152,6 +168,10 @@ pub struct StateEvent<C: StateEventContent> {
} }
/// A state event without a `room_id`. /// A state event without a `room_id`.
///
/// `SyncStateEvent` implements the comparison traits using only
/// the `event_id` field, a sorted list would be sorted lexicographically based on
/// the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct SyncStateEvent<C: StateEventContent> { pub struct SyncStateEvent<C: StateEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
@ -197,6 +217,10 @@ pub struct StrippedStateEvent<C: StateEventContent> {
} }
/// A redacted state event. /// A redacted state event.
///
/// `RedactedStateEvent` implements the comparison traits using only
/// the `event_id` field, a sorted list would be sorted lexicographically based on
/// the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct RedactedStateEvent<C: RedactedStateEventContent> { pub struct RedactedStateEvent<C: RedactedStateEventContent> {
/// Data specific to the event type. /// Data specific to the event type.
@ -225,6 +249,10 @@ pub struct RedactedStateEvent<C: RedactedStateEventContent> {
} }
/// A redacted state event without a `room_id`. /// A redacted state event without a `room_id`.
///
/// `RedactedSyncStateEvent` implements the comparison traits using only
/// the `event_id` field, a sorted list would be sorted lexicographically based on
/// the event's `EventId`.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct RedactedSyncStateEvent<C: RedactedStateEventContent> { pub struct RedactedSyncStateEvent<C: RedactedStateEventContent> {
/// Data specific to the event type. /// Data specific to the event type.