Return an EventType from Event::event_type.

This commit is contained in:
Jimmy Cuadra 2015-11-30 00:05:53 -08:00
parent 149bf66da8
commit 0270e84a1d
15 changed files with 68 additions and 68 deletions

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.answer* event.
use core::{Event, RoomEvent};
use core::{Event, EventType, RoomEvent};
use super::{SessionDescription, SessionDescriptionType};
/// This event is sent by the callee when they wish to answer the call.
@ -16,8 +16,8 @@ impl<'a> Event<'a, AnswerEventContent<'a>> for AnswerEvent<'a> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.call.answer"
fn event_type(&self) -> EventType {
EventType::CallAnswer
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.candidates* event.
use core::{Event, RoomEvent};
use core::{Event, EventType, RoomEvent};
/// This event is sent by callers after sending an invite and by the callee after answering.
/// Its purpose is to give the other party additional ICE candidates to try using to communicate.
@ -16,8 +16,8 @@ impl<'a> Event<'a, CandidatesEventContent<'a>> for CandidatesEvent<'a> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.call.candidates"
fn event_type(&self) -> EventType {
EventType::CallCandidates
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.hangup* event.
use core::{Event, RoomEvent};
use core::{Event, EventType, RoomEvent};
/// Sent by either party to signal their termination of the call. This can be sent either once the
/// call has has been established or before to abort the call.
@ -16,8 +16,8 @@ impl<'a> Event<'a, HangupEventContent<'a>> for HangupEvent<'a> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.call.hangup"
fn event_type(&self) -> EventType {
EventType::CallHangup
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.call.invite* event.
use core::{Event, RoomEvent};
use core::{Event, EventType, RoomEvent};
use super::{SessionDescription, SessionDescriptionType};
/// This event is sent by the caller when they wish to establish a call.
@ -16,8 +16,8 @@ impl<'a> Event<'a, InviteEventContent<'a>> for InviteEvent<'a> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.call.invite"
fn event_type(&self) -> EventType {
EventType::CallInvite
}
}

View File

@ -1,11 +1,37 @@
//! Traits for the basic kinds of events.
//! Types for the basic kinds of events.
/// The type of an event.
pub enum EventType {
CallAnswer,
CallCandidates,
CallHangup,
CallInvite,
Presence,
Receipt,
RoomAliases,
RoomAvatar,
RoomCanonicalAlias,
RoomCreate,
RoomGuestAccess,
RoomHistoryVisibility,
RoomJoinRules,
RoomMember,
RoomMessage,
RoomMessageFeedback,
RoomName,
RoomPowerLevels,
RoomRedaction,
RoomThirdPartyInvite,
RoomTopic,
Typing,
}
/// Functionality common to all events.
pub trait Event<'a, T> {
/// The primary event payload.
fn content(&'a self) -> &'a T;
/// The type of event, e.g. *com.example.subdomain.event.type*.
fn event_type(&self) -> &'static str;
/// The type of event.
fn event_type(&self) -> EventType;
}
/// An event emitted within the context of a room.

View File

@ -7,29 +7,3 @@ pub mod presence;
pub mod receipt;
pub mod room;
pub mod typing;
/// The type of an event.
pub enum EventTypes {
CallAnswer,
CallCandidates,
CallHangup,
CallInvite,
Presence,
Receipt,
RoomAliases,
RoomAvatar,
RoomCanonicalAlias,
RoomCreate,
RoomGuestAccess,
RoomHistoryVisibility,
RoomJoinRules,
RoomMember,
RoomMessage,
RoomMessageFeedback,
RoomName,
RoomPowerLevels,
RoomRedaction,
RoomThirdPartyInvite,
RoomTopic,
Typing,
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.presence* event.
use core::Event;
use core::{Event, EventType};
/// Informs the client of a user's presence state change.
pub struct PresenceEvent<'a> {
@ -13,8 +13,8 @@ impl<'a> Event<'a, PresenceEventContent<'a>> for PresenceEvent<'a> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.presence"
fn event_type(&self) -> EventType {
EventType::Presence
}
}

View File

@ -2,7 +2,7 @@
use std::collections::HashMap;
use core::Event;
use core::{Event, EventType};
/// Informs the client of new receipts.
pub struct ReceiptEvent<'a> {
@ -15,8 +15,8 @@ impl<'a> Event<'a, ReceiptEventContent<'a>> for ReceiptEvent<'a> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.receipt"
fn event_type(&self) -> EventType {
EventType::Receipt
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.aliases* event.
use core::{Event, RoomEvent, StateEvent};
use core::{Event, EventType, RoomEvent, StateEvent};
/// Informs the room about what room aliases it has been given.
pub struct AliasesEvent<'a, 'b> {
@ -18,8 +18,8 @@ impl<'a, 'b> Event<'a, AliasesEventContent<'a>> for AliasesEvent<'a, 'b> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.room.aliases"
fn event_type(&self) -> EventType {
EventType::RoomAliases
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.avatar* event.
use core::{Event, RoomEvent, StateEvent};
use core::{Event, EventType, RoomEvent, StateEvent};
use super::ImageInfo;
/// A picture that is associated with the room.
@ -19,8 +19,8 @@ impl<'a, 'b> Event<'a, AvatarEventContent<'a>> for AvatarEvent<'a, 'b> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.room.avatar"
fn event_type(&self) -> EventType {
EventType::RoomAvatar
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.canonical_alias* event.
use core::{Event, RoomEvent, StateEvent};
use core::{Event, EventType, RoomEvent, StateEvent};
/// Informs the room as to which alias is the canonical one.
pub struct CanonicalAliasEvent<'a, 'b> {
@ -16,8 +16,8 @@ impl<'a, 'b> Event<'a, CanonicalAliasEventContent<'a>> for CanonicalAliasEvent<'
&self.content
}
fn event_type(&self) -> &'static str {
"m.room.canonical_alias"
fn event_type(&self) -> EventType {
EventType::RoomCanonicalAlias
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.create* event.
use core::{Event, RoomEvent, StateEvent};
use core::{Event, EventType, RoomEvent, StateEvent};
/// This is the first event in a room and cannot be changed. It acts as the root of all other
/// events.
@ -17,8 +17,8 @@ impl<'a, 'b> Event<'a, CreateEventContent<'a>> for CreateEvent<'a, 'b> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.room.create"
fn event_type(&self) -> EventType {
EventType::RoomCreate
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.history_visibility* event.
use core::{Event, RoomEvent, StateEvent};
use core::{Event, EventType, RoomEvent, StateEvent};
/// This event controls whether a member of a room can see the events that happened in a room from
/// before they joined.
@ -17,8 +17,8 @@ impl<'a, 'b> Event<'a, HistoryVisibilityEventContent<'a>> for HistoryVisibilityE
&self.content
}
fn event_type(&self) -> &'static str {
"m.room.history_visibility"
fn event_type(&self) -> EventType {
EventType::RoomHistoryVisibility
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.room.join_rules* event.
use core::{Event, RoomEvent, StateEvent};
use core::{Event, EventType, RoomEvent, StateEvent};
/// Describes how users are allowed to join the room.
pub struct JoinRulesEvent<'a, 'b> {
@ -16,8 +16,8 @@ impl<'a, 'b> Event<'a, JoinRulesEventContent<'a>> for JoinRulesEvent<'a, 'b> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.room.join_rules"
fn event_type(&self) -> EventType {
EventType::RoomJoinRules
}
}

View File

@ -1,6 +1,6 @@
//! Types for the *m.typing* event.
use core::Event;
use core::{Event, EventType};
/// Informs the client of the list of users currently typing.
pub struct TypingEvent<'a> {
@ -15,8 +15,8 @@ impl<'a> Event<'a, TypingEventContent<'a>> for TypingEvent<'a> {
&self.content
}
fn event_type(&self) -> &'static str {
"m.typing"
fn event_type(&self) -> EventType {
EventType::Typing
}
}