1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use glib::{ |
4 | prelude::*, |
5 | translate::{from_glib, FromGlibPtrFull, IntoGlib, ToGlibPtr}, |
6 | }; |
7 | |
8 | use crate::{PluginFeature, Rank}; |
9 | |
10 | mod sealed { |
11 | pub trait Sealed {} |
12 | impl<T: super::IsA<super::PluginFeature>> Sealed for T {} |
13 | } |
14 | |
15 | pub trait PluginFeatureExtManual: sealed::Sealed + IsA<PluginFeature> + Sized + 'static { |
16 | #[doc (alias = "get_rank" )] |
17 | #[doc (alias = "gst_plugin_feature_get_rank" )] |
18 | fn rank(&self) -> Rank { |
19 | unsafe { |
20 | let rank = ffi::gst_plugin_feature_get_rank(self.as_ref().to_glib_none().0); |
21 | from_glib(rank as i32) |
22 | } |
23 | } |
24 | |
25 | #[doc (alias = "gst_plugin_feature_set_rank" )] |
26 | fn set_rank(&self, rank: Rank) { |
27 | unsafe { |
28 | ffi::gst_plugin_feature_set_rank( |
29 | self.as_ref().to_glib_none().0, |
30 | rank.into_glib() as u32, |
31 | ); |
32 | } |
33 | } |
34 | |
35 | #[doc (alias = "gst_plugin_feature_load" )] |
36 | fn load(&self) -> Result<Self, glib::BoolError> { |
37 | unsafe { |
38 | let loaded = Option::<PluginFeature>::from_glib_full(ffi::gst_plugin_feature_load( |
39 | self.as_ref().to_glib_none().0, |
40 | )) |
41 | .ok_or_else(|| glib::bool_error!("Failed to load plugin feature" ))?; |
42 | Ok(loaded.unsafe_cast()) |
43 | } |
44 | } |
45 | } |
46 | |
47 | impl<O: IsA<PluginFeature>> PluginFeatureExtManual for O {} |
48 | |
49 | #[cfg (test)] |
50 | mod tests { |
51 | use super::*; |
52 | |
53 | #[test ] |
54 | fn test_load() { |
55 | crate::init().unwrap(); |
56 | |
57 | let factory = crate::ElementFactory::find("identity" ).unwrap(); |
58 | let loaded = factory.load().unwrap(); |
59 | assert_eq!(factory.type_(), loaded.type_()); |
60 | let _element = loaded.create().build().unwrap(); |
61 | } |
62 | } |
63 | |