aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/ffi
diff options
context:
space:
mode:
authorFenrir <[email protected]>2018-08-19 17:48:00 -0600
committerFenrir <[email protected]>2018-08-19 17:56:18 -0600
commit5d28bfcfd6086c3328837de9695099ea39048d0d (patch)
treea514fde042ff2a504a03305bfe0894ff8cd8d47e /ctr-std/src/ffi
parentUpdate for latest nightly 2018-06-09 (#70) (diff)
downloadctru-rs-5d28bfcfd6086c3328837de9695099ea39048d0d.tar.xz
ctru-rs-5d28bfcfd6086c3328837de9695099ea39048d0d.zip
Update for nightly-2018-08-18
Diffstat (limited to 'ctr-std/src/ffi')
-rw-r--r--ctr-std/src/ffi/c_str.rs43
-rw-r--r--ctr-std/src/ffi/os_str.rs48
2 files changed, 86 insertions, 5 deletions
diff --git a/ctr-std/src/ffi/c_str.rs b/ctr-std/src/ffi/c_str.rs
index 52372df..06edd29 100644
--- a/ctr-std/src/ffi/c_str.rs
+++ b/ctr-std/src/ffi/c_str.rs
@@ -692,6 +692,12 @@ impl fmt::Debug for CString {
#[stable(feature = "cstring_into", since = "1.7.0")]
impl From<CString> for Vec<u8> {
+ /// Converts a [`CString`] into a [`Vec`]`<u8>`.
+ ///
+ /// The conversion consumes the [`CString`], and removes the terminating NUL byte.
+ ///
+ /// [`Vec`]: ../vec/struct.Vec.html
+ /// [`CString`]: ../ffi/struct.CString.html
#[inline]
fn from(s: CString) -> Vec<u8> {
s.into_bytes()
@@ -750,14 +756,30 @@ impl<'a> From<&'a CStr> for Box<CStr> {
#[stable(feature = "c_string_from_box", since = "1.18.0")]
impl From<Box<CStr>> for CString {
+ /// Converts a [`Box`]`<CStr>` into a [`CString`] without copying or allocating.
+ ///
+ /// [`Box`]: ../boxed/struct.Box.html
+ /// [`CString`]: ../ffi/struct.CString.html
#[inline]
fn from(s: Box<CStr>) -> CString {
s.into_c_string()
}
}
+#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
+impl Clone for Box<CStr> {
+ #[inline]
+ fn clone(&self) -> Self {
+ (**self).into()
+ }
+}
+
#[stable(feature = "box_from_c_string", since = "1.20.0")]
impl From<CString> for Box<CStr> {
+ /// Converts a [`CString`] into a [`Box`]`<CStr>` without copying or allocating.
+ ///
+ /// [`CString`]: ../ffi/struct.CString.html
+ /// [`Box`]: ../boxed/struct.Box.html
#[inline]
fn from(s: CString) -> Box<CStr> {
s.into_boxed_c_str()
@@ -790,6 +812,10 @@ impl<'a> From<&'a CString> for Cow<'a, CStr> {
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<CString> for Arc<CStr> {
+ /// Converts a [`CString`] into a [`Arc`]`<CStr>` without copying or allocating.
+ ///
+ /// [`CString`]: ../ffi/struct.CString.html
+ /// [`Arc`]: ../sync/struct.Arc.html
#[inline]
fn from(s: CString) -> Arc<CStr> {
let arc: Arc<[u8]> = Arc::from(s.into_inner());
@@ -808,6 +834,10 @@ impl<'a> From<&'a CStr> for Arc<CStr> {
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<CString> for Rc<CStr> {
+ /// Converts a [`CString`] into a [`Rc`]`<CStr>` without copying or allocating.
+ ///
+ /// [`CString`]: ../ffi/struct.CString.html
+ /// [`Rc`]: ../rc/struct.Rc.html
#[inline]
fn from(s: CString) -> Rc<CStr> {
let rc: Rc<[u8]> = Rc::from(s.into_inner());
@@ -881,6 +911,10 @@ impl fmt::Display for NulError {
#[stable(feature = "rust1", since = "1.0.0")]
impl From<NulError> for io::Error {
+ /// Converts a [`NulError`] into a [`io::Error`].
+ ///
+ /// [`NulError`]: ../ffi/struct.NulError.html
+ /// [`io::Error`]: ../io/struct.Error.html
fn from(_: NulError) -> io::Error {
io::Error::new(io::ErrorKind::InvalidInput,
"data provided contains a nul byte")
@@ -933,7 +967,7 @@ impl Error for IntoStringError {
"C string contained non-utf8 bytes"
}
- fn cause(&self) -> Option<&Error> {
+ fn cause(&self) -> Option<&dyn Error> {
Some(&self.error)
}
}
@@ -1234,9 +1268,9 @@ impl CStr {
/// If the contents of the `CStr` are valid UTF-8 data, this
/// function will return a [`Cow`]`::`[`Borrowed`]`(`[`&str`]`)`
/// with the the corresponding [`&str`] slice. Otherwise, it will
- /// replace any invalid UTF-8 sequences with `U+FFFD REPLACEMENT
- /// CHARACTER` and return a [`Cow`]`::`[`Owned`]`(`[`String`]`)`
- /// with the result.
+ /// replace any invalid UTF-8 sequences with
+ /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
+ /// [`Cow`]`::`[`Owned`]`(`[`String`]`)` with the result.
///
/// > **Note**: This method is currently implemented to check for validity
/// > after a constant-time cast, but it is planned to alter its definition
@@ -1248,6 +1282,7 @@ impl CStr {
/// [`Owned`]: ../borrow/enum.Cow.html#variant.Owned
/// [`str`]: ../primitive.str.html
/// [`String`]: ../string/struct.String.html
+ /// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html
///
/// # Examples
///
diff --git a/ctr-std/src/ffi/os_str.rs b/ctr-std/src/ffi/os_str.rs
index 0a31480..6bcd62d 100644
--- a/ctr-std/src/ffi/os_str.rs
+++ b/ctr-std/src/ffi/os_str.rs
@@ -348,6 +348,12 @@ impl OsString {
#[stable(feature = "rust1", since = "1.0.0")]
impl From<String> for OsString {
+ /// Converts a [`String`] into a [`OsString`].
+ ///
+ /// The conversion copies the data, and includes an allocation on the heap.
+ ///
+ /// [`String`]: ../string/struct.String.html
+ /// [`OsString`]: struct.OsString.html
fn from(s: String) -> OsString {
OsString { inner: Buf::from_string(s) }
}
@@ -417,6 +423,20 @@ impl PartialEq<OsString> for str {
}
}
+#[stable(feature = "os_str_str_ref_eq", since = "1.28.0")]
+impl<'a> PartialEq<&'a str> for OsString {
+ fn eq(&self, other: &&'a str) -> bool {
+ **self == **other
+ }
+}
+
+#[stable(feature = "os_str_str_ref_eq", since = "1.28.0")]
+impl<'a> PartialEq<OsString> for &'a str {
+ fn eq(&self, other: &OsString) -> bool {
+ **other == **self
+ }
+}
+
#[stable(feature = "rust1", since = "1.0.0")]
impl Eq for OsString {}
@@ -500,10 +520,12 @@ impl OsStr {
/// Converts an `OsStr` to a [`Cow`]`<`[`str`]`>`.
///
- /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
+ /// Any non-Unicode sequences are replaced with
+ /// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD].
///
/// [`Cow`]: ../../std/borrow/enum.Cow.html
/// [`str`]: ../../std/primitive.str.html
+ /// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html
///
/// # Examples
///
@@ -616,6 +638,10 @@ impl<'a> From<&'a OsStr> for Box<OsStr> {
#[stable(feature = "os_string_from_box", since = "1.18.0")]
impl From<Box<OsStr>> for OsString {
+ /// Converts a `Box<OsStr>` into a `OsString` without copying or allocating.
+ ///
+ /// [`Box`]: ../boxed/struct.Box.html
+ /// [`OsString`]: ../ffi/struct.OsString.html
fn from(boxed: Box<OsStr>) -> OsString {
boxed.into_os_string()
}
@@ -623,13 +649,29 @@ impl From<Box<OsStr>> for OsString {
#[stable(feature = "box_from_os_string", since = "1.20.0")]
impl From<OsString> for Box<OsStr> {
+ /// Converts a [`OsString`] into a [`Box`]`<OsStr>` without copying or allocating.
+ ///
+ /// [`Box`]: ../boxed/struct.Box.html
+ /// [`OsString`]: ../ffi/struct.OsString.html
fn from(s: OsString) -> Box<OsStr> {
s.into_boxed_os_str()
}
}
+#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
+impl Clone for Box<OsStr> {
+ #[inline]
+ fn clone(&self) -> Self {
+ self.to_os_string().into_boxed_os_str()
+ }
+}
+
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<OsString> for Arc<OsStr> {
+ /// Converts a [`OsString`] into a [`Arc`]`<OsStr>` without copying or allocating.
+ ///
+ /// [`Arc`]: ../sync/struct.Arc.html
+ /// [`OsString`]: ../ffi/struct.OsString.html
#[inline]
fn from(s: OsString) -> Arc<OsStr> {
let arc = s.inner.into_arc();
@@ -648,6 +690,10 @@ impl<'a> From<&'a OsStr> for Arc<OsStr> {
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<OsString> for Rc<OsStr> {
+ /// Converts a [`OsString`] into a [`Rc`]`<OsStr>` without copying or allocating.
+ ///
+ /// [`Rc`]: ../rc/struct.Rc.html
+ /// [`OsString`]: ../ffi/struct.OsString.html
#[inline]
fn from(s: OsString) -> Rc<OsStr> {
let rc = s.inner.into_rc();