aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.rs
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2019-11-16 11:14:10 +0100
committerDirk Van Haerenborgh <vhdirk@gmail.com>2019-11-16 11:14:10 +0100
commite16769c9b16223c491766f9c9b2c828ee2253ed4 (patch)
treed1a6e68acc5bbb14d9f1e6bf65d7549916ff95b9 /src/utils.rs
parent084675fdfe1329cbd58a48f2306b7c61dec08834 (diff)
downloadmail-e16769c9b16223c491766f9c9b2c828ee2253ed4.tar.gz
less unwraps
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 022d508..6030f38 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,17 +1,29 @@
use libc;
use std::{ffi, str};
-
+use std::borrow::Cow;
use supercow::{Supercow, DefaultFeatures/*, NonSyncFeatures*/};
use supercow::ext::{BoxedStorage};
pub trait ToStr {
fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error>;
+
+ fn to_str_unchecked<'a>(&self) -> &'a str;
+
+ fn to_string_lossy<'a>(&self) -> Cow<'a, str>;
}
impl ToStr for *const libc::c_char {
fn to_str<'a>(&self) -> Result<&'a str, str::Utf8Error> {
str::from_utf8(unsafe { ffi::CStr::from_ptr(*self) }.to_bytes())
}
+
+ fn to_str_unchecked<'a>(&self) -> &'a str {
+ unsafe { str::from_utf8_unchecked(ffi::CStr::from_ptr(*self).to_bytes()) }
+ }
+
+ fn to_string_lossy<'a>(&self) -> Cow<'a, str> {
+ unsafe { ffi::CStr::from_ptr(*self) }.to_string_lossy()
+ }
}
pub trait ToString {