From 5e58998c760eda7d6c00f7902994254f8fe7e02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 13 Jul 2017 14:57:02 +0300 Subject: [PATCH] Implement FromStr for Caps and Structure --- gstreamer/src/caps.rs | 9 +++++++++ gstreamer/src/structure.rs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index e33e09d7f..a5a54e87a 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -7,6 +7,7 @@ // except according to those terms. use std::fmt; +use std::str; use miniobject::*; use structure::*; @@ -58,6 +59,14 @@ impl GstRc { } } +impl str::FromStr for Caps { + type Err = (); + + fn from_str(s: &str) -> Result { + Caps::from_string(s).ok_or(()) + } +} + impl CapsRef { pub fn set_simple(&mut self, values: &[(&str, &glib::Value)]) { for &(name, ref value) in values { diff --git a/gstreamer/src/structure.rs b/gstreamer/src/structure.rs index 07791dfa5..c7517f78c 100644 --- a/gstreamer/src/structure.rs +++ b/gstreamer/src/structure.rs @@ -9,6 +9,7 @@ use std::fmt; use std::ptr; use std::mem; +use std::str; use std::ffi::CStr; use std::ops::{Deref, DerefMut}; use std::borrow::{Borrow, ToOwned, BorrowMut}; @@ -123,6 +124,14 @@ impl PartialEq for Structure { impl Eq for Structure {} +impl str::FromStr for Structure { + type Err = (); + + fn from_str(s: &str) -> Result { + Structure::from_string(s).ok_or(()) + } +} + impl Borrow for Structure { fn borrow(&self) -> &StructureRef { unsafe { &*self.0 }