These are chat archives for rust-lang/rust

24th
Apr 2016
Paras D. Pain
@ParasDPain
Apr 24 2016 10:50 UTC
Need ideas for a rust crate
Jacob Moen
@jacmoe
Apr 24 2016 13:11 UTC
Any kind of crate?
It would be cool to have something like Gogs (Go Git Service - Github/Gitlab clone in Go) but in Rust. It could be called 'Rugs' (Rust Git Service) :)
yikes, just when I started writing my tool in Rust: http://www.scala-native.org/ :-)
Jacob Moen
@jacmoe
Apr 24 2016 14:07 UTC
The suspense is killing me @soc :smile:
@jacmoe don't worry, was just lamenting the bad timing of my endeavors. :-)
considering that the features Rust gives me are not critical for the tool I'm writing, might make sense to move away from Rust for this tool (especially considering the audience)...
Erik Hedvall
@Ogeon
Apr 24 2016 14:25 UTC

@soc you may have better luck converting converting to an owned string, straight away:

let xdg_cache_home: String = xdg_dirs.get_cache_home().to_str().unwrap().to_string();

Storing the result from xdg_dirs.get_cache_home().to_str().unwrap() requires the result from xdg_dirs.get_cache_home() to live long enough, which I suspect it doesn't.

doesn't work as well, can give you the error message
but less errors ...
Daniel Collin
@emoon
Apr 24 2016 14:30 UTC
take a ref to xdg_cache_home &xdg_cache_home
Erik Hedvall
@Ogeon
Apr 24 2016 14:30 UTC
That's a different error. Adding to a String consumes it and returns a "new" one (actually the same)
alright ... added a clone() ...
@emoon now + is not available anymore
Erik Hedvall
@Ogeon
Apr 24 2016 14:32 UTC
I think clone will be just fine in this case
alright, thanks
Erik Hedvall
@Ogeon
Apr 24 2016 14:33 UTC
It will have to be copied one way or the other, anyway
Daniel Collin
@emoon
Apr 24 2016 14:33 UTC
I guess it’s fine in this case yeah. Just beware of not trying to “default” to clone everything
ok, thanks
is there a concat that returns a new string?
in most cases I don't want to mutate my strings, most of them are fairly constant
Erik Hedvall
@Ogeon
Apr 24 2016 14:35 UTC
Not that I know of. You can also use format!, or keep them as a PathBuf and use first_part.join(second_part)
Actually, working with Path and PathBuf is probably a good idea...
Daniel Collin
@emoon
Apr 24 2016 14:36 UTC
you can do Rust let new_string = my_string + &some_other_string
tried that, didn't work in this case...
I try to stay away from PathBuf operations ... push is just crazy
Erik Hedvall
@Ogeon
Apr 24 2016 14:37 UTC
In what way?
that an absolute path replaces everything else .. that's just on step away from desaster
Erik Hedvall
@Ogeon
Apr 24 2016 14:42 UTC
Yeah, that's a bit icky. It's probably made to work like cd or something.
it should just fail to compile if one tries to append an absolute path to something ...
Daniel Collin
@emoon
Apr 24 2016 14:45 UTC
How can the compiler know that?
types?
Daniel Collin
@emoon
Apr 24 2016 14:45 UTC
you can append an arbitary string as a path, the compiler has no idea whats in the string
less stringly-typed things? :-)
Daniel Collin
@emoon
Apr 24 2016 14:47 UTC
Well you should be able to read a string from disk (or whatever) and use it when building a new path
It would be very restrictive if you could only build paths with known strings
Erik Hedvall
@Ogeon
Apr 24 2016 14:49 UTC
I would have been ok with having a join, that's only able to go deeper, and a navigate (or whatever else), that works like the current join.