These are chat archives for rust-lang/rust

27th
Mar 2018
Dan Robertson
@dlrobertson
Mar 27 2018 03:14
My current thoughts for implementing va_list in core is by adding another variant to TypeVariants for VaList and then properly handling the variant in trans emitting the proper va_list structure for the targets va_list_kind.
While this is the only path I can see forward, it feels off
Am I missing something? Is there another way to implement a target specific type in core?
I'm still a rustc noobie, so I'll keep digging through the code, but any pointers would be appriciated
Roman Proskuryakov
@kpp
Mar 27 2018 11:20
Hello. How do I use rustfmt to pretty format macros. Here how rustfmt changed my code:
 impl FromBytes for HandshakePayload {
-    named!(from_bytes<HandshakePayload>, do_parse!(
-        pk: call!(PublicKey::from_bytes) >>
-        nonce: call!(Nonce::from_bytes) >>
-        (HandshakePayload { session_pk: pk, session_nonce: nonce })
-    ));
+    named!(
+        from_bytes<HandshakePayload>,
+        do_parse!(
+            pk: call!(PublicKey::from_bytes) >> nonce: call!(Nonce::from_bytes)
+                >> (HandshakePayload {
+                    session_pk: pk,
+                    session_nonce: nonce
+                })
+        )
+    );
 }
Is there a way to tell that >> is a custom delimiter?
Zakarum
@omni-viral
Mar 27 2018 11:42
@kpp you can disable rustfmt for some items
Roman Proskuryakov
@kpp
Mar 27 2018 11:42
via config or using #?
Zakarum
@omni-viral
Mar 27 2018 11:43
I believe you can do it with #
Roman Proskuryakov
@kpp
Mar 27 2018 11:44
Well, there are too many lines I have to add it
Ingvar Stepanyan
@RReverser
Mar 27 2018 15:02
You can also try and submit PR or at least issue to rustfmt
They already added few special cases for popular macros, could as well do it here (nom is quite widespread so I think it's reasonable)
Rett Berg
@vitiral
Mar 27 2018 16:16
@nyarly Hey sorry I didn't see your mention until now! I am not working on the rust builder but I am experimenting with it. You might find NixOS/nixpkgs#35587 useful.
@nyarly personally I've been using the rustup nixpkg and it's been working well with a few tweaks to the environment variables
I can develop locally like I did on standard linux
Judson Lester
@nyarly
Mar 27 2018 16:23
@vitiral carnix is the command I was trying to remember. One of the things I like about Nix is being to manage separate working environments, so I'd like to be able to do as much management of my Rust environment with Nix aot rustup as possible.
Rett Berg
@vitiral
Mar 27 2018 16:27
ya, I put some examples for that using nix-shell in the PR
Judson Lester
@nyarly
Mar 27 2018 16:28
Rad
Rett Berg
@vitiral
Mar 27 2018 16:29
personally I prefer to be able to do "normal" development without nix-shell because it doesn't interact very well with my aliases, just, tmux, etc -- but YMMV. I'm probably too much of a NixOS noob since I can't even seem to run nix-build as non-root :laughing:
Judson Lester
@nyarly
Mar 27 2018 16:39
Are you running full NixOS?
The really rad thing with nix-shell is how well it works with direnv
Krisztián Szűcs
@kszucs
Mar 27 2018 16:44
Hey! Could You suggest a way to create a collection Vec with different types implementing the following trait?
trait DataType {
    type Item;

    fn name(&self) -> &str;
    fn bits(&self) -> usize;
}

// something like
struct Schema(Vec<Box<DataType>>)
Michal 'vorner' Vaner
@vorner
Mar 27 2018 16:57
You'd have to restrict the items to a specific type. Eg. Vec<Box<DataType<Item = String>>>. It's not object safe without such restriction.
Krisztián Szűcs
@kszucs
Mar 27 2018 16:57
Isn’t there a workaround for that?
Or move out the associated types and replace them with multiple traits / impls?
Rett Berg
@vitiral
Mar 27 2018 17:11
@nyarly ya, I'm doing full NixOS
never used direnv, looks awesome (https://github.com/direnv/direnv)
David Pedersen
@davidpdrsn
Mar 27 2018 17:38

I really need some help here. Been hard stuck at this for too long...

I have a gzipped file that I decompress using flate2::read::GzDecoder. Yet for some reason I don't get the entire file but only the first five lines.

Compressing the file on the command line with gunzip works just fine.

My code:

use flate2::read::*;
use std::fs::File;
use std::io::prelude::*;

fn main() {
    let mut file = File::open("tmp/compressed/142690/142690_2018-02-01_0#580.json.gz").unwrap();

    let mut gz = GzDecoder::new(file);
    let mut buf = String::new();
    gz.read_to_string(&mut buf).unwrap();
    let line_count = buf.lines().collect::<Vec<_>>().len();
    println!("{}", line_count); // 5
}

On the command line:

$ gunzip -c "tmp/compressed/142690/142690_2018-02-01_0#580.json.gz" | wc -l
1789

I also only get the first five lines if I decompress using Ruby, so the issues seems to be in the file. Any idea whats going on?

Ingvar Stepanyan
@RReverser
Mar 27 2018 17:43
Are the actual lines well-formed?
David Pedersen
@davidpdrsn
Mar 27 2018 17:44
you mean the lines I get back from gunzip?
because if so, then yes they are
they are valid json
Sergey Noskov
@Albibek
Mar 27 2018 17:58
@davidpdrsn You could you check the buf contents first to determine if file was fully read or not.
David Pedersen
@davidpdrsn
Mar 27 2018 18:02
@Albibek how would I do that? Repeating gz.read_to_string(&mut buf).unwrap(); a couple of times doesn't change anything, and Read::read_to_string says its reads until it EOF. I'm wondering if there somehow are multiple EOFs inside the file, but not sure if that is even possible...
using Read::read_to_end also gives the same result
Sergey Noskov
@Albibek
Mar 27 2018 18:05
@davidpdrsn no no, just check the buf length after first iteration or print it to see what's inside. You'll get sure that it's gzip reading error, not line splitting one.
David Pedersen
@davidpdrsn
Mar 27 2018 18:10

Same issue :(

fn main() {
    let mut file = File::open("tmp/compressed/142690/142690_2018-02-01_0#580.json.gz").unwrap();

    let mut gz = GzDecoder::new(file);
    let mut buf = String::new();

    gz.read_to_string(&mut buf).unwrap();

    print!("{}", buf);
}
$ cargo run | wc -l
5

And each line is valid JSON. This works cargo run | while read l; do echo $l | pretty_print_json; done

would it make sense to open an issue for flate2?
even though the issue doesn't seem to unique to the rust implementation? Ruby has the same issue
Sergey Noskov
@Albibek
Mar 27 2018 18:11
In my personal opinion it would, but you'll have to provide the file to the authors, so they could reproduce.
David Pedersen
@davidpdrsn
Mar 27 2018 18:12
:+1:
Michal 'vorner' Vaner
@vorner
Mar 27 2018 18:13
I'm not sure it is related, but technically, gzip file is allowed to consist of multiple gzip „archives“, one after another. It is allowed to take multiple gzip files and concatenate them.
Maybe the docs even mention something about that.
Sergey Noskov
@Albibek
Mar 27 2018 18:13

This could also be a file format issue, since gzip man says

gunzip can currently decompress files created by gzip, zip, compress, compress -H or pack.

Michal 'vorner' Vaner
@vorner
Mar 27 2018 18:16
Also, try to re-compress it. eg. gunzip -c <oldfile.gz | gzip >newfile.gz, to see if it's specific to your code or that actual file.
David Pedersen
@davidpdrsn
Mar 27 2018 18:17
@vorner omg that was it! Just needed to switch to flate2::read::MultiGzDecoder. Thanks!