These are chat archives for rust-lang/rust

14th
Sep 2017
Michal 'vorner' Vaner
@vorner
Sep 14 2017 15:06
I'm seeing something strange. For some time (a week, maybe?) when I run cargo test --all --all-features, no doc-tests are run. It just outputs the Doc-test name-of-crate for each crate in my workspace, but doesn't output any stats (how many tests were run) and doesn't fail if I create a broken test on purpose. If I run it on stable, the test fails.
Does such thing happen to anybody else? Or am I doing something obviously wrong?
But I guess if doc tests suddenly broke completely, someone would have reported an issue by now.
Aleksey Kladov
@matklad
Sep 14 2017 15:09
@vorner you could try to create a self-contained repository wich reproduces the problem: this'll end in either finding a local problem with your setup, or a a high quality bug report :)
Michal 'vorner' Vaner
@vorner
Sep 14 2017 15:10
Yes, I'll try, but I wanted to ask first if it is a known problem and I just missed the issue before investing the time.
Robyn Speer
@rspeer
Sep 14 2017 15:57
I'm missing something basic. I'm trying to import the byteorder crate in a module that isn't lib.rs. The top of that module has:
extern crate byteorder;
use byteorder::{LittleEndian, ReadBytesExt};
Restioson
@Restioson
Sep 14 2017 15:58
extern crate's always go in the crate root
be it lib.rs or main.rs :smile:
Robyn Speer
@rspeer
Sep 14 2017 15:58
okay, got it
Restioson
@Restioson
Sep 14 2017 15:58
The use's go in the files, though
Robyn Speer
@rspeer
Sep 14 2017 15:58
Seems like a good case for a clearer error message
"extern crate goes in the crate root" would be a clearer hint than "did you mean self::byteorder?"
Restioson
@Restioson
Sep 14 2017 15:59
heh
it really would
Michal 'vorner' Vaner
@vorner
Sep 14 2017 16:12
Actually, an extern crate can go can go into other places as well. But it's usually a bad idea.
Robyn Speer
@rspeer
Sep 14 2017 16:14
How do I read a specific number of bytes from a file, and then still be able to read more from the file afterward? I tried using take() but it consumes the file object. This is noted in the comments to https://stackoverflow.com/questions/30412521/how-to-read-specific-number-of-bytes-from-a-stream . However, I don't understand the follow-up from bluss and Shepmaster.
For example, I want to do this, where f is a File:
    let mut header_handle = f.take(header_len as u64);
    let mut header_string = String::new();
    header_handle.read_to_string(&mut header_string)?;
What do I change so I can still read from f afterward?
Robyn Speer
@rspeer
Sep 14 2017 16:16
Does it work when the number of bytes is determined at run time?
That's why I ended up on this StackOverflow page
I'm using read_exact for things that are known at compile time
Aleksey Kladov
@matklad
Sep 14 2017 16:17
Sure, you'll need to heap allocate the buffer at runtime:
let mut buf = vec![0; n];
f.read_exact(&mut buf);
Robyn Speer
@rspeer
Sep 14 2017 16:17
Ah, didn't know it could take a Vec
Robyn Speer
@rspeer
Sep 14 2017 17:29
I posted this as an answer to that SO page, so that someone else has a chance of finding the right answer instead of an ugly half-answer from 2015: https://stackoverflow.com/questions/30412521/how-to-read-specific-number-of-bytes-from-a-stream/46225116#46225116