aboutsummaryrefslogtreecommitdiff
path: root/src/voice
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-07-04 21:28:22 -0700
committerZeyla Hellyer <[email protected]>2018-07-04 21:32:17 -0700
commit7b9764cf1097b0620d871fabe67b5593f0cd4a4a (patch)
tree5b9f3eac6e9c57ac255c73bd1eea07669838f32d /src/voice
parentFix dead doc-links and add missing ones. (#347) (diff)
downloadserenity-7b9764cf1097b0620d871fabe67b5593f0cd4a4a.tar.xz
serenity-7b9764cf1097b0620d871fabe67b5593f0cd4a4a.zip
Monomorphize all functions
This commit monomorphizes all functions, turning functions like: ```rust fn foo<T: Into<Bar>>(baz: T) { baz = baz.into(); // function here } ``` Into functions like: ```rust fn foo<T: Into<Bar>>(baz: T) { _foo(baz.into()) } fn _foo(baz: Bar) { // function here } ``` This avoids binary bloat and improves build times, by reducing the amount of code duplication.
Diffstat (limited to 'src/voice')
-rw-r--r--src/voice/manager.rs36
-rw-r--r--src/voice/streamer.rs10
2 files changed, 38 insertions, 8 deletions
diff --git a/src/voice/manager.rs b/src/voice/manager.rs
index c3e3ba2..4d1a7c4 100644
--- a/src/voice/manager.rs
+++ b/src/voice/manager.rs
@@ -39,14 +39,24 @@ impl Manager {
}
/// Retrieves an immutable handler for the given target, if one exists.
+ #[inline]
pub fn get<G: Into<GuildId>>(&self, guild_id: G) -> Option<&Handler> {
- self.handlers.get(&guild_id.into())
+ self._get(guild_id.into())
+ }
+
+ fn _get(&self, guild_id: GuildId) -> Option<&Handler> {
+ self.handlers.get(&guild_id)
}
/// Retrieves a mutable handler for the given target, if one exists.
+ #[inline]
pub fn get_mut<G: Into<GuildId>>(&mut self, guild_id: G)
-> Option<&mut Handler> {
- self.handlers.get_mut(&guild_id.into())
+ self._get_mut(guild_id.into())
+ }
+
+ fn _get_mut(&mut self, guild_id: GuildId) -> Option<&mut Handler> {
+ self.handlers.get_mut(&guild_id)
}
/// Connects to a target by retrieving its relevant [`Handler`] and
@@ -71,11 +81,17 @@ impl Manager {
/// [`Handler`]: struct.Handler.html
/// [`get`]: #method.get
#[allow(map_entry)]
+ #[inline]
pub fn join<C, G>(&mut self, guild_id: G, channel_id: C) -> &mut Handler
where C: Into<ChannelId>, G: Into<GuildId> {
- let channel_id = channel_id.into();
- let guild_id = guild_id.into();
+ self._join(guild_id.into(), channel_id.into())
+ }
+ fn _join(
+ &mut self,
+ guild_id: GuildId,
+ channel_id: ChannelId,
+ ) -> &mut Handler {
{
let mut found = false;
@@ -111,8 +127,13 @@ impl Manager {
/// [`Handler`]: struct.Handler.html
/// [`get`]: #method.get
/// [`leave`]: struct.Handler.html#method.leave
+ #[inline]
pub fn leave<G: Into<GuildId>>(&mut self, guild_id: G) {
- if let Some(handler) = self.handlers.get_mut(&guild_id.into()) {
+ self._leave(guild_id.into())
+ }
+
+ fn _leave(&mut self, guild_id: GuildId) {
+ if let Some(handler) = self.handlers.get_mut(&guild_id) {
handler.leave();
}
}
@@ -123,9 +144,12 @@ impl Manager {
/// The handler is then dropped, removing settings for the target.
///
/// [`Handler`]: struct.Handler.html
+ #[inline]
pub fn remove<G: Into<GuildId>>(&mut self, guild_id: G) {
- let guild_id = guild_id.into();
+ self._remove(guild_id.into())
+ }
+ fn _remove(&mut self, guild_id: GuildId) {
self.leave(guild_id);
self.handlers.remove(&guild_id);
diff --git a/src/voice/streamer.rs b/src/voice/streamer.rs
index bf77b1d..cd7cae8 100644
--- a/src/voice/streamer.rs
+++ b/src/voice/streamer.rs
@@ -100,8 +100,10 @@ impl<R: Read + Send> AudioSource for InputSource<R> {
/// Opens an audio file through `ffmpeg` and creates an audio source.
pub fn ffmpeg<P: AsRef<OsStr>>(path: P) -> Result<Box<AudioSource>> {
- let path = path.as_ref();
+ _ffmpeg(path.as_ref())
+}
+fn _ffmpeg(path: &OsStr) -> Result<Box<AudioSource>> {
// Will fail if the path is not to a file on the fs. Likely a YouTube URI.
let is_stereo = is_stereo(path).unwrap_or(false);
let stereo_val = if is_stereo { "2" } else { "1" };
@@ -133,7 +135,11 @@ pub fn ffmpeg<P: AsRef<OsStr>>(path: P) -> Result<Box<AudioSource>> {
/// Creates a streamed audio source from a DCA file.
/// Currently only accepts the DCA1 format.
pub fn dca<P: AsRef<OsStr>>(path: P) -> StdResult<Box<AudioSource>, DcaError> {
- let file = File::open(path.as_ref()).map_err(DcaError::IoError)?;
+ _dca(path.as_ref())
+}
+
+fn _dca(path: &OsStr) -> StdResult<Box<AudioSource>, DcaError> {
+ let file = File::open(path).map_err(DcaError::IoError)?;
let mut reader = BufReader::new(file);