Don't return &'static references from functions but give them a generic lifetime

https://github.com/rust-lang/rust/pull/42417#issue-233404573
This commit is contained in:
Sebastian Dröge 2017-09-01 11:40:32 +03:00
parent 15d05ed3ac
commit 380fb319ba
7 changed files with 13 additions and 13 deletions

View file

@ -39,7 +39,7 @@ impl ::AudioFormat {
unsafe { from_glib(ffi::gst_audio_format_from_string(s.to_glib_none().0)) } unsafe { from_glib(ffi::gst_audio_format_from_string(s.to_glib_none().0)) }
} }
pub fn to_string(&self) -> &'static str { pub fn to_string<'a>(&self) -> &'a str {
unsafe { unsafe {
CStr::from_ptr(ffi::gst_audio_format_to_string(self.to_glib())) CStr::from_ptr(ffi::gst_audio_format_to_string(self.to_glib()))
.to_str() .to_str()

View file

@ -66,11 +66,11 @@ impl AudioFormatInfo {
from_glib(self.0.format) from_glib(self.0.format)
} }
pub fn name(&self) -> &'static str { pub fn name<'a>(&self) -> &'a str {
unsafe { CStr::from_ptr(self.0.name).to_str().unwrap() } unsafe { CStr::from_ptr(self.0.name).to_str().unwrap() }
} }
pub fn description(&self) -> &'static str { pub fn description<'a>(&self) -> &'a str {
unsafe { CStr::from_ptr(self.0.description).to_str().unwrap() } unsafe { CStr::from_ptr(self.0.description).to_str().unwrap() }
} }
@ -94,7 +94,7 @@ impl AudioFormatInfo {
from_glib(self.0.unpack_format) from_glib(self.0.unpack_format)
} }
pub fn silence(&self) -> &'static [u8] { pub fn silence<'a>(&self) -> &'a [u8] {
&self.0.silence &self.0.silence
} }

View file

@ -82,7 +82,7 @@ impl ::VideoFormat {
} }
} }
pub fn to_string(&self) -> &'static str { pub fn to_string<'a>(&self) -> &'a str {
unsafe { unsafe {
CStr::from_ptr(ffi::gst_video_format_to_string(self.to_glib())) CStr::from_ptr(ffi::gst_video_format_to_string(self.to_glib()))
.to_str() .to_str()

View file

@ -33,11 +33,11 @@ impl VideoFormatInfo {
from_glib(self.0.format) from_glib(self.0.format)
} }
pub fn name(&self) -> &'static str { pub fn name<'a>(&self) -> &'a str {
unsafe { CStr::from_ptr(self.0.name).to_str().unwrap() } unsafe { CStr::from_ptr(self.0.name).to_str().unwrap() }
} }
pub fn description(&self) -> &'static str { pub fn description<'a>(&self) -> &'a str {
unsafe { CStr::from_ptr(self.0.description).to_str().unwrap() } unsafe { CStr::from_ptr(self.0.description).to_str().unwrap() }
} }

View file

@ -17,11 +17,11 @@ use ffi;
use gobject_ffi; use gobject_ffi;
pub trait DeviceProviderExtManual { pub trait DeviceProviderExtManual {
fn get_metadata(&self, key: &str) -> Option<&'static str>; fn get_metadata<'a>(&self, key: &str) -> Option<&'a str>;
} }
impl<O: IsA<DeviceProvider>> DeviceProviderExtManual for O { impl<O: IsA<DeviceProvider>> DeviceProviderExtManual for O {
fn get_metadata(&self, key: &str) -> Option<&'static str> { fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> {
unsafe { unsafe {
let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class as let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class as
*mut ffi::GstDeviceProviderClass; *mut ffi::GstDeviceProviderClass;

View file

@ -54,7 +54,7 @@ pub trait ElementExtManual {
fn send_event(&self, event: Event) -> bool; fn send_event(&self, event: Event) -> bool;
fn get_metadata(&self, key: &str) -> Option<&'static str>; fn get_metadata<'a>(&self, key: &str) -> Option<&'a str>;
fn get_pad_template(&self, name: &str) -> Option<PadTemplate>; fn get_pad_template(&self, name: &str) -> Option<PadTemplate>;
fn get_pad_template_list(&self) -> Vec<PadTemplate>; fn get_pad_template_list(&self) -> Vec<PadTemplate>;
@ -79,7 +79,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn get_metadata(&self, key: &str) -> Option<&'static str> { fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> {
unsafe { unsafe {
let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class as let klass = (*(self.to_glib_none().0 as *mut gobject_ffi::GTypeInstance)).g_class as
*mut ffi::GstElementClass; *mut ffi::GstElementClass;

View file

@ -24,7 +24,7 @@ use Sample;
pub trait Tag<'a> { pub trait Tag<'a> {
type TagType: FromValueOptional<'a> + SetValue; type TagType: FromValueOptional<'a> + SetValue;
fn tag_name() -> &'static str; fn tag_name<'b>() -> &'b str;
} }
macro_rules! impl_tag( macro_rules! impl_tag(
@ -32,7 +32,7 @@ macro_rules! impl_tag(
pub struct $name; pub struct $name;
impl<'a> Tag<'a> for $name { impl<'a> Tag<'a> for $name {
type TagType = $t; type TagType = $t;
fn tag_name() -> &'static str { fn tag_name<'b>() -> &'b str {
$tag $tag
} }
} }