From 7230aee0693651a58e22a206491980cede5dbdbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 22 Jan 2020 19:38:13 +0200 Subject: [PATCH] Switch everything from lazy_static to once_cell::Lazy Fewer macros, faster compile-time and the Lazy type will likely end up in the standard library in a similar form to this. --- examples/Cargo.toml | 2 +- examples/src/bin/subclass.rs | 10 +- gstreamer-gl/Cargo.toml | 2 +- gstreamer-gl/src/caps_features.rs | 18 ++-- gstreamer-gl/src/gl_display.rs | 14 +-- gstreamer-gl/src/lib.rs | 3 +- gstreamer-rtsp-server/Cargo.toml | 2 +- gstreamer-rtsp-server/src/lib.rs | 117 +++++++++++------------ gstreamer-video/Cargo.toml | 2 +- gstreamer-video/src/lib.rs | 3 +- gstreamer-video/src/video_buffer_pool.rs | 34 +++---- gstreamer/Cargo.toml | 2 +- gstreamer/src/buffer.rs | 10 +- gstreamer/src/caps_features.rs | 18 ++-- gstreamer/src/element.rs | 64 ++++++------- gstreamer/src/lib.rs | 3 +- gstreamer/src/log.rs | 16 ++-- gstreamer/src/tags.rs | 8 +- gstreamer/src/value_serde.rs | 30 +++--- 19 files changed, 178 insertions(+), 180 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index b74bb34cd..04ef1b8dc 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -30,7 +30,7 @@ pango = { git = "https://github.com/gtk-rs/pango", optional = true } pangocairo = { git = "https://github.com/gtk-rs/pangocairo", optional = true } glutin = { version = "0.21", optional = true } winit = { version = "0.19", optional = true } -lazy_static = "1.0" +once_cell = "1.0" [build-dependencies] gl_generator = { version = "0.14", optional = true } diff --git a/examples/src/bin/subclass.rs b/examples/src/bin/subclass.rs index ec49b2541..61473a548 100644 --- a/examples/src/bin/subclass.rs +++ b/examples/src/bin/subclass.rs @@ -42,16 +42,16 @@ mod fir_filter { extern crate byte_slice_cast; use byte_slice_cast::*; - use lazy_static::lazy_static; + use once_cell::sync::Lazy; // The debug category we use below for our filter - lazy_static! { - pub static ref CAT: gst::DebugCategory = gst::DebugCategory::new( + pub static CAT: Lazy = Lazy::new(|| { + gst::DebugCategory::new( "rsfirfilter", gst::DebugColorFlags::empty(), Some("Rust FIR Filter"), - ); - } + ) + }); // In the imp submodule we include the actual implementation mod imp { diff --git a/gstreamer-gl/Cargo.toml b/gstreamer-gl/Cargo.toml index 464ffadfe..3521f6b93 100644 --- a/gstreamer-gl/Cargo.toml +++ b/gstreamer-gl/Cargo.toml @@ -17,7 +17,7 @@ build = "build.rs" bitflags = "1.0" byteorder = "1" libc = "0.2" -lazy_static = "1.0" +once_cell = "1.0" glib-sys = { git = "https://github.com/gtk-rs/sys" } gobject-sys = { git = "https://github.com/gtk-rs/sys" } gstreamer-sys = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys", features = ["v1_14"] } diff --git a/gstreamer-gl/src/caps_features.rs b/gstreamer-gl/src/caps_features.rs index de0d5b427..3727e3c07 100644 --- a/gstreamer-gl/src/caps_features.rs +++ b/gstreamer-gl/src/caps_features.rs @@ -10,12 +10,12 @@ use gst::CapsFeatures; use gst_gl_sys; use std::ffi::CStr; -lazy_static! { - pub static ref CAPS_FEATURE_MEMORY_GL_MEMORY: &'static str = unsafe { - CStr::from_ptr(gst_gl_sys::GST_CAPS_FEATURE_MEMORY_GL_MEMORY) - .to_str() - .unwrap() - }; - pub static ref CAPS_FEATURES_MEMORY_GL_MEMORY: CapsFeatures = - CapsFeatures::new(&[*CAPS_FEATURE_MEMORY_GL_MEMORY]); -} +use once_cell::sync::Lazy; + +pub static CAPS_FEATURE_MEMORY_GL_MEMORY: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_gl_sys::GST_CAPS_FEATURE_MEMORY_GL_MEMORY) + .to_str() + .unwrap() +}); +pub static CAPS_FEATURES_MEMORY_GL_MEMORY: Lazy = + Lazy::new(|| CapsFeatures::new(&[*CAPS_FEATURE_MEMORY_GL_MEMORY])); diff --git a/gstreamer-gl/src/gl_display.rs b/gstreamer-gl/src/gl_display.rs index c9d4f5fac..c0ebd840c 100644 --- a/gstreamer-gl/src/gl_display.rs +++ b/gstreamer-gl/src/gl_display.rs @@ -9,10 +9,10 @@ use gst_gl_sys; use std::ffi::CStr; -lazy_static! { - pub static ref GL_DISPLAY_CONTEXT_TYPE: &'static str = unsafe { - CStr::from_ptr(gst_gl_sys::GST_GL_DISPLAY_CONTEXT_TYPE) - .to_str() - .unwrap() - }; -} +use once_cell::sync::Lazy; + +pub static GL_DISPLAY_CONTEXT_TYPE: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_gl_sys::GST_GL_DISPLAY_CONTEXT_TYPE) + .to_str() + .unwrap() +}); diff --git a/gstreamer-gl/src/lib.rs b/gstreamer-gl/src/lib.rs index 95fa1f180..453cdab7b 100644 --- a/gstreamer-gl/src/lib.rs +++ b/gstreamer-gl/src/lib.rs @@ -10,9 +10,8 @@ #[macro_use] extern crate bitflags; extern crate byteorder; -#[macro_use] -extern crate lazy_static; extern crate libc; +extern crate once_cell; #[macro_use] extern crate glib; extern crate glib_sys; diff --git a/gstreamer-rtsp-server/Cargo.toml b/gstreamer-rtsp-server/Cargo.toml index 87ce6e0c2..7ac6d5493 100644 --- a/gstreamer-rtsp-server/Cargo.toml +++ b/gstreamer-rtsp-server/Cargo.toml @@ -15,7 +15,7 @@ build = "build.rs" [dependencies] bitflags = "1.0" libc = "0.2" -lazy_static = "1.0" +once_cell = "1.0" glib-sys = { git = "https://github.com/gtk-rs/sys" } gio-sys = { git = "https://github.com/gtk-rs/sys" } gobject-sys = { git = "https://github.com/gtk-rs/sys" } diff --git a/gstreamer-rtsp-server/src/lib.rs b/gstreamer-rtsp-server/src/lib.rs index 7f62ff28a..8889661d7 100644 --- a/gstreamer-rtsp-server/src/lib.rs +++ b/gstreamer-rtsp-server/src/lib.rs @@ -8,9 +8,8 @@ #[macro_use] extern crate bitflags; -#[macro_use] -extern crate lazy_static; extern crate libc; +extern crate once_cell; extern crate gio; extern crate gio_sys as gio_sys; @@ -71,63 +70,63 @@ pub use rtsp_stream_transport::RTSPStreamTransportExtManual; pub use rtsp_context::*; pub use rtsp_token::*; -lazy_static! { - pub static ref RTSP_ADDRESS_POOL_ANY_IPV4: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_ADDRESS_POOL_ANY_IPV4) - .to_str() - .unwrap() - }; - pub static ref RTSP_ADDRESS_POOL_ANY_IPV6: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_ADDRESS_POOL_ANY_IPV6) - .to_str() - .unwrap() - }; - pub static ref RTSP_AUTH_CHECK_CONNECT: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_CONNECT) - .to_str() - .unwrap() - }; - pub static ref RTSP_AUTH_CHECK_MEDIA_FACTORY_ACCESS: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_ACCESS) - .to_str() - .unwrap() - }; - pub static ref RTSP_AUTH_CHECK_MEDIA_FACTORY_CONSTRUCT: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_CONSTRUCT) - .to_str() - .unwrap() - }; - pub static ref RTSP_AUTH_CHECK_TRANSPORT_CLIENT_SETTINGS: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_TRANSPORT_CLIENT_SETTINGS) - .to_str() - .unwrap() - }; - pub static ref RTSP_AUTH_CHECK_URL: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_URL) - .to_str() - .unwrap() - }; - pub static ref RTSP_PERM_MEDIA_FACTORY_ACCESS: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_PERM_MEDIA_FACTORY_ACCESS) - .to_str() - .unwrap() - }; - pub static ref RTSP_PERM_MEDIA_FACTORY_CONSTRUCT: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT) - .to_str() - .unwrap() - }; - pub static ref RTSP_TOKEN_MEDIA_FACTORY_ROLE: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE) - .to_str() - .unwrap() - }; - pub static ref RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS: &'static str = unsafe { - CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS) - .to_str() - .unwrap() - }; -} +use once_cell::sync::Lazy; + +pub static RTSP_ADDRESS_POOL_ANY_IPV4: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_ADDRESS_POOL_ANY_IPV4) + .to_str() + .unwrap() +}); +pub static RTSP_ADDRESS_POOL_ANY_IPV6: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_ADDRESS_POOL_ANY_IPV6) + .to_str() + .unwrap() +}); +pub static RTSP_AUTH_CHECK_CONNECT: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_CONNECT) + .to_str() + .unwrap() +}); +pub static RTSP_AUTH_CHECK_MEDIA_FACTORY_ACCESS: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_ACCESS) + .to_str() + .unwrap() +}); +pub static RTSP_AUTH_CHECK_MEDIA_FACTORY_CONSTRUCT: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_MEDIA_FACTORY_CONSTRUCT) + .to_str() + .unwrap() +}); +pub static RTSP_AUTH_CHECK_TRANSPORT_CLIENT_SETTINGS: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_TRANSPORT_CLIENT_SETTINGS) + .to_str() + .unwrap() +}); +pub static RTSP_AUTH_CHECK_URL: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_AUTH_CHECK_URL) + .to_str() + .unwrap() +}); +pub static RTSP_PERM_MEDIA_FACTORY_ACCESS: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_PERM_MEDIA_FACTORY_ACCESS) + .to_str() + .unwrap() +}); +pub static RTSP_PERM_MEDIA_FACTORY_CONSTRUCT: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT) + .to_str() + .unwrap() +}); +pub static RTSP_TOKEN_MEDIA_FACTORY_ROLE: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE) + .to_str() + .unwrap() +}); +pub static RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_rtsp_server_sys::GST_RTSP_TOKEN_TRANSPORT_CLIENT_SETTINGS) + .to_str() + .unwrap() +}); // Re-export all the traits in a prelude module, so that applications // can always "use gst::prelude::*" without getting conflicts diff --git a/gstreamer-video/Cargo.toml b/gstreamer-video/Cargo.toml index 007d2a0b0..0ec9b8ed6 100644 --- a/gstreamer-video/Cargo.toml +++ b/gstreamer-video/Cargo.toml @@ -23,7 +23,7 @@ gstreamer-video-sys = { git = "https://gitlab.freedesktop.org/gstreamer/gstreame glib = { git = "https://github.com/gtk-rs/glib" } gstreamer = { path = "../gstreamer" } gstreamer-base = { path = "../gstreamer-base" } -lazy_static = "1.0" +once_cell = "1.0" [build-dependencies] rustdoc-stripper = { version = "0.1", optional = true } diff --git a/gstreamer-video/src/lib.rs b/gstreamer-video/src/lib.rs index 897319bce..8d41dddcd 100644 --- a/gstreamer-video/src/lib.rs +++ b/gstreamer-video/src/lib.rs @@ -8,9 +8,8 @@ #[macro_use] extern crate bitflags; -#[macro_use] -extern crate lazy_static; extern crate libc; +extern crate once_cell; #[macro_use] extern crate glib; diff --git a/gstreamer-video/src/video_buffer_pool.rs b/gstreamer-video/src/video_buffer_pool.rs index 317f2ba7d..5333c52e8 100644 --- a/gstreamer-video/src/video_buffer_pool.rs +++ b/gstreamer-video/src/video_buffer_pool.rs @@ -12,28 +12,30 @@ use std::mem; use glib::translate::*; -lazy_static! { - pub static ref BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META: &'static str = unsafe { +use once_cell::sync::Lazy; + +pub static BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META: Lazy<&'static str> = + Lazy::new(|| unsafe { CStr::from_ptr(gst_video_sys::GST_BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META) .to_str() .unwrap() - }; - pub static ref BUFFER_POOL_OPTION_VIDEO_ALIGNMENT: &'static str = unsafe { - CStr::from_ptr(gst_video_sys::GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT) - .to_str() - .unwrap() - }; - pub static ref BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META: &'static str = unsafe { + }); +pub static BUFFER_POOL_OPTION_VIDEO_ALIGNMENT: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_video_sys::GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT) + .to_str() + .unwrap() +}); +pub static BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META: Lazy<&'static str> = + Lazy::new(|| unsafe { CStr::from_ptr(gst_video_sys::GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META) .to_str() .unwrap() - }; - pub static ref BUFFER_POOL_OPTION_VIDEO_META: &'static str = unsafe { - CStr::from_ptr(gst_video_sys::GST_BUFFER_POOL_OPTION_VIDEO_META) - .to_str() - .unwrap() - }; -} + }); +pub static BUFFER_POOL_OPTION_VIDEO_META: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_video_sys::GST_BUFFER_POOL_OPTION_VIDEO_META) + .to_str() + .unwrap() +}); #[derive(Debug, Clone)] pub struct VideoAlignment(pub(crate) gst_video_sys::GstVideoAlignment); diff --git a/gstreamer/Cargo.toml b/gstreamer/Cargo.toml index 73d216c04..4228a6e27 100644 --- a/gstreamer/Cargo.toml +++ b/gstreamer/Cargo.toml @@ -21,7 +21,7 @@ gobject-sys = { git = "https://github.com/gtk-rs/sys" } gstreamer-sys = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys", features = ["v1_8"] } glib = { git = "https://github.com/gtk-rs/glib" } num-rational = { version = "0.2", default-features = false, features = [] } -lazy_static = "1.0" +once_cell = "1.0" futures-core = "0.3" futures-util = "0.3" futures-channel = "0.3" diff --git a/gstreamer/src/buffer.rs b/gstreamer/src/buffer.rs index 759315487..39c526f21 100644 --- a/gstreamer/src/buffer.rs +++ b/gstreamer/src/buffer.rs @@ -878,12 +878,10 @@ impl Eq for MappedBuffer {} unsafe impl Send for MappedBuffer {} unsafe impl Sync for MappedBuffer {} -lazy_static! { - pub static ref BUFFER_COPY_METADATA: ::BufferCopyFlags = - ::BufferCopyFlags::FLAGS | ::BufferCopyFlags::TIMESTAMPS | ::BufferCopyFlags::META; - pub static ref BUFFER_COPY_ALL: ::BufferCopyFlags = - *BUFFER_COPY_METADATA | ::BufferCopyFlags::MEMORY; -} +pub const BUFFER_COPY_METADATA: ::BufferCopyFlags = + ::BufferCopyFlags::from_bits_truncate(gst_sys::GST_BUFFER_COPY_METADATA); +pub const BUFFER_COPY_ALL: ::BufferCopyFlags = + ::BufferCopyFlags::from_bits_truncate(gst_sys::GST_BUFFER_COPY_ALL); #[cfg(test)] mod tests { diff --git a/gstreamer/src/caps_features.rs b/gstreamer/src/caps_features.rs index 5fef72ebb..4f16a8ac7 100644 --- a/gstreamer/src/caps_features.rs +++ b/gstreamer/src/caps_features.rs @@ -15,6 +15,8 @@ use std::ops::{Deref, DerefMut}; use std::ptr; use std::str; +use once_cell::sync::Lazy; + use glib; use glib::translate::{ from_glib, from_glib_full, from_glib_none, FromGlibPtrFull, FromGlibPtrNone, GlibPtrDefault, @@ -461,15 +463,13 @@ impl ToOwned for CapsFeaturesRef { unsafe impl Sync for CapsFeaturesRef {} unsafe impl Send for CapsFeaturesRef {} -lazy_static! { - pub static ref CAPS_FEATURE_MEMORY_SYSTEM_MEMORY: &'static str = unsafe { - CStr::from_ptr(gst_sys::GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY) - .to_str() - .unwrap() - }; - pub static ref CAPS_FEATURES_MEMORY_SYSTEM_MEMORY: CapsFeatures = - CapsFeatures::new(&[*CAPS_FEATURE_MEMORY_SYSTEM_MEMORY]); -} +pub static CAPS_FEATURE_MEMORY_SYSTEM_MEMORY: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_sys::GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY) + .to_str() + .unwrap() +}); +pub static CAPS_FEATURES_MEMORY_SYSTEM_MEMORY: Lazy = + Lazy::new(|| CapsFeatures::new(&[*CAPS_FEATURE_MEMORY_SYSTEM_MEMORY])); #[cfg(test)] mod tests { diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index cd1e4217e..99f7e6509 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -9,6 +9,8 @@ use Element; use ElementClass; +use once_cell::sync::Lazy; + use glib; #[cfg(any(feature = "v1_10", feature = "dox"))] use glib::object::Cast; @@ -845,38 +847,36 @@ impl ElementClass { } } -lazy_static! { - pub static ref ELEMENT_METADATA_AUTHOR: &'static str = unsafe { - CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_AUTHOR) - .to_str() - .unwrap() - }; - pub static ref ELEMENT_METADATA_DESCRIPTION: &'static str = unsafe { - CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_DESCRIPTION) - .to_str() - .unwrap() - }; - pub static ref ELEMENT_METADATA_DOC_URI: &'static str = unsafe { - CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_DOC_URI) - .to_str() - .unwrap() - }; - pub static ref ELEMENT_METADATA_ICON_NAME: &'static str = unsafe { - CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_ICON_NAME) - .to_str() - .unwrap() - }; - pub static ref ELEMENT_METADATA_KLASS: &'static str = unsafe { - CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_KLASS) - .to_str() - .unwrap() - }; - pub static ref ELEMENT_METADATA_LONGNAME: &'static str = unsafe { - CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_LONGNAME) - .to_str() - .unwrap() - }; -} +pub static ELEMENT_METADATA_AUTHOR: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_AUTHOR) + .to_str() + .unwrap() +}); +pub static ELEMENT_METADATA_DESCRIPTION: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_DESCRIPTION) + .to_str() + .unwrap() +}); +pub static ELEMENT_METADATA_DOC_URI: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_DOC_URI) + .to_str() + .unwrap() +}); +pub static ELEMENT_METADATA_ICON_NAME: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_ICON_NAME) + .to_str() + .unwrap() +}); +pub static ELEMENT_METADATA_KLASS: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_KLASS) + .to_str() + .unwrap() +}); +pub static ELEMENT_METADATA_LONGNAME: Lazy<&'static str> = Lazy::new(|| unsafe { + CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_LONGNAME) + .to_str() + .unwrap() +}); #[macro_export] macro_rules! gst_element_error( diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 74cb3d7b7..9d44c23db 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -12,9 +12,8 @@ extern crate bitflags; #[cfg(any(feature = "v1_14", feature = "dox"))] #[macro_use] extern crate cfg_if; -#[macro_use] -extern crate lazy_static; extern crate libc; +extern crate once_cell; extern crate thiserror; // Re-exported for the subclass gst_plugin_define! macro diff --git a/gstreamer/src/log.rs b/gstreamer/src/log.rs index a53adafd2..ac8cd1396 100644 --- a/gstreamer/src/log.rs +++ b/gstreamer/src/log.rs @@ -14,6 +14,8 @@ use std::ffi::CStr; use std::fmt; use std::ptr; +use once_cell::sync::Lazy; + use gobject_sys; use gst_sys; @@ -167,20 +169,18 @@ impl fmt::Debug for DebugCategory { } } -lazy_static! { - pub static ref CAT_RUST: DebugCategory = DebugCategory::new( +pub static CAT_RUST: Lazy = Lazy::new(|| { + DebugCategory::new( "GST_RUST", ::DebugColorFlags::UNDERLINE, Some("GStreamer's Rust binding core"), - ); -} + ) +}); macro_rules! declare_debug_category_from_name( ($cat:ident, $cat_name:expr) => ( - lazy_static! { - pub static ref $cat: DebugCategory = DebugCategory::get($cat_name) - .expect(&format!("Unable to find `DebugCategory` with name {}", $cat_name)); - } + pub static $cat: Lazy = Lazy::new(|| DebugCategory::get($cat_name) + .expect(&format!("Unable to find `DebugCategory` with name {}", $cat_name))); ); ); diff --git a/gstreamer/src/tags.rs b/gstreamer/src/tags.rs index dcf18a699..b8effe643 100644 --- a/gstreamer/src/tags.rs +++ b/gstreamer/src/tags.rs @@ -11,6 +11,8 @@ use std::fmt; use std::marker::PhantomData; use std::mem; +use once_cell::sync::Lazy; + use glib; use glib::translate::{ from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlibPtr, ToGlibPtrMut, @@ -42,10 +44,8 @@ macro_rules! impl_tag( } } - lazy_static! { - pub(crate) static ref $rust_tag: &'static str = - unsafe { CStr::from_ptr(gst_sys::$gst_tag).to_str().unwrap() }; - } + pub(crate) static $rust_tag: Lazy<&'static str> = Lazy::new(|| + unsafe { CStr::from_ptr(gst_sys::$gst_tag).to_str().unwrap() }); }; ); diff --git a/gstreamer/src/value_serde.rs b/gstreamer/src/value_serde.rs index 31b742797..3958c0912 100644 --- a/gstreamer/src/value_serde.rs +++ b/gstreamer/src/value_serde.rs @@ -18,6 +18,8 @@ use serde::ser::{Serialize, SerializeTuple, Serializer}; use std::{fmt, mem}; +use once_cell::sync::Lazy; + use Buffer; use DateTime; use Sample; @@ -32,20 +34,20 @@ fn get_other_type_id() -> usize { } } -lazy_static! { - pub(crate) static ref ARRAY_OTHER_TYPE_ID: usize = get_other_type_id::(); - pub(crate) static ref BITMASK_OTHER_TYPE_ID: usize = get_other_type_id::(); - pub(crate) static ref DATE_OTHER_TYPE_ID: usize = get_other_type_id::(); - pub(crate) static ref DATE_TIME_OTHER_TYPE_ID: usize = get_other_type_id::(); - pub(crate) static ref FRACTION_OTHER_TYPE_ID: usize = get_other_type_id::(); - pub(crate) static ref FRACTION_RANGE_OTHER_TYPE_ID: usize = - get_other_type_id::(); - pub(crate) static ref INT_RANGE_I32_OTHER_TYPE_ID: usize = get_other_type_id::>(); - pub(crate) static ref INT_RANGE_I64_OTHER_TYPE_ID: usize = get_other_type_id::>(); - pub(crate) static ref LIST_OTHER_TYPE_ID: usize = get_other_type_id::(); - pub(crate) static ref SAMPLE_OTHER_TYPE_ID: usize = get_other_type_id::(); - pub(crate) static ref BUFFER_OTHER_TYPE_ID: usize = get_other_type_id::(); -} +pub(crate) static ARRAY_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); +pub(crate) static BITMASK_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); +pub(crate) static DATE_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); +pub(crate) static DATE_TIME_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); +pub(crate) static FRACTION_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); +pub(crate) static FRACTION_RANGE_OTHER_TYPE_ID: Lazy = + Lazy::new(get_other_type_id::); +pub(crate) static INT_RANGE_I32_OTHER_TYPE_ID: Lazy = + Lazy::new(get_other_type_id::>); +pub(crate) static INT_RANGE_I64_OTHER_TYPE_ID: Lazy = + Lazy::new(get_other_type_id::>); +pub(crate) static LIST_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); +pub(crate) static SAMPLE_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); +pub(crate) static BUFFER_OTHER_TYPE_ID: Lazy = Lazy::new(get_other_type_id::); impl<'a> Serialize for Fraction { fn serialize(&self, serializer: S) -> Result {