Docs: Move to new intra-doc links, make events non-exhaustive. (#19)
Far cleaner and more reliable than the old doc-link pattern. Also allowed me to spot some event types and sources which should have been made non_exhaustive.
This commit is contained in:
@@ -8,17 +8,18 @@ use discortp::{rtcp::Rtcp, rtp::Rtp};
|
||||
/// Information about which tracks or data fired an event.
|
||||
///
|
||||
/// [`Track`] events may be local or global, and have no tracks
|
||||
/// if fired on the global context via [`Handler::add_global_event`].
|
||||
/// if fired on the global context via [`Driver::add_global_event`].
|
||||
///
|
||||
/// [`Track`]: ../tracks/struct.Track.html
|
||||
/// [`Handler::add_global_event`]: ../struct.Handler.html#method.add_global_event
|
||||
/// [`Track`]: crate::tracks::Track
|
||||
/// [`Driver::add_global_event`]: crate::driver::Driver::add_global_event
|
||||
#[derive(Clone, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum EventContext<'a> {
|
||||
/// Track event context, passed to events created via [`TrackHandle::add_event`],
|
||||
/// [`EventStore::add_event`], or relevant global events.
|
||||
///
|
||||
/// [`EventStore::add_event`]: struct.EventStore.html#method.add_event
|
||||
/// [`TrackHandle::add_event`]: ../tracks/struct.TrackHandle.html#method.add_event
|
||||
/// [`EventStore::add_event`]: EventStore::add_event
|
||||
/// [`TrackHandle::add_event`]: TrackHandle::add_event
|
||||
Track(&'a [(&'a TrackState, &'a TrackHandle)]),
|
||||
/// Speaking state update, typically describing how another voice
|
||||
/// user is transmitting audio data. Clients must send at least one such
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
/// Voice core events occur on receipt of
|
||||
/// voice packets and telemetry.
|
||||
///
|
||||
/// Core events persist while the `action` in [`EventData`]
|
||||
/// returns `None`.
|
||||
///
|
||||
/// [`EventData`]: struct.EventData.html
|
||||
/// [`EventData`]: super::EventData
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum CoreEvent {
|
||||
/// Fired on receipt of a speaking state update from another host.
|
||||
///
|
||||
|
||||
@@ -17,10 +17,10 @@ impl EventData {
|
||||
/// Event handlers will be re-added with their new trigger condition,
|
||||
/// or removed if [`Cancel`]led
|
||||
///
|
||||
/// [`EventContext`]: enum.EventContext.html
|
||||
/// [`Event`]: enum.Event.html
|
||||
/// [`Delayed`]: enum.Event.html#variant.Delayed
|
||||
/// [`Cancel`]: enum.Event.html#variant.Cancel
|
||||
/// [`EventContext`]: EventContext
|
||||
/// [`Event`]: Event
|
||||
/// [`Delayed`]: Event::Delayed
|
||||
/// [`Cancel`]: Event::Cancel
|
||||
pub fn new<F: EventHandler + 'static>(event: Event, action: F) -> Self {
|
||||
Self {
|
||||
event,
|
||||
|
||||
@@ -12,16 +12,15 @@ pub use self::{context::*, core::*, data::*, store::*, track::*, untimed::*};
|
||||
use async_trait::async_trait;
|
||||
use std::time::Duration;
|
||||
|
||||
#[async_trait]
|
||||
/// Trait to handle an event which can be fired per-track, or globally.
|
||||
///
|
||||
/// These may be feasibly reused between several event sources.
|
||||
#[async_trait]
|
||||
pub trait EventHandler: Send + Sync {
|
||||
/// Respond to one received event.
|
||||
async fn act(&self, ctx: &EventContext<'_>) -> Option<Event>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
/// Classes of event which may occur, triggering a handler
|
||||
/// at the local (track-specific) or global level.
|
||||
///
|
||||
@@ -32,7 +31,9 @@ pub trait EventHandler: Send + Sync {
|
||||
///
|
||||
/// Event handlers themselves are described in [`EventData::action`].
|
||||
///
|
||||
/// [`EventData::action`]: struct.EventData.html#method.action
|
||||
/// [`EventData::action`]: EventData::action
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum Event {
|
||||
/// Periodic events rely upon two parameters: a *period*
|
||||
/// and an optional *phase*.
|
||||
@@ -41,7 +42,7 @@ pub enum Event {
|
||||
/// in one *period*. Periodic events repeat automatically
|
||||
/// so long as the `action` in [`EventData`] returns `None`.
|
||||
///
|
||||
/// [`EventData`]: struct.EventData.html
|
||||
/// [`EventData`]: EventData
|
||||
Periodic(Duration, Option<Duration>),
|
||||
/// Delayed events rely upon a *delay* parameter, and
|
||||
/// fire one *delay* after the audio context processes them.
|
||||
@@ -49,7 +50,7 @@ pub enum Event {
|
||||
/// Delayed events are automatically removed once fired,
|
||||
/// so long as the `action` in [`EventData`] returns `None`.
|
||||
///
|
||||
/// [`EventData`]: struct.EventData.html
|
||||
/// [`EventData`]: EventData
|
||||
Delayed(Duration),
|
||||
/// Track events correspond to certain actions or changes
|
||||
/// of state, such as a track finishing, looping, or being
|
||||
@@ -58,7 +59,7 @@ pub enum Event {
|
||||
/// Track events persist while the `action` in [`EventData`]
|
||||
/// returns `None`.
|
||||
///
|
||||
/// [`EventData`]: struct.EventData.html
|
||||
/// [`EventData`]: EventData
|
||||
Track(TrackEvent),
|
||||
/// Core events
|
||||
///
|
||||
@@ -66,7 +67,7 @@ pub enum Event {
|
||||
/// returns `None`. Core events **must** be applied globally,
|
||||
/// as attaching them to a track is a no-op.
|
||||
///
|
||||
/// [`EventData`]: struct.EventData.html
|
||||
/// [`EventData`]: EventData
|
||||
Core(CoreEvent),
|
||||
/// Cancels the event, if it was intended to persist.
|
||||
Cancel,
|
||||
|
||||
@@ -15,7 +15,7 @@ use tracing::info;
|
||||
/// Timed events are stored in a binary heap for fast selection, and have custom `Eq`,
|
||||
/// `Ord`, etc. implementations to support (only) this.
|
||||
///
|
||||
/// [`EventData`]: struct.EventData.html
|
||||
/// [`EventData`]: EventData
|
||||
pub struct EventStore {
|
||||
timed: BinaryHeap<EventData>,
|
||||
untimed: HashMap<UntimedEvent, Vec<EventData>>,
|
||||
@@ -33,7 +33,7 @@ impl EventStore {
|
||||
/// This is usually automatically installed by the driver once
|
||||
/// a track has been registered.
|
||||
///
|
||||
/// [`Track`]: ../tracks/struct.Track.html
|
||||
/// [`Track`]: crate::tracks::Track
|
||||
pub fn new_local() -> Self {
|
||||
EventStore {
|
||||
local_only: true,
|
||||
@@ -45,7 +45,7 @@ impl EventStore {
|
||||
///
|
||||
/// Updates `evt` according to [`EventData::compute_activation`].
|
||||
///
|
||||
/// [`EventData::compute_activation`]: struct.EventData.html#method.compute_activation
|
||||
/// [`EventData::compute_activation`]: EventData::compute_activation
|
||||
pub fn add_event(&mut self, mut evt: EventData, now: Duration) {
|
||||
evt.compute_activation(now);
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
/// Track events correspond to certain actions or changes
|
||||
/// of state, such as a track finishing, looping, or being
|
||||
/// manually stopped. Voice core events occur on receipt of
|
||||
@@ -7,7 +6,9 @@
|
||||
/// Track events persist while the `action` in [`EventData`]
|
||||
/// returns `None`.
|
||||
///
|
||||
/// [`EventData`]: struct.EventData.html
|
||||
/// [`EventData`]: super::EventData
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum TrackEvent {
|
||||
/// The attached track has ended.
|
||||
End,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
/// Track and voice core events.
|
||||
///
|
||||
/// Untimed events persist while the `action` in [`EventData`]
|
||||
/// returns `None`.
|
||||
///
|
||||
/// [`EventData`]: struct.EventData.html
|
||||
/// [`EventData`]: EventData
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum UntimedEvent {
|
||||
/// Untimed events belonging to a track, such as state changes, end, or loops.
|
||||
Track(TrackEvent),
|
||||
|
||||
Reference in New Issue
Block a user