Move to_string() methods into the Display trait or rename to to_str(), move from_string() into the FromStr trait

Fixes clippy warnings, prevents confusing errors and is more consistent.

The Display trait provides a to_string() method by itself and FromStr
provides from_str().
This commit is contained in:
Sebastian Dröge 2019-10-04 09:11:30 +03:00
parent 861f5c1e1a
commit 06cfcd57fc
12 changed files with 154 additions and 192 deletions

View file

@ -73,7 +73,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
appsink.set_caps(Some(&gst::Caps::new_simple( appsink.set_caps(Some(&gst::Caps::new_simple(
"audio/x-raw", "audio/x-raw",
&[ &[
("format", &gst_audio::AUDIO_FORMAT_S16.to_string()), ("format", &gst_audio::AUDIO_FORMAT_S16.to_str()),
("layout", &"interleaved"), ("layout", &"interleaved"),
("channels", &(1i32)), ("channels", &(1i32)),
("rate", &gst::IntRange::<i32>::new(1, i32::MAX)), ("rate", &gst::IntRange::<i32>::new(1, i32::MAX)),

View file

@ -559,7 +559,7 @@ impl App {
let caps = gst::Caps::builder("video/x-raw") let caps = gst::Caps::builder("video/x-raw")
.features(&[&gst_gl::CAPS_FEATURE_MEMORY_GL_MEMORY]) .features(&[&gst_gl::CAPS_FEATURE_MEMORY_GL_MEMORY])
.field("format", &gst_video::VideoFormat::Rgba.to_string()) .field("format", &gst_video::VideoFormat::Rgba.to_str())
.field("texture-target", &"2D") .field("texture-target", &"2D")
.build(); .build();
appsink.set_caps(Some(&caps)); appsink.set_caps(Some(&caps));

View file

@ -27,7 +27,7 @@ fn example_main() {
// from the resulting pipeline. // from the resulting pipeline.
let pipeline = gst::parse_launch(&format!( let pipeline = gst::parse_launch(&format!(
"audiotestsrc name=src ! audio/x-raw,format={},channels=1 ! fakesink", "audiotestsrc name=src ! audio/x-raw,format={},channels=1 ! fakesink",
gst_audio::AUDIO_FORMAT_S16.to_string() gst_audio::AUDIO_FORMAT_S16.to_str()
)) ))
.unwrap(); .unwrap();
let pipeline = pipeline.dynamic_cast::<gst::Pipeline>().unwrap(); let pipeline = pipeline.dynamic_cast::<gst::Pipeline>().unwrap();

View file

@ -12,7 +12,7 @@ use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::str; use std::str;
use glib::translate::{from_glib, ToGlib, ToGlibPtr}; use glib::translate::{from_glib, FromGlib, ToGlib, ToGlibPtr};
impl ::AudioFormat { impl ::AudioFormat {
pub fn build_integer( pub fn build_integer(
@ -33,17 +33,7 @@ impl ::AudioFormat {
} }
} }
pub fn from_string(s: &str) -> ::AudioFormat { pub fn to_str<'a>(self) -> &'a str {
assert_initialized_main_thread!();
unsafe {
from_glib(gst_audio_sys::gst_audio_format_from_string(
s.to_glib_none().0,
))
}
}
pub fn to_string<'a>(self) -> &'a str {
if self == ::AudioFormat::Unknown { if self == ::AudioFormat::Unknown {
return "UNKNOWN"; return "UNKNOWN";
} }
@ -60,20 +50,24 @@ impl str::FromStr for ::AudioFormat {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!(); assert_initialized_main_thread!();
let format = Self::from_string(s); unsafe {
if format == ::AudioFormat::Unknown { let fmt = ::AudioFormat::from_glib(gst_audio_sys::gst_audio_format_from_string(
Err(()) s.to_glib_none().0,
} else { ));
Ok(format) if fmt == ::AudioFormat::Unknown {
Err(())
} else {
Ok(fmt)
}
} }
} }
} }
impl fmt::Display for ::AudioFormat { impl fmt::Display for ::AudioFormat {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(::AudioFormat::to_string(*self)) f.write_str((*self).to_str())
} }
} }

View file

@ -46,16 +46,6 @@ impl ToGlib for VideoEndianness {
} }
impl ::VideoFormat { impl ::VideoFormat {
pub fn from_string(s: &str) -> ::VideoFormat {
assert_initialized_main_thread!();
unsafe {
from_glib(gst_video_sys::gst_video_format_from_string(
s.to_glib_none().0,
))
}
}
pub fn from_fourcc(fourcc: u32) -> ::VideoFormat { pub fn from_fourcc(fourcc: u32) -> ::VideoFormat {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
@ -86,7 +76,7 @@ impl ::VideoFormat {
} }
} }
pub fn to_string<'a>(self) -> &'a str { pub fn to_str<'a>(self) -> &'a str {
if self == ::VideoFormat::Unknown { if self == ::VideoFormat::Unknown {
return "UNKNOWN"; return "UNKNOWN";
} }
@ -103,20 +93,25 @@ impl str::FromStr for ::VideoFormat {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!(); assert_initialized_main_thread!();
let format = Self::from_string(s); unsafe {
if format == ::VideoFormat::Unknown { let fmt = ::VideoFormat::from_glib(gst_video_sys::gst_video_format_from_string(
Err(()) s.to_glib_none().0,
} else { ));
Ok(format)
if fmt == ::VideoFormat::Unknown {
Err(())
} else {
Ok(fmt)
}
} }
} }
} }
impl fmt::Display for ::VideoFormat { impl fmt::Display for ::VideoFormat {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(::VideoFormat::to_string(*self)) f.write_str((*self).to_str())
} }
} }

View file

@ -12,12 +12,13 @@ use gst_video_sys;
use glib; use glib;
use glib::translate::{ use glib::translate::{
from_glib, from_glib_full, from_glib_none, FromGlib, FromGlibPtrNone, ToGlib, ToGlibPtr, from_glib, from_glib_full, from_glib_none, FromGlib, FromGlibPtrFull, FromGlibPtrNone, ToGlib,
ToGlibPtrMut, ToGlibPtr, ToGlibPtrMut,
}; };
use gst; use gst;
use gst::prelude::*; use gst::prelude::*;
use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -110,27 +111,6 @@ impl VideoColorimetry {
VideoColorimetry(colorimetry) VideoColorimetry(colorimetry)
} }
pub fn to_string(&self) -> String {
unsafe { from_glib_full(gst_video_sys::gst_video_colorimetry_to_string(&self.0)) }
}
pub fn from_string(s: &str) -> Option<Self> {
assert_initialized_main_thread!();
unsafe {
let mut colorimetry = mem::MaybeUninit::zeroed();
let valid: bool = from_glib(gst_video_sys::gst_video_colorimetry_from_string(
colorimetry.as_mut_ptr(),
s.to_glib_none().0,
));
if valid {
Some(VideoColorimetry(colorimetry.assume_init()))
} else {
None
}
}
}
pub fn range(&self) -> ::VideoColorRange { pub fn range(&self) -> ::VideoColorRange {
from_glib(self.0.range) from_glib(self.0.range)
} }
@ -170,8 +150,20 @@ impl str::FromStr for ::VideoColorimetry {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!(); assert_initialized_main_thread!();
Self::from_string(s).ok_or(())
unsafe {
let mut colorimetry = mem::MaybeUninit::zeroed();
let valid: bool = from_glib(gst_video_sys::gst_video_colorimetry_from_string(
colorimetry.as_mut_ptr(),
s.to_glib_none().0,
));
if valid {
Ok(VideoColorimetry(colorimetry.assume_init()))
} else {
Err(())
}
}
} }
} }
@ -188,7 +180,10 @@ impl fmt::Debug for ::VideoColorimetry {
impl fmt::Display for ::VideoColorimetry { impl fmt::Display for ::VideoColorimetry {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(&::VideoColorimetry::to_string(self)) let s = unsafe {
glib::GString::from_glib_full(gst_video_sys::gst_video_colorimetry_to_string(&self.0))
};
f.write_str(&s)
} }
} }
@ -822,21 +817,13 @@ impl glib::translate::FromGlibPtrFull<*mut gst_video_sys::GstVideoInfo> for Vide
#[cfg(any(feature = "v1_12", feature = "dox"))] #[cfg(any(feature = "v1_12", feature = "dox"))]
impl ::VideoFieldOrder { impl ::VideoFieldOrder {
pub fn to_string(self) -> String { pub fn to_str<'a>(self) -> &'a str {
unsafe { unsafe {
from_glib_none(gst_video_sys::gst_video_field_order_to_string( CStr::from_ptr(gst_video_sys::gst_video_field_order_to_string(
self.to_glib(), self.to_glib(),
)) ))
} .to_str()
} .unwrap()
pub fn from_string(s: &str) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib(gst_video_sys::gst_video_field_order_from_string(
s.to_glib_none().0,
))
} }
} }
} }
@ -846,34 +833,31 @@ impl str::FromStr for ::VideoFieldOrder {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!(); assert_initialized_main_thread!();
Ok(Self::from_string(s))
unsafe {
Ok(from_glib(gst_video_sys::gst_video_field_order_from_string(
s.to_glib_none().0,
)))
}
} }
} }
#[cfg(any(feature = "v1_12", feature = "dox"))] #[cfg(any(feature = "v1_12", feature = "dox"))]
impl fmt::Display for ::VideoFieldOrder { impl fmt::Display for ::VideoFieldOrder {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(&::VideoFieldOrder::to_string(*self)) f.write_str((*self).to_str())
} }
} }
impl ::VideoInterlaceMode { impl ::VideoInterlaceMode {
pub fn to_string(self) -> String { pub fn to_str<'a>(self) -> &'a str {
unsafe { unsafe {
from_glib_none(gst_video_sys::gst_video_interlace_mode_to_string( CStr::from_ptr(gst_video_sys::gst_video_interlace_mode_to_string(
self.to_glib(), self.to_glib(),
)) ))
} .to_str()
} .unwrap()
pub fn from_string(s: &str) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib(gst_video_sys::gst_video_interlace_mode_from_string(
s.to_glib_none().0,
))
} }
} }
} }
@ -882,14 +866,19 @@ impl str::FromStr for ::VideoInterlaceMode {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!(); assert_initialized_main_thread!();
Ok(Self::from_string(s))
unsafe {
Ok(from_glib(
gst_video_sys::gst_video_interlace_mode_from_string(s.to_glib_none().0),
))
}
} }
} }
impl fmt::Display for ::VideoInterlaceMode { impl fmt::Display for ::VideoInterlaceMode {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(&::VideoInterlaceMode::to_string(*self)) f.write_str((*self).to_str())
} }
} }
@ -992,9 +981,11 @@ mod tests {
#[cfg(any(feature = "v1_12", feature = "dox"))] #[cfg(any(feature = "v1_12", feature = "dox"))]
#[test] #[test]
fn test_display() { fn test_display() {
use std::str::FromStr;
gst::init().unwrap(); gst::init().unwrap();
format!("{}", ::VideoColorimetry::from_string("sRGB").unwrap()); format!("{}", ::VideoColorimetry::from_str("sRGB").unwrap());
format!("{}", ::VideoFieldOrder::TopFieldFirst); format!("{}", ::VideoFieldOrder::TopFieldFirst);
format!("{}", ::VideoInterlaceMode::Progressive); format!("{}", ::VideoInterlaceMode::Progressive);
} }

View file

@ -99,16 +99,6 @@ impl VideoTimeCode {
} }
} }
#[cfg(any(feature = "v1_12", feature = "dox"))]
pub fn from_string(tc_str: &str) -> Option<VideoTimeCode> {
assert_initialized_main_thread!();
unsafe {
from_glib_full(gst_video_sys::gst_video_time_code_new_from_string(
tc_str.to_glib_none().0,
))
}
}
pub fn is_valid(&self) -> bool { pub fn is_valid(&self) -> bool {
unsafe { unsafe {
from_glib(gst_video_sys::gst_video_time_code_is_valid( from_glib(gst_video_sys::gst_video_time_code_is_valid(
@ -246,14 +236,6 @@ impl ValidVideoTimeCode {
macro_rules! generic_impl { macro_rules! generic_impl {
($name:ident) => { ($name:ident) => {
impl $name { impl $name {
pub fn to_string(&self) -> String {
unsafe {
from_glib_full(gst_video_sys::gst_video_time_code_to_string(
self.to_glib_none().0,
))
}
}
pub fn get_hours(&self) -> u32 { pub fn get_hours(&self) -> u32 {
self.0.hours self.0.hours
} }
@ -338,7 +320,12 @@ macro_rules! generic_impl {
impl fmt::Display for $name { impl fmt::Display for $name {
#[inline] #[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string()) let s = unsafe {
glib::GString::from_glib_full(gst_video_sys::gst_video_time_code_to_string(
self.to_glib_none().0,
))
};
f.write_str(&s)
} }
} }
@ -482,8 +469,13 @@ impl str::FromStr for VideoTimeCode {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!(); assert_initialized_main_thread!();
Self::from_string(s).ok_or(()) unsafe {
Option::<VideoTimeCode>::from_glib_full(
gst_video_sys::gst_video_time_code_new_from_string(s.to_glib_none().0),
)
.ok_or(())
}
} }
} }

View file

@ -17,20 +17,12 @@ use std::cmp;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use std::str;
#[derive(Clone)] #[derive(Clone)]
pub struct VideoTimeCodeInterval(gst_video_sys::GstVideoTimeCodeInterval); pub struct VideoTimeCodeInterval(gst_video_sys::GstVideoTimeCodeInterval);
impl VideoTimeCodeInterval { impl VideoTimeCodeInterval {
pub fn from_string(tc_inter_str: &str) -> Option<Self> {
assert_initialized_main_thread!();
unsafe {
from_glib_full(gst_video_sys::gst_video_time_code_interval_new_from_string(
tc_inter_str.to_glib_none().0,
))
}
}
pub fn new(hours: u32, minutes: u32, seconds: u32, frames: u32) -> Self { pub fn new(hours: u32, minutes: u32, seconds: u32, frames: u32) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
@ -135,6 +127,20 @@ impl fmt::Display for VideoTimeCodeInterval {
} }
} }
impl str::FromStr for VideoTimeCodeInterval {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
assert_initialized_main_thread!();
unsafe {
Option::<VideoTimeCodeInterval>::from_glib_full(
gst_video_sys::gst_video_time_code_interval_new_from_string(s.to_glib_none().0),
)
.ok_or(())
}
}
}
#[doc(hidden)] #[doc(hidden)]
impl GlibPtrDefault for VideoTimeCodeInterval { impl GlibPtrDefault for VideoTimeCodeInterval {
type GlibType = *mut gst_video_sys::GstVideoTimeCodeInterval; type GlibType = *mut gst_video_sys::GstVideoTimeCodeInterval;

View file

@ -16,7 +16,7 @@ use structure::*;
use CapsIntersectMode; use CapsIntersectMode;
use glib; use glib;
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlibPtr};
use glib::value::ToSendValue; use glib::value::ToSendValue;
use gst_sys; use gst_sys;
@ -54,11 +54,6 @@ impl Caps {
caps caps
} }
pub fn from_string(value: &str) -> Option<Self> {
assert_initialized_main_thread!();
unsafe { from_glib_full(gst_sys::gst_caps_from_string(value.to_glib_none().0)) }
}
pub fn fixate(caps: Self) -> Self { pub fn fixate(caps: Self) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { from_glib_full(gst_sys::gst_caps_fixate(caps.into_ptr())) } unsafe { from_glib_full(gst_sys::gst_caps_fixate(caps.into_ptr())) }
@ -114,8 +109,11 @@ impl str::FromStr for Caps {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!(); assert_initialized_main_thread!();
Caps::from_string(s).ok_or(()) unsafe {
Option::<Caps>::from_glib_full(gst_sys::gst_caps_from_string(s.to_glib_none().0))
.ok_or(())
}
} }
} }
@ -140,10 +138,6 @@ impl CapsRef {
} }
} }
pub fn to_string(&self) -> String {
unsafe { from_glib_full(gst_sys::gst_caps_to_string(self.as_ptr())) }
}
pub fn get_structure(&self, idx: u32) -> Option<&StructureRef> { pub fn get_structure(&self, idx: u32) -> Option<&StructureRef> {
if idx >= self.get_size() { if idx >= self.get_size() {
return None; return None;
@ -509,7 +503,9 @@ impl fmt::Debug for CapsRef {
impl fmt::Display for CapsRef { impl fmt::Display for CapsRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&CapsRef::to_string(self)) let s =
unsafe { glib::GString::from_glib_full(gst_sys::gst_caps_to_string(self.as_ptr())) };
f.write_str(&s)
} }
} }

View file

@ -63,21 +63,6 @@ impl CapsFeatures {
} }
} }
pub fn from_string(value: &str) -> Option<Self> {
assert_initialized_main_thread!();
unsafe {
let ptr = gst_sys::gst_caps_features_from_string(value.to_glib_none().0);
if ptr.is_null() {
return None;
}
Some(CapsFeatures(
ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef),
PhantomData,
))
}
}
pub unsafe fn into_ptr(self) -> *mut gst_sys::GstCapsFeatures { pub unsafe fn into_ptr(self) -> *mut gst_sys::GstCapsFeatures {
let ptr = self.0.as_ptr() as *mut CapsFeaturesRef as *mut gst_sys::GstCapsFeatures; let ptr = self.0.as_ptr() as *mut CapsFeaturesRef as *mut gst_sys::GstCapsFeatures;
mem::forget(self); mem::forget(self);
@ -148,8 +133,18 @@ impl str::FromStr for CapsFeatures {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!(); assert_initialized_main_thread!();
CapsFeatures::from_string(s).ok_or(()) unsafe {
let ptr = gst_sys::gst_caps_features_from_string(s.to_glib_none().0);
if ptr.is_null() {
return Err(());
}
Ok(CapsFeatures(
ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef),
PhantomData,
))
}
} }
} }
@ -302,10 +297,6 @@ impl CapsFeaturesRef {
self as *const Self as *mut gst_sys::GstCapsFeatures self as *const Self as *mut gst_sys::GstCapsFeatures
} }
pub fn to_string(&self) -> String {
unsafe { from_glib_full(gst_sys::gst_caps_features_to_string(self.as_ptr())) }
}
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.get_size() == 0 && !self.is_any() self.get_size() == 0 && !self.is_any()
} }
@ -448,7 +439,10 @@ impl fmt::Debug for CapsFeaturesRef {
impl fmt::Display for CapsFeaturesRef { impl fmt::Display for CapsFeaturesRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.to_string()) let s = unsafe {
glib::GString::from_glib_full(gst_sys::gst_caps_features_to_string(self.as_ptr()))
};
f.write_str(&s)
} }
} }

View file

@ -109,21 +109,6 @@ impl Structure {
structure structure
} }
pub fn from_string(s: &str) -> Option<Structure> {
assert_initialized_main_thread!();
unsafe {
let structure = gst_sys::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut());
if structure.is_null() {
None
} else {
Some(Structure(
ptr::NonNull::new_unchecked(structure as *mut StructureRef),
PhantomData,
))
}
}
}
pub unsafe fn into_ptr(self) -> *mut gst_sys::GstStructure { pub unsafe fn into_ptr(self) -> *mut gst_sys::GstStructure {
let ptr = self.0.as_ptr() as *mut StructureRef as *mut gst_sys::GstStructure; let ptr = self.0.as_ptr() as *mut StructureRef as *mut gst_sys::GstStructure;
mem::forget(self); mem::forget(self);
@ -206,8 +191,18 @@ impl str::FromStr for Structure {
type Err = (); type Err = ();
fn from_str(s: &str) -> Result<Self, ()> { fn from_str(s: &str) -> Result<Self, ()> {
skip_assert_initialized!(); assert_initialized_main_thread!();
Structure::from_string(s).ok_or(()) unsafe {
let structure = gst_sys::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut());
if structure.is_null() {
Err(())
} else {
Ok(Structure(
ptr::NonNull::new_unchecked(structure as *mut StructureRef),
PhantomData,
))
}
}
} }
} }
@ -373,10 +368,6 @@ impl StructureRef {
self as *const Self as *mut gst_sys::GstStructure self as *const Self as *mut gst_sys::GstStructure
} }
pub fn to_string(&self) -> String {
unsafe { from_glib_full(gst_sys::gst_structure_to_string(&self.0)) }
}
pub fn get<'structure, 'name, T: FromValueOptional<'structure>>( pub fn get<'structure, 'name, T: FromValueOptional<'structure>>(
&'structure self, &'structure self,
name: &'name str, name: &'name str,
@ -598,7 +589,8 @@ impl StructureRef {
impl fmt::Display for StructureRef { impl fmt::Display for StructureRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.to_string()) let s = unsafe { glib::GString::from_glib_full(gst_sys::gst_structure_to_string(&self.0)) };
f.write_str(&s)
} }
} }
@ -749,6 +741,7 @@ impl Builder {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::str::FromStr;
#[test] #[test]
fn new_set_get() { fn new_set_get() {
@ -831,7 +824,7 @@ mod tests {
let a = "Test, f1=(string)abc, f2=(uint)123;"; let a = "Test, f1=(string)abc, f2=(uint)123;";
let s = Structure::from_string(&a).unwrap(); let s = Structure::from_str(&a).unwrap();
assert_eq!(s.get::<&str>("f1"), Ok(Some("abc"))); assert_eq!(s.get::<&str>("f1"), Ok(Some("abc")));
assert_eq!(s.get_some::<u32>("f2"), Ok(123)); assert_eq!(s.get_some::<u32>("f2"), Ok(123));
@ -844,7 +837,7 @@ mod tests {
let a = glib::value::Value::from(None::<&Structure>); let a = glib::value::Value::from(None::<&Structure>);
assert!(a.get::<Structure>().unwrap().is_none()); assert!(a.get::<Structure>().unwrap().is_none());
let b = glib::value::Value::from(&Structure::from_string(&"foo").unwrap()); let b = glib::value::Value::from(&Structure::from_str(&"foo").unwrap());
assert!(b.get::<Structure>().unwrap().is_some()); assert!(b.get::<Structure>().unwrap().is_some());
} }
} }

View file

@ -12,7 +12,9 @@ use std::marker::PhantomData;
use std::mem; use std::mem;
use glib; use glib;
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr, ToGlibPtrMut}; use glib::translate::{
from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlibPtr, ToGlibPtrMut,
};
use glib::value::{FromValueOptional, SendValue, SetValue, ToSendValue, TypedValue, Value}; use glib::value::{FromValueOptional, SendValue, SetValue, ToSendValue, TypedValue, Value};
use glib::StaticType; use glib::StaticType;
use gobject_sys; use gobject_sys;
@ -488,10 +490,6 @@ impl TagListRef {
Iter::new(self) Iter::new(self)
} }
pub fn to_string(&self) -> String {
unsafe { from_glib_full(gst_sys::gst_tag_list_to_string(self.as_ptr())) }
}
pub fn insert(&mut self, other: &TagListRef, mode: TagMergeMode) { pub fn insert(&mut self, other: &TagListRef, mode: TagMergeMode) {
unsafe { gst_sys::gst_tag_list_insert(self.as_mut_ptr(), other.as_ptr(), mode.to_glib()) } unsafe { gst_sys::gst_tag_list_insert(self.as_mut_ptr(), other.as_ptr(), mode.to_glib()) }
} }
@ -523,7 +521,10 @@ impl fmt::Debug for TagListRef {
impl fmt::Display for TagListRef { impl fmt::Display for TagListRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&TagListRef::to_string(self)) let s = unsafe {
glib::GString::from_glib_full(gst_sys::gst_tag_list_to_string(self.as_ptr()))
};
f.write_str(&s)
} }
} }