diff --git a/src/client/client_impl.rs b/src/client/client_impl.rs index 77fe1185..1a2e0755 100644 --- a/src/client/client_impl.rs +++ b/src/client/client_impl.rs @@ -642,15 +642,14 @@ impl Client { let handler = Box::into_raw(Box::new(handler)); unsafe { self.2 = Some(Box::from_raw(handler)); - if j::jack_set_property_change_callback( + let res = j::jack_set_property_change_callback( self.raw(), Some(crate::properties::property_changed::), std::mem::transmute::<_, _>(handler), - ) == 0 - { - Ok(()) - } else { - Err(Error::UnknownError) + ); + match res { + 0 => Ok(()), + error_code => Err(Error::UnknownError { error_code }), } } } diff --git a/src/properties.rs b/src/properties.rs index dd7568a3..898dc0b0 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -99,12 +99,11 @@ mod metadata { } } - //helper to map 0 return to Ok + // Helper to map 0 return to Ok fn map_error ::libc::c_int>(func: F) -> Result<(), Error> { - if func() == 0 { - Ok(()) - } else { - Err(Error::UnknownError) + match func() { + 0 => Ok(()), + error_code => Err(Error::UnknownError { error_code }), } } @@ -307,7 +306,7 @@ mod metadata { pub fn property_remove_subject(&self, subject: uuid) -> Result<(), Error> { unsafe { if j::jack_remove_properties(self.raw(), subject) == -1 { - Err(Error::UnknownError) + Err(Error::UnknownError { error_code: -1 }) } else { Ok(()) } @@ -418,10 +417,10 @@ mod metadata { assert_eq!(None, c1.property_get(c1.uuid(), "mutant")); //second time, error - assert_eq!( - Err(Error::UnknownError), - c2.property_remove(c1.uuid(), "mutant") - ); + assert!(matches!( + c2.property_remove(c1.uuid(), "mutant"), + Err(Error::UnknownError { .. }) + )); assert_eq!(Some(prop1), c2.property_get(c2.uuid(), "blah")); assert_eq!(Some(prop2), c2.property_get(c2.uuid(), "mutant"));