Skip to content

Commit

Permalink
Rollup merge of rust-lang#35775 - frewsxcv:os-str-doc-examples, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

Add a few doc examples for `std::ffi::OsStr`.
  • Loading branch information
Jonathan Turner authored Aug 20, 2016
2 parents ba8611e + c2b6f72 commit 54a4199
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ impl Hash for OsString {

impl OsStr {
/// Coerces into an `OsStr` slice.
///
/// # Examples
///
/// ```
/// use std::ffi::OsStr;
///
/// let os_str = OsStr::new("foo");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new<S: AsRef<OsStr> + ?Sized>(s: &S) -> &OsStr {
s.as_ref()
Expand Down Expand Up @@ -283,6 +291,18 @@ impl OsStr {
}

/// Checks whether the `OsStr` is empty.
///
/// # Examples
///
/// ```
/// use std::ffi::OsStr;
///
/// let os_str = OsStr::new("");
/// assert!(os_str.is_empty());
///
/// let os_str = OsStr::new("foo");
/// assert!(!os_str.is_empty());
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
pub fn is_empty(&self) -> bool {
self.inner.inner.is_empty()
Expand All @@ -296,6 +316,18 @@ impl OsStr {
/// other methods like `OsString::with_capacity` to avoid reallocations.
///
/// See `OsStr` introduction for more information about encoding.
///
/// # Examples
///
/// ```
/// use std::ffi::OsStr;
///
/// let os_str = OsStr::new("");
/// assert_eq!(os_str.len(), 0);
///
/// let os_str = OsStr::new("foo");
/// assert_eq!(os_str.len(), 3);
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
pub fn len(&self) -> usize {
self.inner.inner.len()
Expand Down

0 comments on commit 54a4199

Please sign in to comment.