-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NixPath -> NixString and Error -> Errno
- Loading branch information
Showing
19 changed files
with
201 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::ffi::{CStr, CString}; | ||
use std::borrow::Cow; | ||
|
||
/// Represents a type that can be converted to a `&CStr` without fail. | ||
/// | ||
/// Note: this trait exists in place of `AsRef<CStr>` because is not | ||
/// implemented until Rust 1.7.0 | ||
pub trait NixString { | ||
fn as_ref(&self) -> &CStr; | ||
} | ||
|
||
impl<'a> NixString for Cow<'a, CStr> { | ||
fn as_ref(&self) -> &CStr { | ||
self | ||
} | ||
} | ||
|
||
impl NixString for CStr { | ||
fn as_ref(&self) -> &CStr { | ||
self | ||
} | ||
} | ||
|
||
impl NixString for CString { | ||
fn as_ref(&self) -> &CStr { | ||
self | ||
} | ||
} | ||
|
||
impl<'a, T: ?Sized + NixString> NixString for &'a T { | ||
fn as_ref(&self) -> &CStr { | ||
NixString::as_ref(*self) | ||
} | ||
} | ||
|
||
impl<'a, T: ?Sized + NixString> NixString for &'a mut T { | ||
fn as_ref(&self) -> &CStr { | ||
NixString::as_ref(*self) | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! cstr { | ||
($s:expr) => { | ||
unsafe { ::std::ffi::CStr::from_ptr(concat!($s, "\0").as_ptr() as *const _) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.