T: Decodable<D>>(
buf: &[u8])
-> T {
- let buf = vec::to_owned(buf);
+ let buf = buf.to_owned();
let buf_reader = @BufReader::new(buf);
let reader = buf_reader as @Reader;
let mut deser: D = FromReader::from_reader(reader);
}
i += 1;
}
- return Ok(Matches {opts: vec::to_owned(opts),
+ return Ok(Matches {opts: opts.to_owned(),
vals: vals,
free: free});
}
let vals = opt_vals(mm, nm);
if vals.is_empty() { return None::<~str>; }
return match vals[0] { Val(ref s) => Some::<~str>(copy *s),
- _ => Some::<~str>(str::to_owned(def)) }
+ _ => Some::<~str>(def.to_owned()) }
}
#[deriving(Eq)]
desc: &str, hint: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
- return OptGroup { short_name: str::to_owned(short_name),
- long_name: str::to_owned(long_name),
- hint: str::to_owned(hint),
- desc: str::to_owned(desc),
+ return OptGroup { short_name: short_name.to_owned(),
+ long_name: long_name.to_owned(),
+ hint: hint.to_owned(),
+ desc: desc.to_owned(),
hasarg: Yes,
occur: Req};
}
desc: &str, hint: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
- return OptGroup {short_name: str::to_owned(short_name),
- long_name: str::to_owned(long_name),
- hint: str::to_owned(hint),
- desc: str::to_owned(desc),
+ return OptGroup {short_name: short_name.to_owned(),
+ long_name: long_name.to_owned(),
+ hint: hint.to_owned(),
+ desc: desc.to_owned(),
hasarg: Yes,
occur: Optional};
}
desc: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
- return OptGroup {short_name: str::to_owned(short_name),
- long_name: str::to_owned(long_name),
+ return OptGroup {short_name: short_name.to_owned(),
+ long_name: long_name.to_owned(),
hint: ~"",
- desc: str::to_owned(desc),
+ desc: desc.to_owned(),
hasarg: No,
occur: Optional};
}
desc: &str, hint: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
- return OptGroup {short_name: str::to_owned(short_name),
- long_name: str::to_owned(long_name),
- hint: str::to_owned(hint),
- desc: str::to_owned(desc),
+ return OptGroup {short_name: short_name.to_owned(),
+ long_name: long_name.to_owned(),
+ hint: hint.to_owned(),
+ desc: desc.to_owned(),
hasarg: Maybe,
occur: Optional};
}
desc: &str, hint: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
- return OptGroup {short_name: str::to_owned(short_name),
- long_name: str::to_owned(long_name),
- hint: str::to_owned(hint),
- desc: str::to_owned(desc),
+ return OptGroup {short_name: short_name.to_owned(),
+ long_name: long_name.to_owned(),
+ hint: hint.to_owned(),
+ desc: desc.to_owned(),
hasarg: Yes,
occur: Multi};
}
row
});
- return str::to_owned(brief) +
+ return brief.to_owned() +
"\n\nOptions:\n" +
rows.connect("\n") +
"\n\n";
let orig_len: u64 = (msg.len() * 8u) as u64;
// pad message
- let mut msg = vec::append(vec::to_owned(msg), [0x80u8]);
+ let mut msg = vec::append(msg.to_owned(), [0x80u8]);
let mut bitlen = orig_len + 8u64;
while (bitlen + 64u64) % 512u64 > 0u64 {
msg.push(0u8);
/// Creates and initializes an BigUint.
pub fn from_slice(slice: &[BigDigit]) -> BigUint {
- return BigUint::new(vec::to_owned(slice));
+ return BigUint::new(slice.to_owned());
}
/// Creates and initializes an BigUint.
fn median(self) -> f64 {
assert!(self.len() != 0);
- let mut tmp = vec::to_owned(self);
+ let mut tmp = self.to_owned();
sort::tim_sort(tmp);
if tmp.len() & 1 == 0 {
let m = tmp.len() / 2;
fn test(s: &str, format: &str) -> bool {
match strptime(s, format) {
- Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
+ Ok(ref tm) => tm.strftime(format) == s.to_owned(),
Err(e) => fail!(e)
}
}
if L < 100 {
do under(uint::min(L, 20)) |i| {
error!("Replacing... #%?", uint::to_str(i));
- let fname = str::to_owned(filename.to_str());
+ let fname = filename.to_str();
do under(uint::min(L, 30)) |j| {
let fname = fname.to_str();
error!("With... %?", stringifier(things[j], intr));
};
return ~[ // Target bindings.
- attr::mk_word_item(@str::to_owned(os::FAMILY)),
+ attr::mk_word_item(@os::FAMILY.to_owned()),
mk(@~"target_os", @tos),
- mk(@~"target_family", @str::to_owned(os::FAMILY)),
+ mk(@~"target_family", @os::FAMILY.to_owned()),
mk(@~"target_arch", @arch),
mk(@~"target_endian", @end),
mk(@~"target_word_size", @wordsz),
let item_doc = lookup_item(id, cdata.data);
let path = {
let item_path = item_path(item_doc);
- vec::to_owned(item_path.init())
+ item_path.init().to_owned()
};
match decode_inlined_item(cdata, tcx, copy path, item_doc) {
Some(ref ii) => csearch::found((/*bad*/copy *ii)),
let writer_bytes: &mut ~[u8] = wr.bytes;
- vec::to_owned(metadata_encoding_version) +
+ metadata_encoding_version.to_owned() +
flate::deflate_bytes(*writer_bytes)
}
@FileSearchImpl {
sysroot: sysroot,
addl_lib_search_paths: addl_lib_search_paths,
- target_triple: str::to_owned(target_triple)
+ target_triple: target_triple.to_owned()
} as @FileSearch
}
pub fn relative_target_lib_path(target_triple: &str) -> Path {
Path(libdir()).push_many([~"rustc",
- str::to_owned(target_triple),
+ target_triple.to_owned(),
libdir()])
}
os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
};
- (str::to_owned(dll_prefix), str::to_owned(dll_suffix))
+ (dll_prefix.to_owned(), dll_suffix.to_owned())
}
fn find_library_crate_aux(
match cx.tcx.def_map.find(&pat_id) {
Some(&def_variant(_, id)) => {
if variant(id) == *ctor_id {
- Some(vec::to_owned(r.tail()))
+ Some(r.tail().to_owned())
} else {
None
}
_ => fail!("type error")
};
if match_ {
- Some(vec::to_owned(r.tail()))
+ Some(r.tail().to_owned())
} else {
None
}
_ => fail!("type error")
};
if match_ {
- Some(vec::to_owned(r.tail()))
+ Some(r.tail().to_owned())
} else {
None
}
Some(args) => args,
None => vec::from_elem(arity, wild())
};
- Some(vec::append(args, vec::to_owned(r.tail())))
+ Some(vec::append(args, r.tail().to_owned()))
}
def_variant(_, _) => None,
Some(args) => new_args = args,
None => new_args = vec::from_elem(arity, wild())
}
- Some(vec::append(new_args, vec::to_owned(r.tail())))
+ Some(vec::append(new_args, r.tail().to_owned()))
}
_ => None
}
_ => wild()
}
});
- Some(vec::append(args, vec::to_owned(r.tail())))
+ Some(vec::append(args, r.tail().to_owned()))
} else {
None
}
_ => wild()
}
});
- Some(vec::append(args, vec::to_owned(r.tail())))
+ Some(vec::append(args, r.tail().to_owned()))
}
}
}
single => true,
_ => fail!("type error")
};
- if match_ { Some(vec::to_owned(r.tail())) } else { None }
+ if match_ { Some(r.tail().to_owned()) } else { None }
}
pat_range(lo, hi) => {
let (c_lo, c_hi) = match *ctor_id {
val(ref v) => ((/*bad*/copy *v), (/*bad*/copy *v)),
range(ref lo, ref hi) =>
((/*bad*/copy *lo), (/*bad*/copy *hi)),
- single => return Some(vec::to_owned(r.tail())),
+ single => return Some(r.tail().to_owned()),
_ => fail!("type error")
};
let v_lo = eval_const_expr(cx.tcx, lo);
let m2 = compare_const_vals(&c_hi, &v_hi);
match (m1, m2) {
(Some(val1), Some(val2)) if val1 >= 0 && val2 <= 0 => {
- Some(vec::to_owned(r.tail()))
+ Some(r.tail().to_owned())
},
(Some(_), Some(_)) => None,
_ => {
}
pub fn default(cx: @MatchCheckCtxt, r: &[@pat]) -> Option<~[@pat]> {
- if is_wild(cx, r[0]) { Some(vec::to_owned(r.tail())) }
+ if is_wild(cx, r[0]) { Some(r.tail().to_owned()) }
else { None }
}
size: machine::llsize_of_alloc(cx, llty_rec) /*bad*/as u64,
align: machine::llalign_of_min(cx, llty_rec) /*bad*/as u64,
packed: packed,
- fields: vec::to_owned(tys)
+ fields: tys.to_owned()
}
}
fn insn_ctxt(&self, s: &str) -> icx_popper {
debug!("new insn_ctxt: %s", s);
if self.sess.count_llvm_insns() {
- self.stats.llvm_insn_ctxt.push(str::to_owned(s));
+ self.stats.llvm_insn_ctxt.push(s.to_owned());
}
icx_popper(*self)
}
}
ast_map::node_variant(ref variant, _, path) => {
- vec::append_one(vec::to_owned(vec::init(*path)),
+ vec::append_one(path.init().to_owned(),
ast_map::path_name((*variant).node.name))
}
});
match idx {
Some(idx) if idx > 2u => {
- str::to_owned(s.slice(0, idx - 1))
+ s.slice_to(idx - 1).to_owned()
}
_ => {
if s.ends_with(".") {
- str::to_owned(s)
+ s.to_owned()
} else {
- str::to_owned(s)
+ s.to_owned()
}
}
}
fn read_lines(&self) -> ~[~str] {
do vec::build |push| {
for self.each_line |line| {
- push(str::to_owned(line));
+ push(line.to_owned());
}
}
}
fn with_filestem(&self, s: &str) -> PosixPath {
match self.filetype() {
None => self.with_filename(s),
- Some(ref t) => self.with_filename(str::to_owned(s) + *t),
+ Some(ref t) => self.with_filename(s.to_owned() + *t),
}
}
(None, None) => {
host = None;
device = None;
- rest = str::to_owned(s);
+ rest = s.to_owned();
}
}
fn with_filestem(&self, s: &str) -> WindowsPath {
match self.filetype() {
None => self.with_filename(s),
- Some(ref t) => self.with_filename(str::to_owned(s) + *t),
+ Some(ref t) => self.with_filename(s.to_owned() + *t),
}
}
fn test_posix_paths() {
fn t(wp: &PosixPath, s: &str) {
let ss = wp.to_str();
- let sss = str::to_owned(s);
+ let sss = s.to_owned();
if (ss != sss) {
debug!("got %s", ss);
debug!("expected %s", sss);
fn test_normalize() {
fn t(wp: &PosixPath, s: &str) {
let ss = wp.to_str();
- let sss = str::to_owned(s);
+ let sss = s.to_owned();
if (ss != sss) {
debug!("got %s", ss);
debug!("expected %s", sss);
fn test_windows_paths() {
fn t(wp: &WindowsPath, s: &str) {
let ss = wp.to_str();
- let sss = str::to_owned(s);
+ let sss = s.to_owned();
if (ss != sss) {
debug!("got %s", ss);
debug!("expected %s", sss);
/// Shuffle a vec
fn shuffle<T:Copy>(&mut self, values: &[T]) -> ~[T] {
- let mut m = vec::to_owned(values);
+ let mut m = values.to_owned();
self.shuffle_mut(m);
m
}
}
}
-/// Copy a slice into a new unique str
-#[inline(always)]
-pub fn to_owned(s: &str) -> ~str {
- unsafe { raw::slice_bytes_owned(s, 0, s.len()) }
-}
-
impl ToStr for ~str {
#[inline(always)]
- fn to_str(&self) -> ~str { to_owned(*self) }
+ fn to_str(&self) -> ~str { self.to_owned() }
}
impl<'self> ToStr for &'self str {
#[inline(always)]
- fn to_str(&self) -> ~str { to_owned(*self) }
+ fn to_str(&self) -> ~str { self.to_owned() }
}
impl ToStr for @str {
#[inline(always)]
- fn to_str(&self) -> ~str { to_owned(*self) }
+ fn to_str(&self) -> ~str { self.to_owned() }
}
/**
*/
pub fn to_bytes(s: &str) -> ~[u8] {
unsafe {
- let mut v: ~[u8] = ::cast::transmute(to_owned(s));
+ let mut v: ~[u8] = ::cast::transmute(s.to_owned());
vec::raw::set_len(&mut v, s.len());
v
}
// NB: len includes the trailing null.
assert!(len > 0);
if unsafe { *(ptr::offset(buf,len-1)) != 0 } {
- to_owned(self).as_c_str(f)
+ self.to_owned().as_c_str(f)
} else {
f(buf as *libc::c_char)
}
impl<'self> Add<&'self str,~str> for ~str {
#[inline(always)]
fn add(&self, rhs: & &'self str) -> ~str {
- append(copy *self, (*rhs))
+ let mut s = self.to_owned();
+ s.push_str(*rhs);
+ s
}
}
}
}
}
-
+ /// Copy a slice into a new unique str
#[inline]
- fn to_owned(&self) -> ~str { to_owned(*self) }
+ fn to_owned(&self) -> ~str {
+ unsafe { raw::slice_bytes_owned(*self, 0, self.len()) }
+ }
+ /// Copy a slice into a new @str
#[inline]
fn to_managed(&self) -> @str {
let v = at_vec::from_fn(self.len() + 1, |i| {
impl Clone for ~str {
#[inline(always)]
fn clone(&self) -> ~str {
- to_owned(*self)
+ self.to_owned()
}
}
assert_eq!("abc".to_managed(), @"abc");
assert_eq!("abcdef".slice(1, 5).to_managed(), @"bcde");
}
+ #[test]
+ fn test_to_owned() {
+ assert_eq!("abc".to_owned(), ~"abc");
+ assert_eq!("abcdef".slice(1, 5).to_owned(), ~"bcde");
+ }
#[test]
fn test_total_ord() {
}
}
-/// Creates a new unique vector with the same contents as the slice
-pub fn to_owned<T:Copy>(t: &[T]) -> ~[T] {
- from_fn(t.len(), |i| t[i])
-}
-
/// Creates a new vector with a capacity of `capacity`
pub fn with_capacity<T>(capacity: uint) -> ~[T] {
let mut vec = ~[];
/// Extension methods for vectors
impl<'self,T:Copy> CopyableVector<T> for &'self [T] {
- /// Returns a copy of `v`.
+ /// Creates a new unique vector with the same contents as the slice
#[inline]
fn to_owned(&self) -> ~[T] {
let mut result = ~[];
result.push(copy *e);
}
result
-
}
}
let mut results: ~[~[int]];
results = ~[];
- for each_permutation([]) |v| { results.push(to_owned(v)); }
+ for each_permutation([]) |v| { results.push(v.to_owned()); }
assert_eq!(results, ~[~[]]);
results = ~[];
- for each_permutation([7]) |v| { results.push(to_owned(v)); }
+ for each_permutation([7]) |v| { results.push(v.to_owned()); }
assert_eq!(results, ~[~[7]]);
results = ~[];
- for each_permutation([1,1]) |v| { results.push(to_owned(v)); }
+ for each_permutation([1,1]) |v| { results.push(v.to_owned()); }
assert_eq!(results, ~[~[1,1],~[1,1]]);
results = ~[];
- for each_permutation([5,2,0]) |v| { results.push(to_owned(v)); }
+ for each_permutation([5,2,0]) |v| { results.push(v.to_owned()); }
assert!(results ==
~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]);
}
pub fn sort_meta_items(items: &[@ast::meta_item]) -> ~[@ast::meta_item] {
// This is sort of stupid here, converting to a vec of mutables and back
- let mut v = vec::to_owned(items);
+ let mut v = items.to_owned();
do extra::sort::quick_sort(v) |ma, mb| {
get_meta_item_name(*ma) <= get_meta_item_name(*mb)
}
-> base::MacResult {
let p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(),
- vec::to_owned(tts));
+ tts.to_owned());
let mut asm = ~"";
let mut outputs = ~[];
-> ~[@ast::expr] {
let p = parse::new_parser_from_tts(cx.parse_sess(),
cx.cfg(),
- vec::to_owned(tts));
+ tts.to_owned());
let mut es = ~[];
while *p.token != token::EOF {
if es.len() != 0 {
cx.print_backtrace();
io::stdout().write_line(
print::pprust::tt_to_str(
- ast::tt_delim(vec::to_owned(tt)),
+ ast::tt_delim(tt.to_owned()),
get_ident_interner()));
//trivial expression
use parse;
use print::pprust;
- use core::str;
-
pub use ast::*;
pub use parse::token::*;
pub use parse::new_parser_from_tts;
impl<'self> ToSource for &'self str {
fn to_source(&self) -> ~str {
- let lit = dummy_spanned(ast::lit_str(@str::to_owned(*self)));
+ let lit = dummy_spanned(ast::lit_str(@self.to_owned()));
pprust::lit_to_str(@lit)
}
}
let p = parse::new_parser_from_tts(
cx.parse_sess(),
cx.cfg(),
- vec::to_owned(tts)
+ tts.to_owned()
);
*p.quote_depth += 1u;
let tts = p.parse_all_token_trees();
let tt_rdr = new_tt_reader(
copy cx.parse_sess().span_diagnostic,
None,
- vec::to_owned(tt)
+ tt.to_owned()
);
let rdr = tt_rdr as @reader;
let rust_parser = Parser(
io::println(fmt!("%s! { %s }",
cx.str_of(name),
print::pprust::tt_to_str(
- ast::tt_delim(vec::to_owned(arg)),
+ ast::tt_delim(arg.to_owned()),
get_ident_interner())));
}
let arg_rdr = new_tt_reader(
s_d,
None,
- vec::to_owned(arg)
+ arg.to_owned()
) as @reader;
match parse(cx.parse_sess(), cx.cfg(), arg_rdr, *mtcs) {
success(named_matches) => {
pub fn main() {
let s = ~"Hello, world!";
- let _s = S { f0: str::to_owned(s), ..S { f0: s, f1: 23 } };
+ let _s = S { f0: s.to_owned(), ..S { f0: s, f1: 23 } };
}
pub fn main() {
let s = ~"Hello, world!";
- let _s = S { f1: str::to_owned(s), f0: s };
+ let _s = S { f1: s.to_owned(), f0: s };
}