@Stargateur The question mark wasn't for 'what is the i-word', it was for 'since when idiots should not be used when one is clearly talking about idiots' ;)
While it has nothing to do with the specific problem at hand, it's also worth pointing out that the dot-method-call-syntax does some things like auto-referencing and dereferencing. So the two lines are generally not equivalent, even in cases less crazy than this one. — Lukas Kalbertodt5 mins ago
@LukasKalbertodt why it is not detecting that trait call is made over Vec<i32> ?
It lists all 9 possibilities ({value, ref, ref mut}^2) with each the dot-method-call-syntax and the Trait::method(&variable) syntax.
Basically, the dot syntax correctly takes a reference to the variable or dereferences the variable to make it work whenever it can work somehow.
The other syntax Trait::method(&variable) works like a normal function call in that you have to make sure you pass the right mutability/reference/whatever. The correct exact type, simply put.
Of course (and maybe that's where we misunderstood), you can make all calls happen with the Trait::method syntax. As long as you pass the correct argument. I.e. Foo::by_value(*r) or Foo::by_ref_mut(&mut value)
I know vote manipulation is bad, but in this question the obvious up-to-date correct answer only has one upvote (which I just gave). cargo doc --document-private-items is the way to go now. Answer should be higher up IMO.
Dear all, I'm looking into rust and I have found a solution to a problem I had when writing a generic function which I don't understand. Is it ok to paste it (4 lines) so that someone could explain? Or should I make a SO question of it? It seems a little awkward to post it as a question.
fn digit_value<T>(c: char) -> T where T: Sub+std::convert::From<u8>+std::convert::From<<T as std::ops::Sub>::Output> { (c as u8 - '0' as u8).into() }
I'm writing a compiler that reads text and does something. This function returns the value of a digit as a generic type T'. Now what I do not understand is Sub+std::convert::From<u8>+std::convert::From<<T as std::ops::Sub>::Output>'. I really just collected that from various SO answers, but I'm kind of stuck there.
[it works! I just fail to understand this where stuff).
Ah that would be a better solution ofc. But it still leaves me with the understanding point :/ [I understand my function is kind of unsafe, but I know that the argument is a valid digit at this point because the compiler checks that already.]
I'm especiall puzzled about the `<T as std::ops::Sub>::Output' part.
Does that the result of a subtraction involving T can be converted to T again?
The only thing needed is T: From<u8>. Which just means: T is a type that can be created from a u8value.
@hochl also see this Q&A. The "math operation" traits have an Output type because the output of the operation is not necessarily the input type. Example A: vector * scalar = vector. Example B: (point in time) - (point in time) = duration.
It would be cool if the manual would cover those things better, I'm not exactly a novice, just with Rust. Some example code for these things would go a long way imho.
Well thanks for your answers, I'll dig into it. I like it how Rust makes in very hard to write bullshit code with 5 layers of pointers and noone knows who owns what. We have that here in a lot of C code ... :-(
Yeah I understood that :P I meant it's maybe a problem if someone who usually knows his way through things and manuals actually needs aid after reading the manual for such `basic' things.
@hochl A lot of people has testified that writing Rust code allows to write a better C code because it learns the right mental model (at least it gives the right habits)
in the end it's maybe not that basic if Rust needs so many hints.
I totally agree, you have to think about a lot of stuff when writing C that some ppl just don't. Those ppl would hugely benefit from Rust since all those things just won't work with it.
I'm kind of happy with Rust for now, it's just the documentation could be better.
but I understand the language is still evolving heavily and thingd are changed regularly.
I always compare docs to the Python or Qt docs as the gold standard, so maybe I'm biased.
Yes I searched several times for a solution to the problem and there just lacked examples. I then used the stuff the compiler suggested so that worked, but it felt as if I was missing some pieces.
to understand the whole thing.
But so far I like Rust. I was just writing a small compiler for mathematical expressions to test out the language :)
I wish there was a way to target a specific rust version in cargo
all of my current codebase is targeted at a specific nightly of 1.32 (the latest possible that produces code that works for a processor/arch type). working on that code systematically requires a vm due to that
@SébastienRenauld Not exactly what you want, but there is rust-toolchain. Create a file with that name and fill it with nightly-2019-05-10 or whatever. That tells rustup to use that version. You can commit that file to git! That's probably the main reason behind it :P
@DenysSéguret Ehm, rustc via rustup? If you have rustup installed, cargo and rustc are just proxy executables that dispatch to the right version (they have the rustup logic inside). If you don't have rustup installed, then no, rustc (the actual compiler) will not check that file (I think)
error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)
--> C:\Users\sebre\.cargo\registry\src\github.com-1ecc6299db9ec823\getrandom-0.1.12\src\error_impls.rs:13:5
|
8 | extern crate std;
| ----------------- not an extern crate passed with `--extern`
This error drives me up the wall so fucking much
and since it's a core dependency of hyper there is literally nothing I can do about it
Interesting! So three people voted to close this question as "too broad". I think that's correct, but also wanted to close this as a duplicate because the linked Q&A absolutely answers OP's question. I was not sure what would happen if I do that.
Turns out, I immediately close it as dupe AND the ones who voted closing as "too broad" are also listed as closing as a dupe.