Skip to content

Commit b84c0dc

Browse files
committed
doc: Remove all uses of ~str from the documentation.
1 parent 1fb08f1 commit b84c0dc

File tree

9 files changed

+52
-51
lines changed

9 files changed

+52
-51
lines changed

src/doc/complement-cheatsheet.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Use [`ToStr`](http://static.rust-lang.org/doc/master/std/to_str/trait.ToStr.html
88

99
~~~
1010
let x: int = 42;
11-
let y: ~str = x.to_str();
11+
let y: StrBuf = x.to_str().to_strbuf();
1212
~~~
1313

1414
**String to int**
@@ -22,14 +22,14 @@ let y: int = x.unwrap();
2222

2323
**Int to string, in non-base-10**
2424

25-
Use the `format!` syntax extension.
25+
Use the `format_strbuf!` syntax extension.
2626

2727
~~~
2828
let x: int = 42;
29-
let y: ~str = format!("{:t}", x); // binary
30-
let y: ~str = format!("{:o}", x); // octal
31-
let y: ~str = format!("{:x}", x); // lowercase hexadecimal
32-
let y: ~str = format!("{:X}", x); // uppercase hexadecimal
29+
let y: StrBuf = format_strbuf!("{:t}", x); // binary
30+
let y: StrBuf = format_strbuf!("{:o}", x); // octal
31+
let y: StrBuf = format_strbuf!("{:x}", x); // lowercase hexadecimal
32+
let y: StrBuf = format_strbuf!("{:X}", x); // uppercase hexadecimal
3333
~~~
3434

3535
**String to int, in non-base-10**
@@ -55,13 +55,14 @@ let x: Option<&str> = str::from_utf8(bytes);
5555
let y: &str = x.unwrap();
5656
~~~
5757

58-
To return an Owned String (~str) use the str helper function [`from_utf8_owned`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8_owned.html).
58+
To return an Owned String (StrBuf) use the str helper function [`from_utf8_owned`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8_owned.html).
5959

6060
~~~
6161
use std::str;
6262
63-
let x: Result<~str,~[u8]> = str::from_utf8_owned(~[104u8,105u8]);
64-
let y: ~str = x.unwrap();
63+
let x: Result<StrBuf,~[u8]> =
64+
str::from_utf8_owned(~[104u8,105u8]).map(|x| x.to_strbuf());
65+
let y: StrBuf = x.unwrap();
6566
~~~
6667

6768
To return a [`MaybeOwned`](http://static.rust-lang.org/doc/master/std/str/enum.MaybeOwned.html) use the str helper function [`from_utf8_lossy`](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8_owned.html). This function also replaces non-valid utf-8 sequences with U+FFFD replacement character.
@@ -181,7 +182,7 @@ enum Closed {}
181182
Phantom types are useful for enforcing state at compile time. For example:
182183

183184
~~~
184-
struct Door<State>(~str);
185+
struct Door<State>(StrBuf);
185186
186187
struct Open;
187188
struct Closed;
@@ -194,13 +195,13 @@ fn open(Door(name): Door<Closed>) -> Door<Open> {
194195
Door::<Open>(name)
195196
}
196197
197-
let _ = close(Door::<Open>("front".to_owned()));
198+
let _ = close(Door::<Open>("front".to_strbuf()));
198199
~~~
199200

200201
Attempting to close a closed door is prevented statically:
201202

202203
~~~ {.ignore}
203-
let _ = close(Door::<Closed>("front".to_owned())); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
204+
let _ = close(Door::<Closed>("front".to_strbuf())); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
204205
~~~
205206

206207
# FFI (Foreign Function Interface)

src/doc/guide-macros.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ To take as an argument a fragment of Rust code, write `$` followed by a name
8585
`foo`.)
8686
* `expr` (an expression. Examples: `2 + 2`; `if true then { 1 } else { 2 }`;
8787
`f(42)`.)
88-
* `ty` (a type. Examples: `int`, `~[(char, ~str)]`, `&T`.)
88+
* `ty` (a type. Examples: `int`, `~[(char, StrBuf)]`, `&T`.)
8989
* `pat` (a pattern, usually appearing in a `match` or on the left-hand side of
9090
a declaration. Examples: `Some(t)`; `(17, 'a')`; `_`.)
9191
* `block` (a sequence of actions. Example: `{ log(error, "hi"); return 12; }`)

src/doc/guide-tasks.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,11 @@ Here is the function that implements the child task:
463463
~~~
464464
extern crate sync;
465465
# fn main() {
466-
fn stringifier(channel: &sync::DuplexStream<~str, uint>) {
466+
fn stringifier(channel: &sync::DuplexStream<StrBuf, uint>) {
467467
let mut value: uint;
468468
loop {
469469
value = channel.recv();
470-
channel.send(value.to_str());
470+
channel.send(value.to_str().to_strbuf());
471471
if value == 0 { break; }
472472
}
473473
}
@@ -488,11 +488,11 @@ Here is the code for the parent task:
488488
extern crate sync;
489489
# use std::task::spawn;
490490
# use sync::DuplexStream;
491-
# fn stringifier(channel: &sync::DuplexStream<~str, uint>) {
491+
# fn stringifier(channel: &sync::DuplexStream<StrBuf, uint>) {
492492
# let mut value: uint;
493493
# loop {
494494
# value = channel.recv();
495-
# channel.send(value.to_str());
495+
# channel.send(value.to_str().to_strbuf());
496496
# if value == 0u { break; }
497497
# }
498498
# }
@@ -505,13 +505,13 @@ spawn(proc() {
505505
});
506506
507507
from_child.send(22);
508-
assert!(from_child.recv() == "22".to_owned());
508+
assert!(from_child.recv().as_slice() == "22");
509509
510510
from_child.send(23);
511511
from_child.send(0);
512512
513-
assert!(from_child.recv() == "23".to_owned());
514-
assert!(from_child.recv() == "0".to_owned());
513+
assert!(from_child.recv().as_slice() == "23");
514+
assert!(from_child.recv().as_slice() == "0");
515515
516516
# }
517517
~~~

src/doc/po/ja/complement-cheatsheet.md.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ msgstr ""
3434
#, fuzzy
3535
#| msgid ""
3636
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
37-
msgid "~~~ let x: int = 42; let y: ~str = x.to_str(); ~~~"
37+
msgid "~~~ let x: int = 42; let y: StrBuf = x.to_str(); ~~~"
3838
msgstr ""
3939
"~~~~\n"
4040
"let x: f64 = 4.0;\n"
@@ -96,7 +96,7 @@ msgstr ""
9696
#, fuzzy
9797
#| msgid ""
9898
#| "~~~~ let x: f64 = 4.0; let y: uint = x as uint; assert!(y == 4u); ~~~~"
99-
msgid "let x: int = 42; let y: ~str = x.to_str_radix(16); ~~~"
99+
msgid "let x: int = 42; let y: StrBuf = x.to_str_radix(16); ~~~"
100100
msgstr ""
101101
"~~~~\n"
102102
"let x: f64 = 4.0;\n"

src/doc/po/ja/rust.md.po

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ msgstr "## 最小限の例"
16411641
msgid ""
16421642
"~~~~\n"
16431643
"trait Printable {\n"
1644-
" fn to_string(&self) -> ~str;\n"
1644+
" fn to_string(&self) -> StrBuf;\n"
16451645
"}\n"
16461646
msgstr ""
16471647
"~~~~ {.ignore}\n"
@@ -1656,7 +1656,7 @@ msgstr ""
16561656
#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
16571657
msgid ""
16581658
"impl Printable for int {\n"
1659-
" fn to_string(&self) -> ~str { self.to_str() }\n"
1659+
" fn to_string(&self) -> StrBuf { self.to_str() }\n"
16601660
"}\n"
16611661
msgstr ""
16621662
"~~~~ {.ignore}\n"
@@ -1702,7 +1702,7 @@ msgstr "# クロージャ"
17021702
msgid ""
17031703
"~~~~\n"
17041704
"trait Printable {\n"
1705-
" fn make_string(&self) -> ~str;\n"
1705+
" fn make_string(&self) -> StrBuf;\n"
17061706
"}\n"
17071707
msgstr ""
17081708
"~~~~ {.ignore}\n"
@@ -1716,8 +1716,8 @@ msgstr ""
17161716
#, fuzzy, no-wrap
17171717
#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
17181718
msgid ""
1719-
"impl Printable for ~str {\n"
1720-
" fn make_string(&self) -> ~str {\n"
1719+
"impl Printable for StrBuf {\n"
1720+
" fn make_string(&self) -> StrBuf {\n"
17211721
" (*self).clone()\n"
17221722
" }\n"
17231723
"}\n"

src/doc/po/ja/tutorial.md.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,15 +3755,15 @@ msgstr ""
37553755
#| msgid ""
37563756
#| "Traits may be implemented for specific types with [impls]. An impl that "
37573757
#| "implements a trait includes the name of the trait at the start of the "
3758-
#| "definition, as in the following impls of `Printable` for `int` and `~str`."
3758+
#| "definition, as in the following impls of `Printable` for `int` and `StrBuf`."
37593759
msgid ""
37603760
"Traits may be implemented for specific types with [impls]. An impl for a "
37613761
"particular trait gives an implementation of the methods that trait "
37623762
"provides. For instance, the following impls of `Printable` for `int` and "
3763-
"`~str` give implementations of the `print` method."
3763+
"`StrBuf` give implementations of the `print` method."
37643764
msgstr ""
37653765
"[impl][impls] により特定の型にトレイトを実装することができます。トレイトを実"
3766-
"装する impl は、以下の `Printable` の `int` と `~str` に対する実装のように、"
3766+
"装する impl は、以下の `Printable` の `int` と `StrBuf` に対する実装のように、"
37673767
"定義の先頭にトレイトの名前を含みます。"
37683768

37693769
#. type: Plain text
@@ -3776,7 +3776,7 @@ msgstr "[impls]: #メソッド"
37763776
#, fuzzy, no-wrap
37773777
#| msgid "~~~~ {.ignore} // main.rs extern crate world; fn main() { println(~\"hello \" + world::explore()); } ~~~~"
37783778
msgid ""
3779-
"impl Printable for ~str {\n"
3779+
"impl Printable for StrBuf {\n"
37803780
" fn print(&self) { println!(\"{}\", *self) }\n"
37813781
"}\n"
37823782
msgstr ""

src/doc/rust.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ Two examples of paths with type arguments:
473473
# struct HashMap<K, V>;
474474
# fn f() {
475475
# fn id<T>(t: T) -> T { t }
476-
type T = HashMap<int,~str>; // Type arguments used in a type expression
476+
type T = HashMap<int,StrBuf>; // Type arguments used in a type expression
477477
let x = id::<int>(10); // Type arguments used in a call expression
478478
# }
479479
~~~~
@@ -1259,12 +1259,12 @@ Enumeration constructors can have either named or unnamed fields:
12591259

12601260
~~~~
12611261
enum Animal {
1262-
Dog (~str, f64),
1263-
Cat { name: ~str, weight: f64 }
1262+
Dog (StrBuf, f64),
1263+
Cat { name: StrBuf, weight: f64 }
12641264
}
12651265
1266-
let mut a: Animal = Dog("Cocoa".to_owned(), 37.2);
1267-
a = Cat{ name: "Spotty".to_owned(), weight: 2.7 };
1266+
let mut a: Animal = Dog("Cocoa".to_strbuf(), 37.2);
1267+
a = Cat { name: "Spotty".to_strbuf(), weight: 2.7 };
12681268
~~~~
12691269

12701270
In this example, `Cat` is a _struct-like enum variant_,
@@ -2081,7 +2081,7 @@ These are functions:
20812081
* `str_eq`
20822082
: Compare two strings (`&str`) for equality.
20832083
* `uniq_str_eq`
2084-
: Compare two owned strings (`~str`) for equality.
2084+
: Compare two owned strings (`StrBuf`) for equality.
20852085
* `strdup_uniq`
20862086
: Return a new unique string
20872087
containing a copy of the contents of a unique string.
@@ -3309,7 +3309,7 @@ A value of type `str` is a Unicode string,
33093309
represented as a vector of 8-bit unsigned bytes holding a sequence of UTF-8 codepoints.
33103310
Since `str` is of unknown size, it is not a _first class_ type,
33113311
but can only be instantiated through a pointer type,
3312-
such as `&str` or `~str`.
3312+
such as `&str` or `StrBuf`.
33133313

33143314
### Tuple types
33153315

@@ -3573,11 +3573,11 @@ An example of an object type:
35733573

35743574
~~~~
35753575
trait Printable {
3576-
fn to_string(&self) -> ~str;
3576+
fn to_string(&self) -> StrBuf;
35773577
}
35783578
35793579
impl Printable for int {
3580-
fn to_string(&self) -> ~str { self.to_str() }
3580+
fn to_string(&self) -> StrBuf { self.to_str().to_strbuf() }
35813581
}
35823582
35833583
fn print(a: Box<Printable>) {
@@ -3618,17 +3618,17 @@ example, in:
36183618

36193619
~~~~
36203620
trait Printable {
3621-
fn make_string(&self) -> ~str;
3621+
fn make_string(&self) -> StrBuf;
36223622
}
36233623
3624-
impl Printable for ~str {
3625-
fn make_string(&self) -> ~str {
3624+
impl Printable for StrBuf {
3625+
fn make_string(&self) -> StrBuf {
36263626
(*self).clone()
36273627
}
36283628
}
36293629
~~~~
36303630

3631-
`self` refers to the value of type `~str` that is the receiver for a
3631+
`self` refers to the value of type `StrBuf` that is the receiver for a
36323632
call to the method `make_string`.
36333633

36343634
## Type kinds

src/doc/rustdoc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ comments":
2626
pub struct Widget {
2727
/// All widgets have a purpose (this is a doc comment, and will show up
2828
/// the field's documentation).
29-
purpose: ~str,
29+
purpose: StrBuf,
3030
/// Humans are not allowed to understand some widgets
3131
understandable: bool
3232
}

src/doc/tutorial.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@ don't provide any methods.
22132213
Traits may be implemented for specific types with [impls]. An impl for
22142214
a particular trait gives an implementation of the methods that
22152215
trait provides. For instance, the following impls of
2216-
`Printable` for `int` and `~str` give implementations of the `print`
2216+
`Printable` for `int` and `StrBuf` give implementations of the `print`
22172217
method.
22182218

22192219
[impls]: #methods
@@ -2224,12 +2224,12 @@ impl Printable for int {
22242224
fn print(&self) { println!("{:?}", *self) }
22252225
}
22262226
2227-
impl Printable for ~str {
2227+
impl Printable for StrBuf {
22282228
fn print(&self) { println!("{}", *self) }
22292229
}
22302230
22312231
# 1.print();
2232-
# ("foo".to_owned()).print();
2232+
# ("foo".to_strbuf()).print();
22332233
~~~~
22342234

22352235
Methods defined in an impl for a trait may be called just like
@@ -2270,7 +2270,7 @@ trait Printable {
22702270
22712271
impl Printable for int {}
22722272
2273-
impl Printable for ~str {
2273+
impl Printable for StrBuf {
22742274
fn print(&self) { println!("{}", *self) }
22752275
}
22762276
@@ -2279,7 +2279,7 @@ impl Printable for bool {}
22792279
impl Printable for f32 {}
22802280
22812281
# 1.print();
2282-
# ("foo".to_owned()).print();
2282+
# ("foo".to_strbuf()).print();
22832283
# true.print();
22842284
# 3.14159.print();
22852285
~~~~
@@ -2291,7 +2291,7 @@ provided in the trait definition. Depending on the trait, default
22912291
methods can save a great deal of boilerplate code from having to be
22922292
written in impls. Of course, individual impls can still override the
22932293
default method for `print`, as is being done above in the impl for
2294-
`~str`.
2294+
`StrBuf`.
22952295

22962296
## Type-parameterized traits
22972297

0 commit comments

Comments
 (0)