These are chat archives for rust-lang/rust

21st
Aug 2018
TuckerBMorgan
@TuckerBMorgan
Aug 21 2018 05:19
I am having a strange issue with installing rust through rustup on windows. It will go through the install process all fine, but then when I go to leave my home directory cargo will say that there are no default toolchains installed. If I run rustup it will install them locally in that folder.
Sorry, no default toochain configured is what the error message says
I have both RUSTUP_HOME and CARGO_HOME environment variables set
Derk Bell
@derkbell
Aug 21 2018 09:49
After a few weeks of hobbying with rust I convinced management that I should do the next project in rust, a network component for an ARM device. Such a relief to work with a real language after two years of buggering about with nodejs. Love rust <3
Denis Lisov
@tanriol
Aug 21 2018 09:52
Hope they didn't want you to write that in nodejs :-)
apiraino
@apiraino
Aug 21 2018 10:09
@derkbell awesome
Michal 'vorner' Vaner
@vorner
Aug 21 2018 10:37
@derkbell How long did it take to persuade them? The management here is vaguely pro-rust but there are still problem to be solved ‒ like bus factors, people having to learn it and so on. I guess it comes with the company size, though.
Derk Bell
@derkbell
Aug 21 2018 11:09
well, the alternative was C. Someone from management has some C experience and all I had to really do was mentioning memory safety and showing a bit of my hobby code :D
Yeah we are quite small, a few programmers and just past the startup phase so there isn't too much involved
Fantasized
@Fantasized
Aug 21 2018 11:20
why not C++? Hmmm....yeah, few weeks of hobbying is not enough I suppose.
Michal 'vorner' Vaner
@vorner
Aug 21 2018 11:22
@Fantasized There's nothing like a real project to work on to learn a language, and I'd say that learning Rust on the go is much safer than learning C++ on the go. Learning C might be easier than C++ (it's simpler, but there's more to keep track of in the programmers mind). If you're clever about what you do and design it well, you're actually better of f with plain C than C++. But Rust is going to be nicer to people with high-level-language background.
So if the options were just choosing which language everyone learns, than I guess Rust is quite a good choice between the ones you might want to put on some restricted ARM device.
apiraino
@apiraino
Aug 21 2018 11:27

Rust is going to be nicer to people with high-level-language background.

Funny how the more Rust I do, the more I'm growing into believing the contrary :-) but hey, maybe just my subjective experience

Fantasized
@Fantasized
Aug 21 2018 11:29
what is the contrary you've been facing if I may ask ?
apiraino
@apiraino
Aug 21 2018 11:31
Sure no problem. I am a pythonist devops. I'm learning by doing (like many here) and I'm trying to build up a simple web app with some simple CRUD endpoints:
https://github.com/kkom/open-taffeta
I have to rewire a lot of what I give for granted in my previous life. Trivial things like getting an env var are not so straightforwarded now and require a bit of thinking, researching and so on
Derk Bell
@derkbell
Aug 21 2018 11:33
Last years I've done mostly high level stuff, nodejs, (slooow) ruby and occasionally some C. I don't have any C++ experience and I chose to learn rust because it seems to form a nice bridge from high level to low, giving me a lot of familiar stuff like iterators and closures but also allowing me to easily interact with a C library or drop to raw memory and unsafe stuff when needed
apiraino
@apiraino
Aug 21 2018 11:34
I think - in my case - part of the problem - is that I'm forcing the Rust framework to do what I want - thinking in Python
simple things like initializing a variable / object and then change its value in a if-then-else statement are still confusing me a bit :-)
and don't get me started on crate imports ;-)
but looking back I see what I accomplished and - well - I'm learning, so yay
Michal 'vorner' Vaner
@vorner
Aug 21 2018 11:44
@apiraino What I meant was, if you know python, learning Rust might be hard, but learning C or C++ would likely be even harder. But I come mostly from the low-level end myself so I can't say for sure.
apiraino
@apiraino
Aug 21 2018 11:52
yes, I agree with that ^^^ although sometimes I think that the humongous C codebase and stratified knowledge-base will help you get into C sooner that one might expect. I miss that a bit for Rust (but hey that's expected). I can't speak for C++.
Fantasized
@Fantasized
Aug 21 2018 11:53
I've little experience with C++ and I would say your choice to go with Rust is good, not to mention that some of the familiar things you've said(memory safety, iterators, closure,interact with a C library )could actually be done using C++ as well. @derkbell
Denis Lisov
@tanriol
Aug 21 2018 13:10
For me the nice point of Rust is not that it's easy to do something safely, but that it's hard to violate safety accidentally.
Derk Bell
@derkbell
Aug 21 2018 14:21

I do find myself struggling to model some things in rust, but thats mostly a lack of knowledge. For example, right now I'm parsing a stream of binary data using nom. Each packet in the stream has a 4 byte header, two for the kind, two for the length and then some data that is specific for the kind of packet.

So I thought, let's make a struct with two fields, header and payload, where header is another struct Header that holds kind, enum and length, u16. But now I'm stuck in figuring how to get the payload to be a struct that represents the kind as specified in the header.

Derk Bell
@derkbell
Aug 21 2018 14:27
Now I have different structs for the different packet types and use match header.kind to initialise the correct struct and I have all the structs implement the same Packet trait so I can have generic functions for packet handling
But I'm not sure if this is the optimal way. If at a later point I would want to add a packet type, I would have to make changes at three places: add a variant to the header.kind enum, add a match rule to the payload parser and define a new struct
which would make it impossible to add a new packet type through a crate
Dmitriy
@dpogretskiy
Aug 21 2018 14:31
@derkbell that's what you generally do to make it all work, can't add new packet type through a crate, you have only one place which decides what kind of packet it is
Michal 'vorner' Vaner
@vorner
Aug 21 2018 14:34
You probably could have some global registry of header value → factory function. But I don't know how to auto-register these factory functions, so you'd still need to have something that pushes all the factory functions into the registry.
Derk Bell
@derkbell
Aug 21 2018 14:39
Yeah I was thinking to make a PacketParser trait with a register function, let all packet types implement that trait and then let the main parser hold a Hashmap of type u16's and corresponding implementations. That would probably work if I get rid of the enum in the header and just store the plain u16 value of the packet type
@vorner yeah I would still have to register each packet parser type with the main parser manually, but then I don't have to touch the internals anymore
Justin Kilpatrick
@jkilpatr
Aug 21 2018 19:01
is there any way to namespace implementations on generics for upstream crates?
conflicting implementations of trait std::convert::From<uint::U128>
shouldn't this just require type annotation?
Denis Lisov
@tanriol
Aug 21 2018 20:48
No, there has to be only one applicable impl (only one implementation at all in case of stable). Are you getting this error for a type alias defined with type?