These are chat archives for rust-lang/rust

6th
Apr 2018
C Roger
@talus46
Apr 06 2018 04:43
greetings everyone, I’m trying to learn Rust and I’m having an error could anyone point me the right direction to solve it? I’m trying to install a crate and I’m getting the following error message :smile:
cargo install image
Updating registry https://github.com/rust-lang/crates.io-index
Installing image v0.18.0
error: specified package has no binaries
Sergey Noskov
@Albibek
Apr 06 2018 04:46
@talus46 I suppose you need a library, not a command. If so, you don't need to install it, specify it inCargo.toml and it will be downloaded on check/build stage
C Roger
@talus46
Apr 06 2018 05:03
@Albibek thanks,
:)
Olson3R
@Olson3R
Apr 06 2018 05:04
C Roger
@talus46
Apr 06 2018 05:13
one more question has anyone used cargo to build a wasm ?
or better saying does anyone have an example on how to customize cargo build ?
C Roger
@talus46
Apr 06 2018 05:21
ok found it :) thanks very much for the references
Dylan DPC
@Dylan-DPC
Apr 06 2018 07:08
does anyone know of a cool way to generate random "human names" in rust?
Christian Witts
@ChristianWitts
Apr 06 2018 07:21
it’s very much like Faker, from Python
apiraino
@apiraino
Apr 06 2018 07:31
:+1: handy tool
Ralf Jung
@RalfJung
Apr 06 2018 09:13
Some time ago I stumbled upon a website that collects Rust blogs (or blog posts, not sure about that any more). it was nicely categorized and had RSS feeds and whatnot. unfortunately I cannot find it again right now. does anyone have an idea what I could be talking about?
Christian Witts
@ChristianWitts
Apr 06 2018 09:14
https://rust.libhunt.com/ && https://this-week-in-rust.org/ perhaps. Libhunt has a weekly newsletter as well
Ralf Jung
@RalfJung
Apr 06 2018 09:15
TWIR I know, that's not the one
lubhunt... maybe? the layout is certainly different, but it could have changed
apiraino
@apiraino
Apr 06 2018 09:20
I'm getting Rust related articles mostly from https://readrust.net/about.html#feeds (I'm hooked to the "main feed")
Ralf Jung
@RalfJung
Apr 06 2018 09:22
@apiraino that's the one, thanks a ton :)
apiraino
@apiraino
Apr 06 2018 09:22
:+1:
Ralf Jung
@RalfJung
Apr 06 2018 09:24
searching for that link in reddit brings me to the link submission form... is that reddit's way of telling me that the link couldn't be found? that's confusing.
apiraino
@apiraino
Apr 06 2018 09:27
strange, I get one result: https://www.reddit.com/search?q=readrust.net :confused:
Ralf Jung
@RalfJung
Apr 06 2018 09:28
maybe I am searching wrong? I entered the URL in the text box at the right and hit enter
apiraino
@apiraino
Apr 06 2018 09:29
^^^ exactly what I did
Ralf Jung
@RalfJung
Apr 06 2018 09:29
nah, same if I go to https://www.reddit.com/r/rust/search and enter a link
and they block curl so I cant really debug this :(
Dylan DPC
@Dylan-DPC
Apr 06 2018 10:27
@ChristianWitts ya fake is what i was searching for. thanks :)
Dylan DPC
@Dylan-DPC
Apr 06 2018 10:34
i have used faker in other languages but forgot to search for it here and was looking for "name generators" etc but couldn't see fakewasn't listed
Restioson
@Restioson
Apr 06 2018 10:56
So, I'm writing a memory pool with RawVec
I'm wondering how I should handle ZSTs

The doc on ptr says

Gets a raw pointer to the start of the allocation. Note that this is Unique::empty() if cap = 0 or T is zero-sized. In the former case, you must be careful.

Would the ptr just be 1 since ZSTs align to 1?
why do they align to one and not zero, btw?
Is there a trait for IsNotZst or similar?
apiraino
@apiraino
Apr 06 2018 11:39
Hi, a question about using the same TcpStream to read+write.
My readings from this socket are of variable length and may or may not be on a single line, therefore I can't always trust the \nas a terminator using io::BufReader::read_line
what are my options to fully read the socket without truncating the read?
should I loop the read_line until the read size returned is 0?
apiraino
@apiraino
Apr 06 2018 12:03
^^^ I can't do that because I would have a "hanging" read before being able to check the size
But I have a way out: every response on the socket ends with OK, therefore I can check that and stop iterating the read_line
Roman Proskuryakov
@kpp
Apr 06 2018 12:12
No
if it is possible
It is the best choice for variable-length data
apiraino
@apiraino
Apr 06 2018 12:15
uhm ... ok so get the "declared length" and then read that exact amount with something like read_exact?
Roman Proskuryakov
@kpp
Apr 06 2018 12:15
if you protocol depends on "\n" at the end, you should use another codec
See tokio-rs/tokio#301 for example of BytesCodec
If you proto depends on "\n" you should use https://docs.rs/tokio-io/0.1.6/tokio_io/codec/struct.LinesCodec.html
Just replace BytesCodec with LinesCodec and that should be fine for you
apiraino
@apiraino
Apr 06 2018 12:17
that is for Tokio: do I have these facilities also on standard TcpStream?
Roman Proskuryakov
@kpp
Apr 06 2018 12:18
Oh sorry I mixed up channels
apiraino
@apiraino
Apr 06 2018 12:18
no problem, your suggestions will come in handy later (because in the end I'm writing a TCP forwarder with Tokio)
Roman Proskuryakov
@kpp
Apr 06 2018 12:21
Well if you want to use std TcpStream then you may read 2 bytes (assuming that 2 bytes are enough for lenght), allocate buffer and call read_exact(buffer). But these calls are blocking
apiraino
@apiraino
Apr 06 2018 12:21
thanks
Roman Proskuryakov
@kpp
Apr 06 2018 12:23
Did it help?
apiraino
@apiraino
Apr 06 2018 12:24
yes, I'm thinking. Probably I'll have to end up with something like you suggested. Now I'm just reading "stuff" from a sync socket and learning when to stop
then I'll move this code into the Tokio implementation and then improve the packet reading
thanks for now, I didn't know about those APIs!
apiraino
@apiraino
Apr 06 2018 13:17
here's a (rough) sync implementation, for the records:
https://gist.github.com/apiraino/76b2fd71c22336db51bbe1959a88809d
Restioson
@Restioson
Apr 06 2018 13:20
I'm a bit confused
Michal 'vorner' Vaner
@vorner
Apr 06 2018 13:21
It describes things about the data type, like how many bytes it actually takes, how it needs to be aligned, etc.
Restioson
@Restioson
Apr 06 2018 13:22
ohh
the data type itself
Seems I can use realloc_array anyway though
Michal 'vorner' Vaner
@vorner
Apr 06 2018 13:23
Well, the layout of the allocation can be composed of the types it'll contain. There's an RFC somewhere describing all these details.
vorner @vorner just looked and there are several intertwined RFCs about this… seems like a complex topic
Restioson
@Restioson
Apr 06 2018 13:26
I'm unsure about this atomic logic I'm writing
(will post snippet soon)
Restioson
@Restioson
Apr 06 2018 13:33
ok
trying to atomically realloc a buffer
(rip)
// Reallocate the buffer
unsafe {
    let old_ptr = NonNull::new_unchecked(
        self.buffer_ptr.load(Ordering::Release)
    );
    let old_capacity = self.capacity.load(Ordering::Release);
    let new_capacity = old_capacity + amount;

    let new_ptr = self.allocator.realloc_array(
        old_ptr, 
        old_capacity, 
        new_capacity
    );

    self.buffer_ptr.store(new_ptr, Ordering::Acquire);
}
i'm just not sure what would happen if someone else tried to tried to realloc as well in the middle of this realloc
Michal 'vorner' Vaner
@vorner
Apr 06 2018 13:40
This seems to be wrong on several levels. For example, load with Release is nonsense (and should panic at runtime). The same for store with Acquire
and what about the time between you reallocate and publish the new pointer to others? That's quite racy.
Restioson
@Restioson
Apr 06 2018 13:42
oh
maybe I mixed up release and acquire in my head
That's exactly what I thought
maybe I need locks here
Michal 'vorner' Vaner
@vorner
Apr 06 2018 13:49
Yes, I think reallocation can't be really done atomically. Maybe some kind of modified reallocation, where you keep the old memory around for long enough after allocating the new one (but thats probably super-hard, you can read some blog posts from the crossbeam project).
Restioson
@Restioson
Apr 06 2018 14:18
yeah
Judson Lester
@nyarly
Apr 06 2018 16:09
The plan is for rustfmt to build on stable when its syntax parsing works there, though right?
scottmcm
@scottmcm
Apr 06 2018 21:00
I don't know if it'd ever build on stable, the same way the compiler doesn't build with the stable compiler. But it'd certainly be available on stable as a component at some point.