These are chat archives for rust-lang/rust

14th
Oct 2018
Andrey Lesnikov
@ozkriff
Oct 14 2018 07:51
I guess that their parser can't handle this yet.
David Harvey-Macaulay
@alteous
Oct 14 2018 12:28
Dirk Van Haerenborgh
@vhdirk
Oct 14 2018 13:14
Hi. Anyone here familiar with writing ffi bindings for objects that have dependent lifetimes?
I'm the author of the notmuch crate. When actually using the thing, I'm starting to get really annoyed by the fact that the pointer handles have dependent lifetimes (while the objects the ffi pointers point to live on the heap anyway)
Dirk Van Haerenborgh
@vhdirk
Oct 14 2018 13:19
I've experimented with wrapping the ffi pointers in rc's internally, but then I can't make it Send anymore (unless I send everything). So it'd have to be wrapped in Arc's, but that seems way too heavy. And I'd need additional Mutexes to make it Sync
How are these kind of things solved in other bindings?
Rotem Yaari
@vmalloc
Oct 14 2018 14:41
Is there any convenient way to add automatic conversions from specific errors when using the failure crate? (i.e. specifying which error type should convert to which error enumeration in the new error type)
Alexis Viscogliosi
@alexisvisco
Oct 14 2018 15:16
How do you read in realtime stdout of a process spawned in async ?
Rotem Yaari
@vmalloc
Oct 14 2018 17:04
@AlexisVisco I'm assuming you mean through Command::spawn? What do you mean in real time?
cubetastic
@cubetastic33
Oct 14 2018 17:50
I'm using serde_yaml, and I am storing a boolean in a Yaml file. What I want to do is to reverse the value of the boolean on user input. So, I did this:
if let serde_yaml::Value::Bool(my_boolean) = values["my_boolean"] {
    values.insert("my_boolean".to_string(), serde_yaml::Value::Bool(!my_boolean));
}
file.seek(SeekFrom::Start(0)).unwrap();
serde_yaml::to_writer(&file, &values).unwrap();
Denis Lisov
@tanriol
Oct 14 2018 17:52
@cubetastic33 Why are you using serde_yaml::Value and not normal structures?
cubetastic
@cubetastic33
Oct 14 2018 17:52
@tanriol what do you mean normal structures?
The issue I'm having is, if the value of my_boolean is written to the file as false(which is 5 letters long), and then I write the reversed value, it is written as true(which is 4 letters long)
so the file ends up being my_boolean: truee
Denis Lisov
@tanriol
Oct 14 2018 17:54
When I need a config file or something like that, I usually deserialize it with serde into a structure to avoid the boilerplate...
Well, you need to truncate the file before writing if you do it that way.
cubetastic
@cubetastic33
Oct 14 2018 17:54
This is the first time I'm using serde, I don't really know what you mean by deseiralize it into a structure...
Also, how do I truncate the file?
Denis Lisov
@tanriol
Oct 14 2018 18:10
There's File::set_len
Ryan Levick
@rylev
Oct 14 2018 18:11
@cubetastic33 I think @tanriol was asking if it would be easier to derive the serialization: https://serde.rs/derive.html
Sylwester Rąpała
@xoac
Oct 14 2018 18:36

Hi, I just try to switch from actix to warp and come to some problem. Warp use Filter to match HTTP request. I would like to match it like:

  1. match path "fire"
  2. match query (TimeoutQuery and map it to RequestBuilder)
  3. match GET.and_then(do_sth) or PUT.and_then(do_sth2) or more..

And I can't do this working that way. I just curious I do sth wrong or it's impossible. The way I did it at this moment:

    let req_builder2 = req_builder.clone();
    let routes = warp::path("/fire").and( //1
        warp::get2() //3
            .and(warp::query()) //2
            .and_then(move |tout: TimeoutQuery| { //2
                let rb = req_builder.clone().with_timeout(tout.timeout); //2
                rb.get_fire_status()
                    .map(|fire_status| warp::reply::json(&fire_status))
                    .map_err(|err| warp::reject::server_error())
            }).or(warp::put2().and(warp::query()).and_then( //3 and 2
                move |tout: TimeoutQuery| { // 2
                    let rb = req_builder2.clone().with_timeout(tout.timeout); //2
                    rb.active_fire() //3
                        .map(|_ok| warp::reply())
                        .map_err(|err| warp::reject::server_error())
                },
            )),
    );
this code dosen't work
let routes =
        warp::path("/fire") // 1
        .and(warp::query().map(|tout: TimeoutQuery| req_builder.clone().with_timeout(tout.timeout)) //2
        .and(
            warp::get2() //3
                .and_then(|rb: RequestBuilder| {
                    rb.get_fire_status()
                        .map(|fire_status| warp::reply::json(&fire_status))
                        .map_err(|err| warp::reject::server_error())
                }).or(
            warp::put2().and_then(|rb: RequestBuilder| { //3
                    rb.active_fire()
                        .map(|_ok| warp::reply())
                        .map_err(|err| warp::reject::server_error())
                })),
        ));
tsoernes
@tsoernes
Oct 14 2018 21:37
was there a new feature allowing for marking functions as pure?
Denis Lisov
@tanriol
Oct 14 2018 21:38
Don't remember anything like that.
There are const functions, but that's not about purity.
tsoernes
@tsoernes
Oct 14 2018 21:38
i must have misunderstood.
John
@gitlabaccount624_gitlab
Oct 14 2018 21:38
aren't const functions pure?
Denis Lisov
@tanriol
Oct 14 2018 21:39
They are, but their requirements are much more strict.
tsoernes
@tsoernes
Oct 14 2018 21:39
what reqs in addition to purity
in any case going over your code base marking functions as const where applicable would be a code quality increase.. no?
John
@gitlabaccount624_gitlab
Oct 14 2018 21:42
not sure im still waiting on blogposts to explain it all monkey-speak for me. is it even on stable yet?
Denis Lisov
@tanriol
Oct 14 2018 21:44
Note that if you're writing a library, removing const in a newer version is a breaking change, so you should not mark functions as const unless you want to provide this guarantee.
Here's a description of what's going stable in 1.31