Skip to content

Rename to as str #17171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 66 additions & 66 deletions src/libcollections/str.rs

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ impl String {
/// ```
#[inline]
pub fn truncate(&mut self, len: uint) {
assert!(self.as_slice().is_char_boundary(len));
assert!(self.as_str().is_char_boundary(len));
self.vec.truncate(len)
}

Expand Down Expand Up @@ -648,7 +648,7 @@ impl String {
return None
}

let CharRange {ch, next} = self.as_slice().char_range_at_reverse(len);
let CharRange {ch, next} = self.as_str().char_range_at_reverse(len);
unsafe {
self.vec.set_len(next);
}
Expand Down Expand Up @@ -698,7 +698,7 @@ impl String {
return None
}

let CharRange {ch, next} = self.as_slice().char_range_at(0);
let CharRange {ch, next} = self.as_str().char_range_at(0);
let new_len = len - next;
unsafe {
ptr::copy_memory(self.vec.as_mut_ptr(), self.vec.as_ptr().offset(next as int), new_len);
Expand Down Expand Up @@ -760,7 +760,7 @@ impl Extendable<char> for String {

impl Str for String {
#[inline]
fn as_slice<'a>(&'a self) -> &'a str {
fn as_str<'a>(&'a self) -> &'a str {
unsafe {
mem::transmute(self.vec.as_slice())
}
Expand All @@ -782,28 +782,28 @@ impl Default for String {

impl fmt::Show for String {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.as_slice().fmt(f)
self.as_str().fmt(f)
}
}

impl<H: hash::Writer> hash::Hash<H> for String {
#[inline]
fn hash(&self, hasher: &mut H) {
self.as_slice().hash(hasher)
self.as_str().hash(hasher)
}
}

impl<'a, S: Str> Equiv<S> for String {
#[inline]
fn equiv(&self, other: &S) -> bool {
self.as_slice() == other.as_slice()
self.as_str() == other.as_str()
}
}

impl<S: Str> Add<S, String> for String {
fn add(&self, other: &S) -> String {
let mut s = String::from_str(self.as_slice());
s.push_str(other.as_slice());
let mut s = String::from_str(self.as_str());
s.push_str(other.as_str());
return s;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ impl Bool for bool {

impl<'a, T: str::Str> String for T {
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad(self.as_slice())
f.pad(self.as_str())
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,19 +1077,19 @@ pub mod traits {

impl<'a, S: Str> Equiv<S> for &'a str {
#[inline]
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) }
fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_str()) }
}
}

/// Any string that can be represented as a slice
pub trait Str {
/// Work with `self` as a slice.
fn as_slice<'a>(&'a self) -> &'a str;
/// Work with `self` as a &str
fn as_str<'a>(&'a self) -> &'a str;
}

impl<'a> Str for &'a str {
#[inline]
fn as_slice<'a>(&'a self) -> &'a str { *self }
fn as_str<'a>(&'a self) -> &'a str { *self }
}

impl<'a> Collection for &'a str {
Expand Down
2 changes: 1 addition & 1 deletion src/libdebug/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<T> Poly for T {
// this allocation of a new string
_ => {
let s = repr::repr_to_string(self);
f.pad(s.as_slice())
f.pad(s.as_str())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libfmt_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ impl<'a> Parser<'a> {
Some((_, other)) => {
self.err(format!("expected `{}`, found `{}`",
c,
other).as_slice());
other).as_str());
}
None => {
self.err(format!("expected `{}` but string was terminated",
c).as_slice());
c).as_str());
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl OptGroup {
aliases: Vec::new()
},
(1,0) => Opt {
name: Short(short_name.as_slice().char_at(0)),
name: Short(short_name.as_str().char_at(0)),
hasarg: hasarg,
occur: occur,
aliases: Vec::new()
Expand All @@ -263,7 +263,7 @@ impl OptGroup {
occur: occur,
aliases: vec!(
Opt {
name: Short(short_name.as_slice().char_at(0)),
name: Short(short_name.as_str().char_at(0)),
hasarg: hasarg,
occur: occur,
aliases: Vec::new()
Expand Down Expand Up @@ -306,7 +306,7 @@ impl Matches {
pub fn opts_present(&self, names: &[String]) -> bool {
for nm in names.iter() {
match find_opt(self.opts.as_slice(),
Name::from_str(nm.as_slice())) {
Name::from_str(nm.as_str())) {
Some(id) if !self.vals[id].is_empty() => return true,
_ => (),
};
Expand All @@ -317,7 +317,7 @@ impl Matches {
/// Returns the string argument supplied to one of several matching options or `None`.
pub fn opts_str(&self, names: &[String]) -> Option<String> {
for nm in names.iter() {
match self.opt_val(nm.as_slice()) {
match self.opt_val(nm.as_str()) {
Some(Val(ref s)) => return Some(s.clone()),
_ => ()
}
Expand Down Expand Up @@ -547,17 +547,17 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
while i < l {
let cur = args[i].clone();
let curlen = cur.len();
if !is_arg(cur.as_slice()) {
if !is_arg(cur.as_str()) {
free.push(cur);
} else if cur.as_slice() == "--" {
} else if cur.as_str() == "--" {
let mut j = i + 1;
while j < l { free.push(args[j].clone()); j += 1; }
break;
} else {
let mut names;
let mut i_arg = None;
if cur.as_bytes()[1] == b'-' {
let tail = cur.as_slice().slice(2, curlen);
let tail = cur.as_str().slice(2, curlen);
let tail_eq: Vec<&str> = tail.split('=').collect();
if tail_eq.len() <= 1 {
names = vec!(Long(tail.to_string()));
Expand All @@ -570,7 +570,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
let mut j = 1;
names = Vec::new();
while j < curlen {
let range = cur.as_slice().char_range_at(j);
let range = cur.as_str().char_range_at(j);
let opt = Short(range.ch);

/* In a series of potential options (eg. -aheJ), if we
Expand All @@ -593,7 +593,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
};

if arg_follows && range.next < curlen {
i_arg = Some(cur.as_slice()
i_arg = Some(cur.as_str()
.slice(range.next, curlen).to_string());
break;
}
Expand Down Expand Up @@ -621,7 +621,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
.push(Val((i_arg.clone())
.unwrap()));
} else if name_pos < names.len() || i + 1 == l ||
is_arg(args[i + 1].as_slice()) {
is_arg(args[i + 1].as_str()) {
vals.get_mut(optid).push(Given);
} else {
i += 1;
Expand Down Expand Up @@ -686,7 +686,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
0 => {}
1 => {
row.push_char('-');
row.push_str(short_name.as_slice());
row.push_str(short_name.as_str());
row.push_char(' ');
}
_ => fail!("the short name should only be 1 ascii char long"),
Expand All @@ -697,43 +697,43 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
0 => {}
_ => {
row.push_str("--");
row.push_str(long_name.as_slice());
row.push_str(long_name.as_str());
row.push_char(' ');
}
}

// arg
match hasarg {
No => {}
Yes => row.push_str(hint.as_slice()),
Yes => row.push_str(hint.as_str()),
Maybe => {
row.push_char('[');
row.push_str(hint.as_slice());
row.push_str(hint.as_str());
row.push_char(']');
}
}

// FIXME: #5516 should be graphemes not codepoints
// here we just need to indent the start of the description
let rowlen = row.as_slice().char_len();
let rowlen = row.as_str().char_len();
if rowlen < 24 {
for _ in range(0, 24 - rowlen) {
row.push_char(' ');
}
} else {
row.push_str(desc_sep.as_slice())
row.push_str(desc_sep.as_str())
}

// Normalize desc to contain words separated by one space character
let mut desc_normalized_whitespace = String::new();
for word in desc.as_slice().words() {
for word in desc.as_str().words() {
desc_normalized_whitespace.push_str(word);
desc_normalized_whitespace.push_char(' ');
}

// FIXME: #5516 should be graphemes not codepoints
let mut desc_rows = Vec::new();
each_split_within(desc_normalized_whitespace.as_slice(),
each_split_within(desc_normalized_whitespace.as_str(),
54,
|substr| {
desc_rows.push(substr.to_string());
Expand All @@ -742,7 +742,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {

// FIXME: #5516 should be graphemes not codepoints
// wrapped description
row.push_str(desc_rows.connect(desc_sep.as_slice()).as_slice());
row.push_str(desc_rows.connect(desc_sep.as_str()).as_str());

row
});
Expand All @@ -761,18 +761,18 @@ fn format_option(opt: &OptGroup) -> String {
// Use short_name is possible, but fallback to long_name.
if opt.short_name.len() > 0 {
line.push_char('-');
line.push_str(opt.short_name.as_slice());
line.push_str(opt.short_name.as_str());
} else {
line.push_str("--");
line.push_str(opt.long_name.as_slice());
line.push_str(opt.long_name.as_str());
}

if opt.hasarg != No {
line.push_char(' ');
if opt.hasarg == Maybe {
line.push_char('[');
}
line.push_str(opt.hint.as_slice());
line.push_str(opt.hint.as_str());
if opt.hasarg == Maybe {
line.push_char(']');
}
Expand All @@ -795,7 +795,7 @@ pub fn short_usage(program_name: &str, opts: &[OptGroup]) -> String {
.map(format_option)
.collect::<Vec<String>>()
.connect(" ")
.as_slice());
.as_str());
line
}

Expand Down
18 changes: 9 additions & 9 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl<'a> Id<'a> {
pub fn new<Name:str::IntoMaybeOwned<'a>>(name: Name) -> Id<'a> {
let name = name.into_maybe_owned();
{
let mut chars = name.as_slice().chars();
let mut chars = name.as_str().chars();
assert!(is_letter_or_underscore(chars.next().unwrap()));
assert!(chars.all(is_constituent));
}
Expand All @@ -372,7 +372,7 @@ impl<'a> Id<'a> {
}

pub fn as_slice(&'a self) -> &'a str {
self.name.as_slice()
self.name.as_str()
}

pub fn name(self) -> str::MaybeOwned<'a> {
Expand Down Expand Up @@ -434,8 +434,8 @@ impl<'a> LabelText<'a> {
/// Renders text as string suitable for a label in a .dot file.
pub fn escape(&self) -> String {
match self {
&LabelStr(ref s) => s.as_slice().escape_default(),
&EscStr(ref s) => LabelText::escape_str(s.as_slice()),
&LabelStr(ref s) => s.as_str().escape_default(),
&EscStr(ref s) => LabelText::escape_str(s.as_str()),
}
}

Expand All @@ -446,8 +446,8 @@ impl<'a> LabelText<'a> {
fn pre_escaped_content(self) -> str::MaybeOwned<'a> {
match self {
EscStr(s) => s,
LabelStr(s) => if s.as_slice().contains_char('\\') {
str::Owned(s.as_slice().escape_default())
LabelStr(s) => if s.as_str().contains_char('\\') {
str::Owned(s.as_str().escape_default())
} else {
s
},
Expand All @@ -463,7 +463,7 @@ impl<'a> LabelText<'a> {
pub fn suffix_line(self, suffix: LabelText) -> LabelText<'static> {
let prefix = self.pre_escaped_content().into_string();
let suffix = suffix.pre_escaped_content();
EscStr(str::Owned(prefix.append(r"\n\n").append(suffix.as_slice())))
EscStr(str::Owned(prefix.append(r"\n\n").append(suffix.as_str())))
}
}

Expand Down Expand Up @@ -518,7 +518,7 @@ pub fn render<'a, N:'a, E:'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>(
let id = g.node_id(n);
let escaped = g.node_label(n).escape();
try!(writeln(w, [id.as_slice(),
"[label=\"", escaped.as_slice(), "\"];"]));
"[label=\"", escaped.as_str(), "\"];"]));
}

for e in g.edges().iter() {
Expand All @@ -529,7 +529,7 @@ pub fn render<'a, N:'a, E:'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>(
let source_id = g.node_id(&source);
let target_id = g.node_id(&target);
try!(writeln(w, [source_id.as_slice(), " -> ", target_id.as_slice(),
"[label=\"", escaped_label.as_slice(), "\"];"]));
"[label=\"", escaped_label.as_str(), "\"];"]));
}

writeln(w, ["}"])
Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ macro_rules! rtassert (

macro_rules! rtabort (
($($arg:tt)*) => ( {
::macros::abort(format!($($arg)*).as_slice());
::macros::abort(format!($($arg)*).as_str());
} )
)

Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn max_cached_stacks() -> uint {
0 => {}
n => return n - 1,
}
let amt = getenv("RUST_MAX_CACHED_STACKS").and_then(|s| from_str(s.as_slice()));
let amt = getenv("RUST_MAX_CACHED_STACKS").and_then(|s| from_str(s.as_str()));
// This default corresponds to 20M of cache per scheduler (at the
// default size).
let amt = amt.unwrap_or(10);
Expand Down
Loading