[rust-dev] [suggestion] Add ~[mut T].to_str() and @[mut T].to_str() to the core lib

Alexander Tumin itakingiteasy at gmail.com
Wed Jul 18 04:52:33 PDT 2012


Hi, i am not aware of why similar implementations of to_str() for
~[mut T] and @[mut T] are missing and core lib, so i am suggesting to
add them as follows (in rather naive manner, so any change should be
an improvement):

-->8--
import io::*;
import to_str::*;

impl <T : to_str> of to_str for @[mut T] {
    fn to_str() -> ~str {
        (@self).map(|x| { x.to_str() }).to_str()
    }
}

impl <T : to_str copy> of to_str for ~[mut T] {
    fn to_str() -> ~str {
        (~copy self).map(|x| { x.to_str() }).to_str()
    }
}

fn main() {
    println((~[mut 1, 2, 3]).to_str());
    println((@[mut 1, 2, 3]).to_str());
}
-->8--

Thanks.


More information about the Rust-dev mailing list