Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to new intra-doc links, make events non-exhaustive. #19

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/driver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Config {
/// driver is actively connected, but will apply to subsequent
/// sessions.
///
/// [`CryptoMode::Normal`]: enum.CryptoMode.html#variant.Normal
/// [`CryptoMode::Normal`]: CryptoMode::Normal
pub crypto_mode: CryptoMode,
/// Configures whether decoding and decryption occur for all received packets.
///
Expand All @@ -24,10 +24,10 @@ pub struct Config {
/// Defaults to [`DecodeMode::Decrypt`]. This is due to per-packet decoding costs,
/// which most users will not want to pay, but allowing speaking events which are commonly used.
///
/// [`DecodeMode::Decode`]: enum.DecodeMode.html#variant.Decode
/// [`DecodeMode::Decrypt`]: enum.DecodeMode.html#variant.Decrypt
/// [`DecodeMode::Pass`]: enum.DecodeMode.html#variant.Pass
/// [user speaking events]: ../events/enum.CoreEvent.html#variant.SpeakingUpdate
/// [`DecodeMode::Decode`]: DecodeMode::Decode
/// [`DecodeMode::Decrypt`]: DecodeMode::Decrypt
/// [`DecodeMode::Pass`]: DecodeMode::Pass
/// [user speaking events]: crate::events::CoreEvent::SpeakingUpdate
pub decode_mode: DecodeMode,
/// Number of concurrently active tracks to allocate memory for.
///
Expand Down
2 changes: 1 addition & 1 deletion src/driver/decode_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum DecodeMode {
/// are not present, as they are encrypted.
/// This event requires such functionality.*
///
/// [user speaking events]: ../events/enum.CoreEvent.html#variant.SpeakingUpdate
/// [user speaking events]: crate::events::CoreEvent::SpeakingUpdate
Pass,
/// Decrypts the body of each received packet.
///
Expand Down
34 changes: 17 additions & 17 deletions src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ impl Driver {
///
/// This can be a source created via [`ffmpeg`] or [`ytdl`].
///
/// [`ffmpeg`]: ../input/fn.ffmpeg.html
/// [`ytdl`]: ../input/fn.ytdl.html
/// [`ffmpeg`]: crate::input::ffmpeg
/// [`ytdl`]: crate::input::ytdl
#[instrument(skip(self))]
pub fn play_source(&mut self, source: Input) -> TrackHandle {
let (player, handle) = super::create_player(source);
Expand All @@ -140,7 +140,7 @@ impl Driver {
/// Unlike [`play_source`], this stops all other sources attached
/// to the channel.
///
/// [`play_source`]: #method.play_source
/// [`play_source`]: Driver::play_source
#[instrument(skip(self))]
pub fn play_only_source(&mut self, source: Input) -> TrackHandle {
let (player, handle) = super::create_player(source);
Expand All @@ -156,9 +156,9 @@ impl Driver {
/// that this allows for direct manipulation of the [`Track`] object
/// before it is passed over to the voice and mixing contexts.
///
/// [`create_player`]: ../tracks/fn.create_player.html
/// [`Track`]: ../tracks/struct.Track.html
/// [`play_source`]: #method.play_source
/// [`create_player`]: crate::tracks::create_player
/// [`create_player`]: crate::tracks::Track
/// [`play_source`]: Driver::play_source
#[instrument(skip(self))]
pub fn play(&mut self, track: Track) {
self.send(CoreMessage::AddTrack(track));
Expand All @@ -171,10 +171,10 @@ impl Driver {
/// channel. Like [`play`], however, this allows for direct manipulation of the
/// [`Track`] object before it is passed over to the voice and mixing contexts.
///
/// [`create_player`]: ../tracks/fn.create_player.html
/// [`Track`]: ../tracks/struct.Track.html
/// [`play_only_source`]: #method.play_only_source
/// [`play`]: #method.play
/// [`create_player`]: crate::tracks::create_player
/// [`Track`]: crate::tracks::Track
/// [`play_only_source`]: Driver::play_only_source
/// [`play`]: Driver::play
#[instrument(skip(self))]
pub fn play_only(&mut self, track: Track) {
self.send(CoreMessage::SetTrack(Some(track)));
Expand Down Expand Up @@ -216,9 +216,9 @@ impl Driver {
/// within the supplied function or closure. *Taking excess time could prevent
/// timely sending of packets, causing audio glitches and delays*.
///
/// [`Track`]: ../tracks/struct.Track.html
/// [`TrackEvent`]: ../events/enum.TrackEvent.html
/// [`EventContext`]: ../events/enum.EventContext.html
/// [`Track`]: crate::tracks::Track
/// [`TrackEvent`]: crate::events::TrackEvent
/// [`EventContext`]: crate::events::EventContext
#[instrument(skip(self, action))]
pub fn add_global_event<F: EventHandler + 'static>(&mut self, event: Event, action: F) {
self.send(CoreMessage::AddEvent(EventData::new(event, action)));
Expand All @@ -243,8 +243,8 @@ impl Driver {
/// Queue additions should be made via [`enqueue`] and
/// [`enqueue_source`].
///
/// [`enqueue`]: #method.enqueue
/// [`enqueue_source`]: #method.enqueue_source
/// [`enqueue`]: Driver::enqueue
/// [`enqueue_source`]: Driver::enqueue_source
pub fn queue(&self) -> &TrackQueue {
&self.queue
}
Expand All @@ -253,7 +253,7 @@ impl Driver {
///
/// Requires the `"builtin-queue"` feature.
///
/// [`Input`]: ../input/struct.input.html
/// [`Input`]: crate::input::Input
pub fn enqueue_source(&mut self, source: Input) {
let (mut track, _) = tracks::create_player(source);
self.queue.add_raw(&mut track);
Expand All @@ -264,7 +264,7 @@ impl Driver {
///
/// Requires the `"builtin-queue"` feature.
///
/// [`Track`]: ../tracks/struct.track.html
/// [`Track`]: crate::tracks::Track
pub fn enqueue(&mut self, mut track: Track) {
self.queue.add_raw(&mut track);
self.play(track);
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum JoinError {
NoSender,
/// Tried to leave a [`Call`] which was not found.
///
/// [`Call`]: ../struct.Call.html
/// [`Call`]: crate::Call
NoCall,
#[cfg(feature = "serenity")]
/// Serenity-specific WebSocket send error.
Expand Down
11 changes: 6 additions & 5 deletions src/events/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/events/core.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
8 changes: 4 additions & 4 deletions src/events/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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*.
Expand All @@ -41,15 +42,15 @@ 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.
///
/// 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
Expand All @@ -58,15 +59,15 @@ pub enum Event {
/// Track events persist while the `action` in [`EventData`]
/// returns `None`.
///
/// [`EventData`]: struct.EventData.html
/// [`EventData`]: EventData
Track(TrackEvent),
/// Core events
///
/// Track events persist while the `action` in [`EventData`]
/// 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,
Expand Down
6 changes: 3 additions & 3 deletions src/events/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand All @@ -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,
Expand All @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions src/events/track.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/events/untimed.rs
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
30 changes: 12 additions & 18 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ enum Return {
/// If the `"driver"` feature is enabled, then a Call exposes all control methods of
/// [`Driver`] via `Deref(Mut)`.
///
/// [`Driver`]: driver/struct.Driver.html
/// [`Shard`]: ../gateway/struct.Shard.html
/// [`Driver`]: struct@Driver
#[derive(Clone, Debug)]
pub struct Call {
connection: Option<(ChannelId, ConnectionProgress, Return)>,
Expand All @@ -45,11 +44,14 @@ pub struct Call {
/// Whether the current handler is set to mute voice connections.
self_mute: bool,
user_id: UserId,
/// Will be set when a `Call` is made via the [`new`][`Call::new`]
/// Will be set when a `Call` is made via the [`new`]
/// method.
///
/// When set via [`standalone`][`Call::standalone`], it will not be
/// When set via [`standalone`](`Call::standalone`), it will not be
/// present.
///
/// [`new`]: Call::new
/// [`standalone`]: Call::standalone
ws: Option<Shard>,
}

Expand Down Expand Up @@ -153,7 +155,7 @@ impl Call {
/// **Note**: If the `Call` was created via [`standalone`], then this
/// will _only_ update whether the connection is internally deafened.
///
/// [`standalone`]: #method.standalone
/// [`standalone`]: Call::standalone
#[instrument(skip(self))]
pub async fn deafen(&mut self, deaf: bool) -> JoinResult<()> {
self.self_deaf = deaf;
Expand Down Expand Up @@ -217,7 +219,7 @@ impl Call {
/// will _only_ update whether the connection is internally connected to a
/// voice channel.
///
/// [`standalone`]: #method.standalone
/// [`standalone`]: Call::standalone
#[instrument(skip(self))]
pub async fn leave(&mut self) -> JoinResult<()> {
// Only send an update if we were in a voice channel.
Expand All @@ -237,7 +239,7 @@ impl Call {
/// **Note**: If the `Call` was created via [`standalone`], then this
/// will _only_ update whether the connection is internally muted.
///
/// [`standalone`]: #method.standalone
/// [`standalone`]: Call::standalone
#[instrument(skip(self))]
pub async fn mute(&mut self, mute: bool) -> JoinResult<()> {
self.self_mute = mute;
Expand All @@ -259,11 +261,7 @@ impl Call {
/// You should only need to use this if you initialized the `Call` via
/// [`standalone`].
///
/// Refer to the documentation for [`connect`] for when this will
/// automatically connect to a voice channel.
///
/// [`connect`]: #method.connect
/// [`standalone`]: #method.standalone
/// [`standalone`]: Call::standalone
#[instrument(skip(self, token))]
pub fn update_server(&mut self, endpoint: String, token: String) {
let try_conn = if let Some((_, ref mut progress, _)) = self.connection.as_mut() {
Expand All @@ -282,11 +280,7 @@ impl Call {
/// You should only need to use this if you initialized the `Call` via
/// [`standalone`].
///
/// refer to the documentation for [`connect`] for when this will
/// automatically connect to a voice channel.
///
/// [`connect`]: #method.connect
/// [`standalone`]: #method.standalone
/// [`standalone`]: Call::standalone
#[instrument(skip(self))]
pub fn update_state(&mut self, session_id: String) {
let try_conn = if let Some((_, ref mut progress, _)) = self.connection.as_mut() {
Expand All @@ -304,7 +298,7 @@ impl Call {
///
/// Does nothing if initialized via [`standalone`].
///
/// [`standalone`]: #method.standalone
/// [`standalone`]: Call::standalone
#[instrument(skip(self))]
async fn update(&mut self) -> JoinResult<()> {
if let Some(ws) = self.ws.as_mut() {
Expand Down
Loading