Alright. Thank you. There's still a lot to learn for me coming from a dynamic language like Ruby.
On Mon, May 26, 2014 at 9:41 AM, Vladimir Matveev <dpx.infin...@gmail.com>wrote: > > And hopefully in the future the regular expression library will be > updated to work on StrBuf instead of &str > This is very unlikely. See, you can go from `StrBuf` to `&str` without > allocation - `as_slice()` returns a "view" into the `StrBuf`. This is > very cheap operation. But you cannot go from `&str` to `StrBuf` > without allocation and copying, which are much more expensive than > slicing. Hence you should always try to use `&str` where possible, > only resorting to `StrBuf` when absolutely necessary (for example, > when you need to accumulate a string dynamically). All APIs should > also take `&str` when possible. > > 2014-05-26 11:31 GMT+04:00 Urban Hafner <cont...@urbanhafner.com>: > > Thanks guys, I now use "as_slice()" when necessary. And hopefully in the > > future the regular expression library will be updated to work on StrBuf > > instead of &str as this seems to be the main use case (read in file, run > > regexp on it). > > > > Urban > > > > > > On Mon, May 26, 2014 at 8:58 AM, Vladimir Matveev < > dpx.infin...@gmail.com> > > wrote: > >> > >> > My suspicion is that the automatic conversion will come back at some > >> > point, but I'm not sure. > >> > >> I think it will be possible to make `String` implement `Deref<str>` > >> when DST land. Then it will be possible to convert from `String` to > >> `&str` using explicit reborrowing: > >> > >> let sgf_slice = &*sgf; > >> > >> I'm not sure this will be fully automatic when `String` is an > >> arbitrary actual argument to arbitrary function, however. > >> > >> 2014-05-26 10:36 GMT+04:00 Andrew Gallant <jams...@gmail.com>: > >> > Try using `self.sgf.as_slice()` instead. > >> > > >> > The change is necessary, AFAIK, because `~str` would automatically be > >> > converted to a borrowed reference without having to explicitly call > the > >> > `as_slice` method. This doesn't happen for the StrBuf (and what is now > >> > String, I think) type. > >> > > >> > My suspicion is that the automatic conversion will come back at some > >> > point, but I'm not sure. > >> > > >> > - Andrew > >> > > >> > > >> > On Mon, May 26, 2014 at 2:32 AM, Urban Hafner < > cont...@urbanhafner.com> > >> > wrote: > >> >> Hello there, > >> >> > >> >> I just updated the compiler (I use the git master branch) and now > when > >> >> I > >> >> read in a file I get a StrBuf instead of a ~str. That is easy enough > to > >> >> change, but how do I use regular expressions now? I have the > following > >> >> in my > >> >> code: > >> >> > >> >> let re = regex!(r"SZ\[(\d+)\]"); > >> >> let captures = re.captures(self.sgf).unwrap(); > >> >> > >> >> And it fails now because "self.sgf" is a StrBuf instead of a &str. > Do I > >> >> have > >> >> just a Rust compiler that is somewhere in between (i.e. not > everything > >> >> has > >> >> been changed to StrBuf) or is this intentional? And if so, what's the > >> >> best > >> >> way to use regular expressions now? > >> >> > >> >> Urban > >> >> -- > >> >> Freelancer > >> >> > >> >> Available for hire for Ruby, Ruby on Rails, and JavaScript projects > >> >> > >> >> More at http://urbanhafner.com > >> >> > >> >> _______________________________________________ > >> >> Rust-dev mailing list > >> >> Rust-dev@mozilla.org > >> >> https://mail.mozilla.org/listinfo/rust-dev > >> >> > >> > _______________________________________________ > >> > Rust-dev mailing list > >> > Rust-dev@mozilla.org > >> > https://mail.mozilla.org/listinfo/rust-dev > > > > > > > > > > -- > > Freelancer > > > > Available for hire for Ruby, Ruby on Rails, and JavaScript projects > > > > More at http://urbanhafner.com > -- Freelancer Available for hire for Ruby, Ruby on Rails, and JavaScript projects More at http://urbanhafner.com
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev