#[cfg(not(feature = "no-string-validation"))] fn check_valid(c: *const c_char) -> Result<(), String> { letmut e = Error::empty(); let b = unsafe { ffi::$s(c, e.get_mut()) }; if b != 0 { Ok(()) } else { Err(e.message().unwrap().into()) }
}
/// Creates a new instance of this struct. /// /// Note: If the no-string-validation feature is activated, this string /// will not be checked for conformance with the D-Bus specification. pubfn new<S: Into<Vec<u8>>>(s: S) -> Result<$t<'m>, String> { let c = try!(CString::new(s).map_err(|e| e.to_string()));
$t::check_valid(c.as_ptr()).map(|_| $t(Cow::Owned(c)))
}
/// Creates a new instance of this struct. If you end it with \0, /// it can borrow the slice without extra allocation. /// /// Note: If the no-string-validation feature is activated, this string /// will not be checked for conformance with the D-Bus specification. pubfn from_slice(s: &'m [u8]) -> Result<$t<'m>, String> { if s.len() == 0 || s[s.len()-1] != 0 { return $t::new(s) };
$t::check_valid(s.as_ptr() as *const c_char).map(|_| { let c = unsafe { CStr::from_ptr(s.as_ptr() as *const c_char) };
$t(Cow::Borrowed(c))
})
}
/// This function creates a new instance of this struct, without checking. /// It's up to you to guarantee that s ends with a \0 and is valid. pubunsafefn from_slice_unchecked(s: &'m [u8]) -> $t<'m> {
debug_assert!(s[s.len()-1] == 0);
$t(Cow::Borrowed(CStr::from_ptr(s.as_ptr() as *const c_char)))
}
/// View this struct as a CStr. pubfn as_cstr(&self) -> &CStr { &self.0 }
/// Makes sure this string does not contain borrows. pubfn into_static(self) -> $t<'static> {
$t(Cow::Owned(self.0.into_owned()))
}
/// Converts this struct to a CString. pubfn into_cstring(self) -> CString { self.0.into_owned() }
}
/* /// #Panics /// /// If given string is not valid. /// impl<S: Into<Vec<u8>>> From<S> for $t { fn from(s: S) -> $t { $t::new(s).unwrap() } }
*/
/// #Panics /// /// If given string is not valid. impl<'m> From<String> for $t<'m> { fn from(s: String) -> $t<'m> { $t::new(s).unwrap() } }
/// #Panics /// /// If given string is not valid. impl<'m> From<&'m String> for $t<'m> { fn from(s: &'m String) -> $t<'m> { $t::from_slice(s.as_bytes()).unwrap() } }
/// #Panics /// /// If given string is not valid. impl<'m> From<&'m str> for $t<'m> { fn from(s: &'m str) -> $t<'m> { $t::from_slice(s.as_bytes()).unwrap() } }
/// #Panics /// /// If given string is not valid. impl<'m> From<Cow<'m, str>> for $t<'m> { fn from(s: Cow<'m, str>) -> $t<'m> { match s {
Cow::Borrowed(z) => z.into(),
Cow::Owned(z) => z.into(),
}
}
}
/// A wrapper around a string that is guaranteed to be /// a valid (single) D-Bus type signature. Supersedes TypeSig. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)] pubstruct Signature<'a>(Cow<'a, CStr>);
impl Signature<'static> { /// Makes a D-Bus signature that corresponds to A. pubfn make<A: super::arg::Arg>() -> Signature<'static> { A::signature() }
}
/// A wrapper around a string that is guaranteed to be /// a valid D-Bus object path. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)] pubstruct Path<'a>(Cow<'a, CStr>);
cstring_wrapper!(Path, dbus_validate_path);
// This is needed so one can make arrays of paths easily impl<'a> default::Default for Path<'a> { fn default() -> Path<'a> { Path(Cow::Borrowed(unsafe { CStr::from_ptr(b"/\0".as_ptr() as *const c_char)})) }
}
/// A wrapper around a string that is guaranteed to be /// a valid D-Bus member, i e, a signal or method name. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)] pubstruct Member<'a>(Cow<'a, CStr>);
cstring_wrapper!(Member, dbus_validate_member);
/// A wrapper around a string that is guaranteed to be /// a valid D-Bus interface name. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)] pubstruct Interface<'a>(Cow<'a, CStr>);
/// A wrapper around a string that is guaranteed to be /// a valid D-Bus bus name. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)] pubstruct BusName<'a>(Cow<'a, CStr>);
/// A wrapper around a string that is guaranteed to be /// a valid D-Bus bus name. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)] pubstruct ErrorName<'a>(Cow<'a, CStr>);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.