1 // Take a look at the license at the top of the repository in the LICENSE file.
2 
3 use glib::translate::mut_override;
4 
5 #[must_use = "if unused the Mutex will immediately unlock"]
6 #[doc(alias = "GMutex")]
7 pub struct MutexGuard<'a>(&'a glib::ffi::GMutex);
8 
9 impl<'a> MutexGuard<'a> {
10     #[allow(clippy::trivially_copy_pass_by_ref)]
11     #[doc(alias = "g_mutex_lock")]
lock(mutex: &'a glib::ffi::GMutex) -> Self12     pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self {
13         skip_assert_initialized!();
14         unsafe {
15             glib::ffi::g_mutex_lock(mut_override(mutex));
16         }
17         MutexGuard(mutex)
18     }
19 }
20 
21 impl<'a> Drop for MutexGuard<'a> {
drop(&mut self)22     fn drop(&mut self) {
23         unsafe {
24             glib::ffi::g_mutex_unlock(mut_override(self.0));
25         }
26     }
27 }
28 
29 // rustdoc-stripper-ignore-next
30 /// Trait that allows accessing `Display` implementation on types external to this crate.
31 pub trait Displayable {
32     type DisplayImpl: std::fmt::Display;
33 
display(self) -> Self::DisplayImpl34     fn display(self) -> Self::DisplayImpl;
35 }
36