gstreamer: Return &'static str from StructureRef

The names are backed by Quarks and thus eternally valid.
This commit is contained in:
Jan Alexander Steffens (heftig) 2020-03-12 19:17:15 +01:00
parent 8a80c2c574
commit af27d73e5c
No known key found for this signature in database
GPG key ID: DE5E0C5F25941CA5
2 changed files with 7 additions and 7 deletions

View file

@ -427,7 +427,7 @@ impl StructureRef {
} }
} }
pub fn get_name(&self) -> &str { pub fn get_name(&self) -> &'static str {
unsafe { unsafe {
CStr::from_ptr(gst_sys::gst_structure_get_name(&self.0)) CStr::from_ptr(gst_sys::gst_structure_get_name(&self.0))
.to_str() .to_str()
@ -484,7 +484,7 @@ impl StructureRef {
Iter::new(self) Iter::new(self)
} }
pub fn get_nth_field_name(&self, idx: u32) -> Option<&str> { pub fn get_nth_field_name(&self, idx: u32) -> Option<&'static str> {
unsafe { unsafe {
let field_name = gst_sys::gst_structure_nth_field_name(&self.0, idx); let field_name = gst_sys::gst_structure_nth_field_name(&self.0, idx);
if field_name.is_null() { if field_name.is_null() {
@ -625,9 +625,9 @@ impl<'a> FieldIterator<'a> {
} }
impl<'a> Iterator for FieldIterator<'a> { impl<'a> Iterator for FieldIterator<'a> {
type Item = &'a str; type Item = &'static str;
fn next(&mut self) -> Option<&'a str> { fn next(&mut self) -> Option<Self::Item> {
if self.idx >= self.n_fields { if self.idx >= self.n_fields {
return None; return None;
} }
@ -683,9 +683,9 @@ impl<'a> Iter<'a> {
} }
impl<'a> Iterator for Iter<'a> { impl<'a> Iterator for Iter<'a> {
type Item = (&'a str, &'a SendValue); type Item = (&'static str, &'a SendValue);
fn next(&mut self) -> Option<(&'a str, &'a SendValue)> { fn next(&mut self) -> Option<Self::Item> {
if let Some(f) = self.iter.next() { if let Some(f) = self.iter.next() {
let v = self.iter.structure.get_value(f); let v = self.iter.structure.get_value(f);
Some((f, v.unwrap())) Some((f, v.unwrap()))

View file

@ -27,7 +27,7 @@ use value_serde::*;
use Structure; use Structure;
use StructureRef; use StructureRef;
struct FieldSe<'a>(&'a str, &'a glib::SendValue); struct FieldSe<'a>(&'static str, &'a glib::SendValue);
impl<'a> Serialize for FieldSe<'a> { impl<'a> Serialize for FieldSe<'a> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
ser_value!(self.1, |type_, value| { ser_value!(self.1, |type_, value| {