gstreamer-rs/gstreamer/src/utils.rs

38 lines
993 B
Rust
Raw Normal View History

2020-12-15 10:53:31 +00:00
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::translate::mut_override;
#[must_use = "if unused the Mutex will immediately unlock"]
#[doc(alias = "GMutex")]
pub struct MutexGuard<'a>(&'a glib::ffi::GMutex);
impl<'a> MutexGuard<'a> {
#[allow(clippy::trivially_copy_pass_by_ref)]
#[doc(alias = "g_mutex_lock")]
#[inline]
pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self {
2020-03-22 14:18:47 +00:00
skip_assert_initialized!();
unsafe {
glib::ffi::g_mutex_lock(mut_override(mutex));
}
MutexGuard(mutex)
}
}
impl<'a> Drop for MutexGuard<'a> {
#[inline]
fn drop(&mut self) {
unsafe {
glib::ffi::g_mutex_unlock(mut_override(self.0));
}
}
}
2020-10-27 17:27:16 +00:00
// rustdoc-stripper-ignore-next
/// Trait that allows accessing `Display` implementation on types external to this crate.
pub trait Displayable {
type DisplayImpl: std::fmt::Display;
fn display(self) -> Self::DisplayImpl;
}