mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 04:51:09 +00:00
gstreamer/plugin_feature: Make load downcast to Self
The loaded plugin feature is always of the same type as the unloaded one. Move `fn load` to PluginFeatureExtManual to implement this.
This commit is contained in:
parent
d746bf91e1
commit
59d91b2abf
9 changed files with 43 additions and 29 deletions
|
@ -1240,8 +1240,7 @@ manual_traits = ["PluginFeatureExtManual"]
|
|||
|
||||
[[object.function]]
|
||||
name = "load"
|
||||
[object.function.return]
|
||||
nullable_return_is_error = "Failed to load plugin feature"
|
||||
manual = true
|
||||
|
||||
[[object]]
|
||||
name = "Gst.Registry"
|
||||
|
|
|
@ -29,9 +29,6 @@ pub trait PluginFeatureExt: 'static {
|
|||
|
||||
#[doc(alias = "gst_plugin_feature_get_plugin_name")]
|
||||
fn get_plugin_name(&self) -> Option<glib::GString>;
|
||||
|
||||
#[doc(alias = "gst_plugin_feature_load")]
|
||||
fn load(&self) -> Result<PluginFeature, glib::BoolError>;
|
||||
}
|
||||
|
||||
impl<O: IsA<PluginFeature>> PluginFeatureExt for O {
|
||||
|
@ -61,13 +58,4 @@ impl<O: IsA<PluginFeature>> PluginFeatureExt for O {
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn load(&self) -> Result<PluginFeature, glib::BoolError> {
|
||||
unsafe {
|
||||
Option::<_>::from_glib_full(ffi::gst_plugin_feature_load(
|
||||
self.as_ref().to_glib_none().0,
|
||||
))
|
||||
.ok_or_else(|| glib::bool_error!("Failed to load plugin feature"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
Generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a)
|
||||
from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db)
|
||||
Generated by gir (https://github.com/gtk-rs/gir @ d8408d8)
|
||||
from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1)
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
use crate::PluginFeature;
|
||||
use crate::Rank;
|
||||
|
||||
use glib::object::IsA;
|
||||
use glib::translate::{from_glib, ToGlib, ToGlibPtr};
|
||||
use glib::object::{Cast, IsA};
|
||||
use glib::translate::{from_glib, FromGlibPtrFull, ToGlib, ToGlibPtr};
|
||||
|
||||
pub trait PluginFeatureExtManual: 'static {
|
||||
pub trait PluginFeatureExtManual: Sized + 'static {
|
||||
fn get_rank(&self) -> Rank;
|
||||
fn set_rank(&self, rank: Rank);
|
||||
fn load(&self) -> Result<Self, glib::BoolError>;
|
||||
}
|
||||
|
||||
impl<O: IsA<PluginFeature>> PluginFeatureExtManual for O {
|
||||
|
@ -24,4 +25,30 @@ impl<O: IsA<PluginFeature>> PluginFeatureExtManual for O {
|
|||
ffi::gst_plugin_feature_set_rank(self.as_ref().to_glib_none().0, rank.to_glib() as u32);
|
||||
}
|
||||
}
|
||||
|
||||
fn load(&self) -> Result<Self, glib::BoolError> {
|
||||
unsafe {
|
||||
let loaded = Option::<PluginFeature>::from_glib_full(ffi::gst_plugin_feature_load(
|
||||
self.as_ref().to_glib_none().0,
|
||||
))
|
||||
.ok_or_else(|| glib::bool_error!("Failed to load plugin feature"))?;
|
||||
Ok(loaded.unsafe_cast())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_load() {
|
||||
crate::init().unwrap();
|
||||
|
||||
let factory = crate::ElementFactory::find("identity").unwrap();
|
||||
let loaded = factory.load().unwrap();
|
||||
assert_eq!(factory.get_type(), loaded.get_type());
|
||||
let _element = loaded.create(None).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db)
|
||||
// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1)
|
||||
// DO NOT EDIT
|
||||
|
||||
#[cfg(not(feature = "dox"))]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db)
|
||||
// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1)
|
||||
// DO NOT EDIT
|
||||
|
||||
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db)
|
||||
// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1)
|
||||
// DO NOT EDIT
|
||||
|
||||
use gstreamer_sys::*;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db)
|
||||
// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1)
|
||||
// DO NOT EDIT
|
||||
|
||||
#include "manual.h"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// This file was generated by gir (https://github.com/gtk-rs/gir @ 1c7b41a)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 3c0281db)
|
||||
// This file was generated by gir (https://github.com/gtk-rs/gir @ d8408d8)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ 5f5218e1)
|
||||
// DO NOT EDIT
|
||||
|
||||
#include "manual.h"
|
||||
|
|
Loading…
Reference in a new issue