Fix various clippy warnings

This commit is contained in:
Sebastian Dröge 2017-04-20 20:37:08 +01:00
parent 154e996e2d
commit 757d7532c1
3 changed files with 14 additions and 30 deletions

View file

@ -48,10 +48,8 @@ impl Structure {
}
pub fn get<'a, T: ValueType<'a>>(&'a self, name: &str) -> Option<TypedValueRef<'a, T>> {
match self.get_value(name) {
Some(value) => TypedValueRef::from_value_ref(value),
None => None,
}
self.get_value(name)
.and_then(TypedValueRef::from_value_ref)
}
pub fn get_value<'a>(&'a self, name: &str) -> Option<ValueRef<'a>> {
@ -78,7 +76,7 @@ impl Structure {
}
}
pub fn get_name<'a>(&'a self) -> &'a str {
pub fn get_name(&self) -> &str {
unsafe {
let cstr = CStr::from_ptr(gst::gst_structure_get_name(self.0));
cstr.to_str().unwrap()
@ -88,11 +86,7 @@ impl Structure {
pub fn has_field(&self, field: &str) -> bool {
unsafe {
let cstr = CString::new(field).unwrap();
if gst::gst_structure_has_field(self.0, cstr.as_ptr()) == glib::GTRUE {
true
} else {
false
}
gst::gst_structure_has_field(self.0, cstr.as_ptr()) == glib::GTRUE
}
}
@ -109,15 +103,15 @@ impl Structure {
}
}
pub fn fields<'a>(&'a self) -> FieldIterator<'a> {
pub fn fields(&self) -> FieldIterator {
FieldIterator::new(self)
}
pub fn iter<'a>(&'a self) -> Iter<'a> {
pub fn iter(&self) -> Iter {
Iter::new(self)
}
fn get_nth_field_name<'a>(&'a self, idx: u32) -> Option<&'a str> {
fn get_nth_field_name(&self, idx: u32) -> Option<&str> {
unsafe {
let field_name = gst::gst_structure_nth_field_name(self.0, idx);
if field_name.is_null() {

View file

@ -118,12 +118,7 @@ impl TagList {
return None;
}
let res = match Value::from_raw(gvalue) {
Some(value) => TypedValue::from_value(value),
None => None,
};
res
Value::from_raw(gvalue).and_then(TypedValue::from_value)
}
}
@ -137,12 +132,7 @@ impl TagList {
return None;
}
let res = match ValueRef::from_ptr(value) {
Some(value) => TypedValueRef::from_value_ref(value),
None => None,
};
res
ValueRef::from_ptr(value).and_then(TypedValueRef::from_value_ref)
}
}

View file

@ -41,7 +41,7 @@ pub enum ValueView<'a> {
impl<'a> ValueView<'a> {
pub fn try_get<T: ValueType<'a>>(&'a self) -> Option<T> {
T::from_value_view(&self)
T::from_value_view(self)
}
}
@ -223,7 +223,7 @@ impl<'a> ValueRef<'a> {
gobject::G_TYPE_INT64 => ValueView::Int64(i64::from_value(self.0).unwrap()),
gobject::G_TYPE_UINT64 => ValueView::UInt64(u64::from_value(self.0).unwrap()),
typ if typ == *TYPE_FRACTION => {
ValueView::Fraction(Rational32::from_value(&self.0).unwrap())
ValueView::Fraction(Rational32::from_value(self.0).unwrap())
}
gobject::G_TYPE_STRING => {
ValueView::String(Cow::Borrowed(<&str as ValueType>::from_value(self.0).unwrap()))
@ -356,7 +356,7 @@ impl<'a> ValueType<'a> for &'a str {
unsafe {
let s = gobject::g_value_get_string(value);
if s.is_null() {
return Some(&"");
return Some("");
}
let cstr = CStr::from_ptr(s).to_str().expect("Invalid string");
@ -488,8 +488,8 @@ impl<'a> From<Cow<'a, [Value]>> for Value {
gobject::g_value_init(&mut value.0, <&[Value] as ValueType>::g_type());
match v {
Cow::Borrowed(ref array) => {
for e in *array {
Cow::Borrowed(array) => {
for e in array {
gst::gst_value_array_append_value(&mut value.0,
e.as_ptr() as *mut gobject::GValue);
}