From 0beb0f0d760fbd84f3f4abcb68fa8e71a667e896 Mon Sep 17 00:00:00 2001 From: Gnome! <45660393+GnomedDev@users.noreply.github.com> Date: Mon, 25 Jul 2022 14:20:58 +0100 Subject: [PATCH] Input: lazy_static -> once_cell::sync::Lazy (#136) --- Cargo.toml | 6 +----- src/config.rs | 4 ++-- src/input/codecs/mod.rs | 37 ++++++++++++++++--------------------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3448d6e..90ef9d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,10 +59,6 @@ version = "0.10" [dependencies.futures] version = "0.3" -[dependencies.lazy_static] -optional = true -version = "1" - [dependencies.parking_lot] optional = true version = "0.12" @@ -194,7 +190,7 @@ driver = [ "discortp", "reqwest", "flume", - "lazy_static", + "once_cell", "parking_lot", "rand", "ringbuf", diff --git a/src/config.rs b/src/config.rs index 2265ca8..4e2249f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -200,14 +200,14 @@ impl Config { /// Sets this `Config`'s symphonia codec registry. #[must_use] - pub fn codec_registry(mut self, codec_registry: &'static CODEC_REGISTRY) -> Self { + pub fn codec_registry(mut self, codec_registry: &'static CodecRegistry) -> Self { self.codec_registry = codec_registry; self } /// Sets this `Config`'s symphonia format registry/probe set. #[must_use] - pub fn format_registry(mut self, format_registry: &'static PROBE) -> Self { + pub fn format_registry(mut self, format_registry: &'static Probe) -> Self { self.format_registry = format_registry; self } diff --git a/src/input/codecs/mod.rs b/src/input/codecs/mod.rs index b919816..a71d079 100644 --- a/src/input/codecs/mod.rs +++ b/src/input/codecs/mod.rs @@ -5,30 +5,25 @@ mod opus; mod raw; pub use self::{dca::DcaReader, opus::OpusDecoder, raw::*}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use symphonia::{ core::{codecs::CodecRegistry, probe::Probe}, default::*, }; -lazy_static! { - /// Default Symphonia CodecRegistry, including the (audiopus-backed) - /// Opus codec. - pub static ref CODEC_REGISTRY: CodecRegistry = { - let mut registry = CodecRegistry::new(); - register_enabled_codecs(&mut registry); - registry.register_all::(); - registry - }; -} +/// Default Symphonia [`CodecRegistry`], including the (audiopus-backed) Opus codec. +pub static CODEC_REGISTRY: Lazy = Lazy::new(|| { + let mut registry = CodecRegistry::new(); + register_enabled_codecs(&mut registry); + registry.register_all::(); + registry +}); -lazy_static! { - /// Default Symphonia Probe, including DCA format support. - pub static ref PROBE: Probe = { - let mut probe = Probe::default(); - probe.register_all::(); - probe.register_all::(); - register_enabled_formats(&mut probe); - probe - }; -} +/// Default Symphonia Probe, including DCA format support. +pub static PROBE: Lazy = Lazy::new(|| { + let mut probe = Probe::default(); + probe.register_all::(); + probe.register_all::(); + register_enabled_formats(&mut probe); + probe +});