mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 14:36:29 +03:00
refactor: a rusty job
* refactor(jobthread): safe and rusty * refactor(job): rusty and safe
This commit is contained in:
committed by
GitHub
parent
1a8e08e429
commit
a906faeb35
@@ -1284,6 +1284,14 @@ pub fn as_str<'a>(s: *const libc::c_char) -> &'a str {
|
||||
as_str_safe(s).unwrap_or_else(|err| panic!("{}", err))
|
||||
}
|
||||
|
||||
/// Converts a C string to either a Rust `&str` or `None` if it is a null pointer.
|
||||
pub fn as_opt_str<'a>(s: *const libc::c_char) -> Option<&'a str> {
|
||||
if s.is_null() {
|
||||
return None;
|
||||
}
|
||||
Some(as_str(s))
|
||||
}
|
||||
|
||||
fn as_str_safe<'a>(s: *const libc::c_char) -> Result<&'a str, Error> {
|
||||
assert!(!s.is_null(), "cannot be used on null pointers");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user