Skip to content

Commit

Permalink
doc: Fix extraneous as_slice()'s in docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
richo committed Mar 9, 2015
1 parent 061d843 commit 7981aa6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/doc/style/errors/ergonomics.md
Expand Up @@ -22,9 +22,9 @@ fn write_info(info: &Info) -> Result<(), IoError> {
let mut file = File::open_mode(&Path::new("my_best_friends.txt"),
Open, Write);
// Early return on error
try!(file.write_line(format!("name: {}", info.name).as_slice()));
try!(file.write_line(format!("age: {}", info.age).as_slice()));
try!(file.write_line(format!("rating: {}", info.rating).as_slice()));
try!(file.write_line(&format!("name: {}", info.name)));
try!(file.write_line(&format!("age: {}", info.age)));
try!(file.write_line(&format!("rating: {}", info.rating)));
return Ok(());
}
```
Expand All @@ -44,15 +44,15 @@ fn write_info(info: &Info) -> Result<(), IoError> {
let mut file = File::open_mode(&Path::new("my_best_friends.txt"),
Open, Write);
// Early return on error
match file.write_line(format!("name: {}", info.name).as_slice()) {
match file.write_line(&format!("name: {}", info.name)) {
Ok(_) => (),
Err(e) => return Err(e)
}
match file.write_line(format!("age: {}", info.age).as_slice()) {
match file.write_line(&format!("age: {}", info.age)) {
Ok(_) => (),
Err(e) => return Err(e)
}
return file.write_line(format!("rating: {}", info.rating).as_slice());
return file.write_line(&format!("rating: {}", info.rating));
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/fmt.rs
Expand Up @@ -198,7 +198,7 @@
//! // for details, and the function `pad` can be used to pad strings.
//! let decimals = f.precision().unwrap_or(3);
//! let string = f64::to_str_exact(magnitude, decimals);
//! f.pad_integral(true, "", string.as_slice())
//! f.pad_integral(true, "", &string)
//! }
//! }
//!
Expand Down
10 changes: 5 additions & 5 deletions src/libcollections/string.rs
Expand Up @@ -139,7 +139,7 @@ impl String {
/// ```rust
/// let input = b"Hello \xF0\x90\x80World";
/// let output = String::from_utf8_lossy(input);
/// assert_eq!(output.as_slice(), "Hello \u{FFFD}World");
/// assert_eq!(output, "Hello \u{FFFD}World");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> {
Expand Down Expand Up @@ -355,7 +355,7 @@ impl String {
/// ```
/// let mut s = String::from_str("foo");
/// s.push_str("bar");
/// assert_eq!(s.as_slice(), "foobar");
/// assert_eq!(s, "foobar");
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -450,7 +450,7 @@ impl String {
/// s.push('1');
/// s.push('2');
/// s.push('3');
/// assert_eq!(s.as_slice(), "abc123");
/// assert_eq!(s, "abc123");
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -503,7 +503,7 @@ impl String {
/// ```
/// let mut s = String::from_str("hello");
/// s.truncate(2);
/// assert_eq!(s.as_slice(), "he");
/// assert_eq!(s, "he");
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -622,7 +622,7 @@ impl String {
/// assert!(vec == &[104, 101, 108, 108, 111]);
/// vec.reverse();
/// }
/// assert_eq!(s.as_slice(), "olleh");
/// assert_eq!(s, "olleh");
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/result.rs
Expand Up @@ -178,13 +178,13 @@
//! fn write_info(info: &Info) -> Result<(), IoError> {
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
//! // Early return on error
//! if let Err(e) = file.write_line(format!("name: {}", info.name).as_slice()) {
//! if let Err(e) = file.write_line(&format!("name: {}", info.name)) {
//! return Err(e)
//! }
//! if let Err(e) = file.write_line(format!("age: {}", info.age).as_slice()) {
//! if let Err(e) = file.write_line(&format!("age: {}", info.age)) {
//! return Err(e)
//! }
//! return file.write_line(format!("rating: {}", info.rating).as_slice());
//! return file.write_line(&format!("rating: {}", info.rating));
//! }
//! ```
//!
Expand All @@ -202,9 +202,9 @@
//! fn write_info(info: &Info) -> Result<(), IoError> {
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
//! // Early return on error
//! try!(file.write_line(format!("name: {}", info.name).as_slice()));
//! try!(file.write_line(format!("age: {}", info.age).as_slice()));
//! try!(file.write_line(format!("rating: {}", info.rating).as_slice()));
//! try!(file.write_line(&format!("name: {}", info.name)));
//! try!(file.write_line(&format!("age: {}", info.age)));
//! try!(file.write_line(&format!("rating: {}", info.rating)));
//! return Ok(());
//! }
//! ```
Expand Down
8 changes: 4 additions & 4 deletions src/libgetopts/lib.rs
Expand Up @@ -46,7 +46,7 @@
//!
//! fn print_usage(program: &str, opts: &[OptGroup]) {
//! let brief = format!("Usage: {} [options]", program);
//! print!("{}", usage(brief.as_slice(), opts));
//! print!("{}", usage(brief, opts));
//! }
//!
//! fn main() {
Expand All @@ -63,17 +63,17 @@
//! Err(f) => { panic!(f.to_string()) }
//! };
//! if matches.opt_present("h") {
//! print_usage(program.as_slice(), opts);
//! print_usage(program, opts);
//! return;
//! }
//! let output = matches.opt_str("o");
//! let input = if !matches.free.is_empty() {
//! matches.free[0].clone()
//! } else {
//! print_usage(program.as_slice(), opts);
//! print_usage(program, opts);
//! return;
//! };
//! do_work(input.as_slice(), output);
//! do_work(input, output);
//! }
//! ```

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_bitflags/lib.rs
Expand Up @@ -86,7 +86,7 @@
/// let mut flags = FLAG_A | FLAG_B;
/// flags.clear();
/// assert!(flags.is_empty());
/// assert_eq!(format!("{:?}", flags).as_slice(), "hi!");
/// assert_eq!(format!("{:?}", flags), "hi!");
/// }
/// ```
///
Expand Down
2 changes: 1 addition & 1 deletion src/libserialize/json.rs
Expand Up @@ -188,7 +188,7 @@
//! let json_str: String = json_obj.to_string();
//!
//! // Deserialize like before
//! let decoded: TestStruct = json::decode(json_str.as_slice()).unwrap();
//! let decoded: TestStruct = json::decode(json_str)).unwrap();
//! }
//! ```

Expand Down

0 comments on commit 7981aa6

Please sign in to comment.