These are chat archives for rust-lang/rust

Jun 2018
Jun 10 2018 00:17 UTC
Anybody know/have recommendations about mqtt libraries? All I have managed to find are either pre-alpha or abandoned..
Fredrik Portström
Jun 10 2018 08:39 UTC
@trsh Your code allocates no memory.
Jun 10 2018 08:41 UTC
That's stack allocations. 4 stack allocations
last one allocates fixed amount of bytes for any type (4 on 32bit and 8 on 64bit system).
Fredrik Portström
Jun 10 2018 08:46 UTC
The entire stack (2 MB by default) is allocated up front, and no memory allocations are made when putting values on the stack.
Fredrik Portström
Jun 10 2018 09:05 UTC
If your question is how much these variables add to the size of the stack frame of your function is, that question has a more complex answer. In an optimized build, your unused variables will be removed and use no memory at all. Try this as a debug and then release build:
@portstrom I was always thinking that when I do x = y, its like cloning values, but x = &y just point to same location in memory
What would be The most elegant way to conver JsonValue in serde_json::Value?
David Harvey-Macaulay
Jun 10 2018 14:13 UTC
   Uploading gltf v0.11.0 (file:///home/alteous/gltf)
error: failed to get a 200 OK response, got 503
    HTTP/1.1 100 Continue

    HTTP/1.1 503 Service Unavailable

    Connection: keep-alive

    Server: Cowboy

    Date: Sun, 10 Jun 2018 14:12:58 GMT

    Content-Length: 506

    Content-Type: text/html; charset=utf-8

    Cache-Control: no-cache, no-store
This just happened twice in a row and gltf-json and gltf-derive published just fine.
Any ideas why?
Fredrik Portström
Jun 10 2018 14:49 UTC
@trsh Could you explain your question in more detail?
David Harvey-Macaulay
Jun 10 2018 15:34 UTC
I think I figured why: the package is too large for to accept. After adding include = ["src", "examples", "tests", "Cargo.toml"]to the [package] section the package uploaded just fine.
Oh gosh now is broken...
David Harvey-Macaulay
Jun 10 2018 16:38 UTC
Ah, cargo package --list is helpful in these situations.
Mathieu Prevel
Jun 10 2018 17:24 UTC

Hi guys,
I'm new to rust and try to parse a file line by line but get lifetimes issues :s

// the struct I build
#[derive(Debug, Clone)]
pub struct TestCfg<'a> {
    audio_file: &'a str,
    volume: u32

fn parse<'a>(s: &'a str, i: &str) -> (&'a str, u32) {
    (s, i.parse().unwrap())

fn to_config<'a>(s: &'a str) -> Option<TestCfg<'a>> {
    let x = s.split(";");
    let split: Vec<&str> = x.collect();

    let maybe_config: Option<TestCfg<'a>> = match split.as_slice() {
        [a, b] => {
            let (audio_file, volume) = parse(a, b);
            let cfg = TestCfg {
        _ => None


// the issue is when I read the file and try to map each line to a config
// lifetime is not long enough in the lambda
// ...
            let vec_configs: Vec<TestCfg> = buffer.lines()
                .flat_map(|line| { // line is of type Result<String, Error>
                    let l = line.unwrap();
                    let the_config = to_config(&l); // <= issue here 'borrowed value does not live long enough'

What do I miss to get the proper lifetime ?

David Harvey-Macaulay
Jun 10 2018 17:26 UTC
@mprevel What type is buffer in buffer.lines()?
Sylwester Rąpała
Jun 10 2018 17:27 UTC
@mprevel You can share your example using
Mathieu Prevel
Jun 10 2018 17:27 UTC
        let mut buffer = BufReader::new(file);
David Harvey-Macaulay
Jun 10 2018 17:30 UTC
In this situation, this will not work because buffer.lines() produces String which must be 'owned' by something but audio_file: &str strictly only 'borrows' from an owner.
One solution may be to read the file into a buffer: String first and call buffer.lines() since that would produce &str.
Another might be to make audio_file: String or audio_file: Cow<'a, str>.
Does that make any sense?
Mathieu Prevel
Jun 10 2018 17:32 UTC
Thanks, I'll check that :)
Mathieu Prevel
Jun 10 2018 17:39 UTC
It works :)
            use std::io::Read;

            let mut buff_str = String::new();
            file.read_to_string(&mut buff_str);

            let vec_configs: Vec<TestCfg> = buff_str.lines()
                .flat_map(|line| to_config(&line))
Jakub Kozlowski
Jun 10 2018 22:47 UTC
I am wrapping a c lib (spdk) and therefore need to pass a rather long (and complex) set of linker flags (so not just -l and -L); I think I need to use .cargo/config file for this, but I am facing issues with the custom flags applying to all my dependencies, rather than just my wrapper; so if I use [build] and list all the flags, then they apply also to all my dependencies and cause some issues; I tried [target.x86_64-unknown-linux-gnu.rust_spdk], but it doesn't seem to work either. I was hoping someone could give me some pointers. Thanks!
the flags are -Wl,--whole-archive -lspdk_copy_ioat -lspdk_ioat -Wl,--no-whole-archive -Wl,--whole-archive -lspdk_vbdev_lvol -lspdk_blob -lspdk_blob_bdev -lspdk_lvol -lspdk_bdev_malloc -lspdk_bdev_null -lspdk_bdev_nvme -lspdk_nvme -lspdk_vbdev_passthru -lspdk_vbdev_error -lspdk_vbdev_gpt -lspdk_vbdev_split -lspdk_bdev_aio -lspdk_bdev_virtio -lspdk_virtio -Wl,--no-whole-archive -laio -L/tmp/spdk/build/lib -Wl,--whole-archive -lspdk_event_bdev -lspdk_event_copy -Wl,--no-whole-archive -lspdk_blobfs -lspdk_blob -lspdk_bdev -lspdk_blob_bdev -lspdk_copy -lspdk_event -lspdk_util -lspdk_conf -lspdk_trace -lspdk_log -lspdk_jsonrpc -lspdk_json -lspdk_rpc /tmp/spdk/build/lib/libspdk_env_dpdk.a -Wl,--start-group -Wl,--whole-archive /tmp/spdk/dpdk/build/lib/librte_eal.a /tmp/spdk/dpdk/build/lib/librte_mempool.a /tmp/spdk/dpdk/build/lib/librte_ring.a /tmp/spdk/dpdk/build/lib/librte_mempool_ring.a /tmp/spdk/dpdk/build/lib/librte_pci.a /tmp/spdk/dpdk/build/lib/librte_bus_pci.a -Wl,--end-group -Wl,--no-whole-archive -lnuma -ldl -lrt -luuid