about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-30 12:03:35 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-30 12:03:35 -0800
commita75e308a61be8cc64ed19214daa979c049e7c459 (patch)
tree60db47a131e9cf27e649266b515d9d6bed560ecc /src/doc
parent6ea5fb8a6d3131931dd70d45dc4d4f0b1e26cd01 (diff)
parent19a1f7ed06d3f4f3b64cb4417f7159cd59f38ae7 (diff)
downloadrust-a75e308a61be8cc64ed19214daa979c049e7c459.tar.gz
rust-a75e308a61be8cc64ed19214daa979c049e7c459.zip
rollup merge of #21780: steveklabnik/no_as_slice
Use auto deref instead.
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/reference.md2
-rw-r--r--src/doc/trpl/more-strings.md4
-rw-r--r--src/doc/trpl/patterns.md4
-rw-r--r--src/doc/trpl/plugins.md2
-rw-r--r--src/doc/trpl/strings.md26
5 files changed, 9 insertions, 29 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md
index 686820eb813..936c0aac79f 100644
--- a/src/doc/reference.md
+++ b/src/doc/reference.md
@@ -3518,7 +3518,7 @@ An example of each kind:
 ```{rust}
 let vec: Vec<i32> = vec![1, 2, 3];
 let arr: [i32; 3] = [1, 2, 3];
-let s: &[i32] = vec.as_slice();
+let s: &[i32] = &vec;
 ```
 
 As you can see, the `vec!` macro allows you to create a `Vec<T>` easily. The
diff --git a/src/doc/trpl/more-strings.md b/src/doc/trpl/more-strings.md
index b4669b0819f..986ad23c665 100644
--- a/src/doc/trpl/more-strings.md
+++ b/src/doc/trpl/more-strings.md
@@ -100,7 +100,7 @@ To write a function that's generic over types of strings, use `&str`.
 
 ```
 fn some_string_length(x: &str) -> uint {
-        x.len()
+    x.len()
 }
 
 fn main() {
@@ -110,7 +110,7 @@ fn main() {
 
     let s = "Hello, world".to_string();
 
-    println!("{}", some_string_length(s.as_slice()));
+    println!("{}", some_string_length(&s));
 }
 ```
 
diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md
index 5c7b406a6fc..8240689c24b 100644
--- a/src/doc/trpl/patterns.md
+++ b/src/doc/trpl/patterns.md
@@ -174,13 +174,13 @@ match origin {
 }
 ```
 
-If you want to match against a slice or array, you can use `[]`:
+If you want to match against a slice or array, you can use `&`:
 
 ```{rust}
 fn main() {
     let v = vec!["match_this", "1"];
 
-    match v.as_slice() {
+    match &v {
         ["match_this", second] => println!("The second element is {}", second),
         _ => {},
     }
diff --git a/src/doc/trpl/plugins.md b/src/doc/trpl/plugins.md
index 6e8e2c7ffe2..5ff233b4844 100644
--- a/src/doc/trpl/plugins.md
+++ b/src/doc/trpl/plugins.md
@@ -82,7 +82,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
         }
     };
 
-    let mut text = text.as_slice();
+    let mut text = &text;
     let mut total = 0;
     while !text.is_empty() {
         match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) {
diff --git a/src/doc/trpl/strings.md b/src/doc/trpl/strings.md
index 51f9356bd2f..e05c6e172a4 100644
--- a/src/doc/trpl/strings.md
+++ b/src/doc/trpl/strings.md
@@ -36,36 +36,16 @@ s.push_str(", world.");
 println!("{}", s);
 ```
 
-You can get a `&str` view into a `String` with the `as_slice()` method:
+`String`s will coerece into `&str` with an `&`:
 
-```{rust}
+```
 fn takes_slice(slice: &str) {
     println!("Got: {}", slice);
 }
 
 fn main() {
     let s = "Hello".to_string();
-    takes_slice(s.as_slice());
-}
-```
-
-To compare a String to a constant string, prefer `as_slice()`...
-
-```{rust}
-fn compare(string: String) {
-    if string.as_slice() == "Hello" {
-        println!("yes");
-    }
-}
-```
-
-... over `to_string()`:
-
-```{rust}
-fn compare(string: String) {
-    if string == "Hello".to_string() {
-        println!("yes");
-    }
+    takes_slice(&s);
 }
 ```