forked from mirrors/gstreamer-rs
const ElementMetadata constructor
The usual use of this will be through the `ElementImpl::metadata` method, which requires a `&'static` reference to `ElementMetadata` to be returned, so we better make it easy to construct these (without forcing people to resort to `Lazy`'n'stuff)
This commit is contained in:
parent
adfb6e35a4
commit
db30c121a0
1 changed files with 33 additions and 16 deletions
|
@ -13,25 +13,26 @@ use crate::StateChangeError;
|
||||||
use crate::StateChangeReturn;
|
use crate::StateChangeReturn;
|
||||||
use crate::StateChangeSuccess;
|
use crate::StateChangeSuccess;
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::sync::atomic;
|
use std::sync::atomic;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ElementMetadata {
|
pub struct ElementMetadata {
|
||||||
long_name: String,
|
long_name: Cow<'static, str>,
|
||||||
classification: String,
|
classification: Cow<'static, str>,
|
||||||
description: String,
|
description: Cow<'static, str>,
|
||||||
author: String,
|
author: Cow<'static, str>,
|
||||||
additional: Vec<(String, String)>,
|
additional: Cow<'static, [(Cow<'static, str>, Cow<'static, str>)]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ElementMetadata {
|
impl ElementMetadata {
|
||||||
pub fn new(long_name: &str, classification: &str, description: &str, author: &str) -> Self {
|
pub fn new(long_name: &str, classification: &str, description: &str, author: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
long_name: long_name.into(),
|
long_name: Cow::Owned(long_name.into()),
|
||||||
classification: classification.into(),
|
classification: Cow::Owned(classification.into()),
|
||||||
description: description.into(),
|
description: Cow::Owned(description.into()),
|
||||||
author: author.into(),
|
author: Cow::Owned(author.into()),
|
||||||
additional: vec![],
|
additional: Cow::Borrowed(&[]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,17 +44,33 @@ impl ElementMetadata {
|
||||||
additional: &[(&str, &str)],
|
additional: &[(&str, &str)],
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
long_name: long_name.into(),
|
long_name: Cow::Owned(long_name.into()),
|
||||||
classification: classification.into(),
|
classification: Cow::Owned(classification.into()),
|
||||||
description: description.into(),
|
description: Cow::Owned(description.into()),
|
||||||
author: author.into(),
|
author: Cow::Owned(author.into()),
|
||||||
additional: additional
|
additional: additional
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.map(|(key, value)| (key.into(), value.into()))
|
.map(|(key, value)| (Cow::Owned(key.into()), Cow::Owned(value.into())))
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn with_cow(
|
||||||
|
long_name: Cow<'static, str>,
|
||||||
|
classification: Cow<'static, str>,
|
||||||
|
description: Cow<'static, str>,
|
||||||
|
author: Cow<'static, str>,
|
||||||
|
additional: Cow<'static, [(Cow<'static, str>, Cow<'static, str>)]>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
long_name,
|
||||||
|
classification,
|
||||||
|
description,
|
||||||
|
author,
|
||||||
|
additional,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
|
pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
|
||||||
|
@ -384,7 +401,7 @@ unsafe impl<T: ElementImpl> IsSubclassable<T> for Element {
|
||||||
metadata.author.to_glib_none().0,
|
metadata.author.to_glib_none().0,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (key, value) in &metadata.additional {
|
for (key, value) in &metadata.additional[..] {
|
||||||
ffi::gst_element_class_add_metadata(
|
ffi::gst_element_class_add_metadata(
|
||||||
klass,
|
klass,
|
||||||
key.to_glib_none().0,
|
key.to_glib_none().0,
|
||||||
|
|
Loading…
Reference in a new issue