These are chat archives for rust-lang/rust

23rd
Mar 2018
Francisco Sosa
@Francososa
Mar 23 2018 01:20

I'm trying to use rustfmt. I installed following the instructions in rustfmt README:
rustup component add rustfmt-preview
cargo fmt
But I got the following error:

error: no such subcommand: `fmt`

    Did you mean `doc`?

If I check inside ~/.cargo/bin/ there aren't any rustfmt binaries

How can I succesfully install rustfmt?
Thibault Delor
@thibaultdelor
Mar 23 2018 03:00
@Francososa whats your toolchain?
rustup toolchain list
you need to be on the the latest stable
if on stable, try running rustup update before
Francisco Sosa
@Francososa
Mar 23 2018 03:26
I ran rustup update before rustup component add rustfmt-preview
$ rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
Francisco Sosa
@Francososa
Mar 23 2018 03:36
$ rustup update
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: checking for self-updates

   stable-x86_64-unknown-linux-gnu unchanged - rustc 1.24.1 (d3ae9a9e0 2018-02-27)
  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.26.0-nightly (75af15ee6 2018-03-20)
Francisco Sosa
@Francososa
Mar 23 2018 03:51
@thibaultdelor
Francisco Sosa
@Francososa
Mar 23 2018 04:58
What's inside ~/.cargo/registry/src/github.com.../ ?
I found the rustfmt-0.10.0 directory in there
Also found cargo-fmt.rs and rustfmt.rs inside ~/.cargo/registry/src/github.com-1ecc6299db9ec823/rustfmt-0.10.0/src/bin which should be the name of the binaries inside ~/.cargo/bin/ ?
Michal 'vorner' Vaner
@vorner
Mar 23 2018 10:58
Hello. I'm trying to do something someone must have done already. I'm using log, currently with env_logger. But I'd like to log to file (that's not really a problem), but also re-open the log file on SIGHUP, so it plays nice with classical logrotate. Is there a ready-made solution or half-made one? I'm not finding one when browsing through crates.io.
Olson3R
@Olson3R
Mar 23 2018 12:46
@vorner I use slog wich supports what it calls drains. That allows you to specify where/how you want your logs. You can output them to the terminal and to file.
Michal 'vorner' Vaner
@vorner
Mar 23 2018 12:50
@Olson3R Sorry, but you probably misunderstood what I was asking about. For one, I explicitly want to use log, not slog (the first one is much easier to use). Second, I have no trouble sending the output to a log file (for example with this https://docs.rs/simple-logging/2.0.1/simple_logging/fn.log_to_file.html), what I ask about is log reopening when I get the signal. There doesn't seem to be a way to close & open the log again.
Olson3R
@Olson3R
Mar 23 2018 12:51
Ok, sorry for the misunderstanding.
Daniel Bischof
@dbischof90
Mar 23 2018 13:34
Hey guys, looking at HashMaps and HashSets a little more in detail out of interest. While I get the use-case in cryptographic applications, why is it so important to have a cryptographically save hash function in those?
So if I just want to do some set operations as I would know them from Python for example, why would I care about cryptographic properties of the hash function?
Nikolay Kim
@fafhrd91
Mar 23 2018 13:38
You can use different hasher
Ed Page
@epage
Mar 23 2018 13:39
Isn't the reason for the hasher to prevent attackers from DoSing your application by intentionally putting stuff in that would hash similarly?
Python similarly put in fixes for these attacks iirc
Daniel Bischof
@dbischof90
Mar 23 2018 13:40
Yes, sure! But why is that mentioned so often? What properties to I gain from using a cryptographically secure hash function?
Ingvar Stepanyan
@RReverser
Mar 23 2018 13:40
What @fafhrd91 - for example, fnv crate is a popular choice if you are really sure you won't have user-generated dynamic keys or just don't care about DDOS attacks
Daniel Bischof
@dbischof90
Mar 23 2018 13:40
Oh
Ah, I see
So if I had a set {a,b,c} and some logic that had to do with a value being in that set someone could just test different values until the hash functions are the same?
And an 'ideal' hashfunction has the property hash(k1) == hash(k2) -> k1 == k2 for all k1, k2 while 'bad' but possibly faster hash functions only have the other way around
So the 'worst' hash function would just map everything to one integer, say 1
Which would be stupid and useless, but, well, fast.
Daniel Bischof
@dbischof90
Mar 23 2018 13:49
So if I have a set of values in a client-facing application that are not immediately exposed to the client and the variety is not too big I can choose something like fnvand if it's something like authentification I should take care that I have a hash function that is 'as injective as possible'. Okay, that makes sense.
Ingvar Stepanyan
@RReverser
Mar 23 2018 13:51

Which would be stupid and useless, but, well, fast.

fast to hash, but slow to find item back, yeah

Daniel Bischof
@dbischof90
Mar 23 2018 13:52
Huh. That's quite a difficult problem, isn't it?
Ingvar Stepanyan
@RReverser
Mar 23 2018 13:53
so it leads to various issues: someone can try and push keys that will make your service increasingly slower to legitimate requests; someone can measure timings of key retrievals to guess what you have stored in a hashmap; list goes on
cryptographic hash function aka default gives you protection against these things at the cost of slower hashing for everyone, but it's a good default for user-facing hashmaps/sets
fnv and such gives you better speed (often, much better), but better not to use if it's a web server or something
Daniel Bischof
@dbischof90
Mar 23 2018 13:54
With this in mind, I fully agree.
Ingvar Stepanyan
@RReverser
Mar 23 2018 13:54
for example, I'm mostly working on cli tools, so hashmap is just for caching or storing regular tree structures, so fnv is usually my first choice
Daniel Bischof
@dbischof90
Mar 23 2018 13:55
I'm still learning the language, my day-to-day work is mostly hacking stuff together in Python, I never really had to care too much about details like that.
But gives me a fully new perspective
Olson3R
@Olson3R
Mar 23 2018 13:56
I have enjoyed the new perspectives from Rust as well.
Olson3R
@Olson3R
Mar 23 2018 14:02
Does anyone use Rust for an API in production that feels like sharing their thoughts on it?