aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/ffi
diff options
context:
space:
mode:
authorFenrir <[email protected]>2018-04-14 20:02:05 -0600
committerFenrir <[email protected]>2018-04-21 16:35:01 -0600
commitb330206f5590d88a2f995321d2ea847ded951d1d (patch)
tree4fecd0ca00b754c494e96b13e9837db48de93109 /ctr-std/src/ffi
parentMove more implementation details to `imp` module (diff)
downloadctru-rs-b330206f5590d88a2f995321d2ea847ded951d1d.tar.xz
ctru-rs-b330206f5590d88a2f995321d2ea847ded951d1d.zip
Update for Rust nightly 2018-04-19
Diffstat (limited to 'ctr-std/src/ffi')
-rw-r--r--ctr-std/src/ffi/c_str.rs34
-rw-r--r--ctr-std/src/ffi/os_str.rs30
2 files changed, 48 insertions, 16 deletions
diff --git a/ctr-std/src/ffi/c_str.rs b/ctr-std/src/ffi/c_str.rs
index a19fe82..c88c2bc 100644
--- a/ctr-std/src/ffi/c_str.rs
+++ b/ctr-std/src/ffi/c_str.rs
@@ -91,7 +91,7 @@ use sys;
///
/// # Examples
///
-/// ```no_run
+/// ```ignore (extern-declaration)
/// # fn main() {
/// use std::ffi::CString;
/// use std::os::raw::c_char;
@@ -150,7 +150,7 @@ pub struct CString {
///
/// Inspecting a foreign C string:
///
-/// ```no_run
+/// ```ignore (extern-declaration)
/// use std::ffi::CStr;
/// use std::os::raw::c_char;
///
@@ -164,7 +164,7 @@ pub struct CString {
///
/// Passing a Rust-originating C string:
///
-/// ```no_run
+/// ```ignore (extern-declaration)
/// use std::ffi::{CString, CStr};
/// use std::os::raw::c_char;
///
@@ -180,7 +180,7 @@ pub struct CString {
///
/// Converting a foreign C string into a Rust [`String`]:
///
-/// ```no_run
+/// ```ignore (extern-declaration)
/// use std::ffi::CStr;
/// use std::os::raw::c_char;
///
@@ -307,7 +307,7 @@ impl CString {
///
/// # Examples
///
- /// ```no_run
+ /// ```ignore (extern-declaration)
/// use std::ffi::CString;
/// use std::os::raw::c_char;
///
@@ -389,7 +389,7 @@ impl CString {
/// Create a `CString`, pass ownership to an `extern` function (via raw pointer), then retake
/// ownership with `from_raw`:
///
- /// ```no_run
+ /// ```ignore (extern-declaration)
/// use std::ffi::CString;
/// use std::os::raw::c_char;
///
@@ -875,6 +875,8 @@ impl CStr {
/// `ptr`.
/// * There is no guarantee that the memory pointed to by `ptr` contains a
/// valid nul terminator byte at the end of the string.
+ /// * It is not guaranteed that the memory pointed by `ptr` won't change
+ /// before the `CStr` has been destroyed.
///
/// > **Note**: This operation is intended to be a 0-cost cast but it is
/// > currently implemented with an up-front calculation of the length of
@@ -882,7 +884,7 @@ impl CStr {
///
/// # Examples
///
- /// ```no_run
+ /// ```ignore (extern-declaration)
/// # fn main() {
/// use std::ffi::CStr;
/// use std::os::raw::c_char;
@@ -1026,9 +1028,9 @@ impl CStr {
/// The returned slice will **not** contain the trailing nul terminator that this C
/// string has.
///
- /// > **Note**: This method is currently implemented as a 0-cost cast, but
- /// > it is planned to alter its definition in the future to perform the
- /// > length calculation whenever this method is called.
+ /// > **Note**: This method is currently implemented as a constant-time
+ /// > cast, but it is planned to alter its definition in the future to
+ /// > perform the length calculation whenever this method is called.
///
/// # Examples
///
@@ -1077,9 +1079,9 @@ impl CStr {
/// it will return an error with details of where UTF-8 validation failed.
///
/// > **Note**: This method is currently implemented to check for validity
- /// > after a 0-cost cast, but it is planned to alter its definition in the
- /// > future to perform the length calculation in addition to the UTF-8
- /// > check whenever this method is called.
+ /// > after a constant-time cast, but it is planned to alter its definition
+ /// > in the future to perform the length calculation in addition to the
+ /// > UTF-8 check whenever this method is called.
///
/// [`&str`]: ../primitive.str.html
///
@@ -1110,9 +1112,9 @@ impl CStr {
/// with the result.
///
/// > **Note**: This method is currently implemented to check for validity
- /// > after a 0-cost cast, but it is planned to alter its definition in the
- /// > future to perform the length calculation in addition to the UTF-8
- /// > check whenever this method is called.
+ /// > after a constant-time cast, but it is planned to alter its definition
+ /// > in the future to perform the length calculation in addition to the
+ /// > UTF-8 check whenever this method is called.
///
/// [`Cow`]: ../borrow/enum.Cow.html
/// [`Borrowed`]: ../borrow/enum.Cow.html#variant.Borrowed
diff --git a/ctr-std/src/ffi/os_str.rs b/ctr-std/src/ffi/os_str.rs
index 3959e85..7520121 100644
--- a/ctr-std/src/ffi/os_str.rs
+++ b/ctr-std/src/ffi/os_str.rs
@@ -295,6 +295,36 @@ impl OsString {
self.inner.shrink_to_fit()
}
+ /// Shrinks the capacity of the `OsString` with a lower bound.
+ ///
+ /// The capacity will remain at least as large as both the length
+ /// and the supplied value.
+ ///
+ /// Panics if the current capacity is smaller than the supplied
+ /// minimum capacity.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(shrink_to)]
+ /// use std::ffi::OsString;
+ ///
+ /// let mut s = OsString::from("foo");
+ ///
+ /// s.reserve(100);
+ /// assert!(s.capacity() >= 100);
+ ///
+ /// s.shrink_to(10);
+ /// assert!(s.capacity() >= 10);
+ /// s.shrink_to(0);
+ /// assert!(s.capacity() >= 3);
+ /// ```
+ #[inline]
+ #[unstable(feature = "shrink_to", reason = "new API", issue="0")]
+ pub fn shrink_to(&mut self, min_capacity: usize) {
+ self.inner.shrink_to(min_capacity)
+ }
+
/// Converts this `OsString` into a boxed [`OsStr`].
///
/// [`OsStr`]: struct.OsStr.html