These are chat archives for rust-lang/rust

15th
Aug 2017
Jonas Platte
@jplatte
Aug 15 2017 12:14
First time in a while that I've had borrowck issues... Anybody have an idea why rustc complains here? http://i.imgur.com/1g4OXN5.png
The immutable borrow it complains about is in line 25. But that borrow should end at line 32, no??
I used to_owned() exactly because I didn't want the result of that block to have responses lifetime.
Oh.. Figured it out already. to_owned() wasn't doing what I expected it to. Added a type assertion (let cookie: String = ...) and it told me what I did wrong.
Max Frai
@max-frai
Aug 15 2017 12:17
Try to clone cookies from let statement
Jonas Platte
@jplatte
Aug 15 2017 12:17
Yeah that would lead to the exact same issue ^^
Because I used nth and didn't check the error case. So I'm calling to_owned() on Option<&str> which apparently just clones the option.
Added another error type, and with this is now works:
let cookie: String = {
    let &SetCookie(ref cookies) = response
        .headers()
        .get::<SetCookie>()
        .ok_or(error::CookieMissing)?;

    assert!(cookies.len() == 1);
    cookies[0]
        .split(';')
        .nth(0)
        .ok_or(error::InvalidSetCookie)?
        .to_owned()
};
Igor
@target-san
Aug 15 2017 20:08
Does anybody know if it's deemed correct:
std::slice::from_raw_parts_mut(std::ptr::null_mut(), 0usize)
can someone explain rust-lang/rust#42694 to me?
i.e. what's the incantation to make let mut file = File::open("foo.bin")?; work?
Max Frai
@max-frai
Aug 15 2017 20:43
@soc function should return correct Result type
Igor
@target-san
Aug 15 2017 20:43
@soc The return type of function which contains this should be Result<V, E>, where V is an actual result you want, and E is an error type which can be constructed from std::fs::Error. Two simplest cases are std::fs::Result and Box<Error>
@soc please note that ? doesn't do any wild magic, it just performs early return of error value, if one occurs.
thanks