« first day (1795 days earlier)      last day (1914 days later) » 

01:47
Is there a way I can coerce bytes::bytes::Bytes into &[u8]?
 
3 hours later…
04:30
@PeterVaro "idiots"
@DanielBank depend of what is Bytes...
04:43
I'm trying to use hyper to read the bytes of a request body using docs.rs/hyper/0.12.24/hyper/body/…
I want to try and extract image data from that and was trying to do something like docs.rs/image/0.19.0/image/fn.load_from_memory.html
impl AsRef<[u8]> for Bytes
Thanks as_ref() did the trick
worked almost a little toooo well :O
&body_content[..] also worked... trying to wrap my head around the two approaches
 
1 hour later…
06:18
@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' ;)
@PeterVaro XD
 
3 hours later…
08:55
So I just learn there seem to be sub traits in rust... and I never saw that in the docs
At least not with the syntax used in the last question
@DenysSéguret when you say 'sub trait' are you referring to inheritance? if so, they are mentioned even in The Book ;)
OK, for<'a> is an HRTB thing
@PeterVaro I was disturbed by the for<'a> thing
@DenysSéguret the syntax for it is quite, well, confusing if you ask me
I confirm that I'm confused
09:34
@DenysSéguret ah the arcane magic
09:49
Do you confirm you can use neither the @binding nor if let in the guard clause of a pattern matching ?
10:13
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 Kalbertodt 5 mins ago
@LukasKalbertodt why it is not detecting that trait call is made over Vec<i32> ?
@ÖmerErden No idea. Sorry, I have on clue about the question at hand :D My comment was just a general remark.
Something's wrong with trait resolution. Don't see a reason why the compiler couldn't figure out the Vec<i32> as Foo impl
Actually i wrote because of this: "So the two lines are generally not equivalent"
i expect that those lines should be equivalent(unless there is no ambiguous call), if not i need to make a lot of read :)
10:44
@ÖmerErden Maybe this helps: play.rust-lang.org/…
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)
Last relevant message... from january... is basically "I'm going to do it"
11:06
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.
An earlier answer (which says the same thing) has 7 upvotes, if that matters: stackoverflow.com/a/49202790/401137
Ah, it uses cargo rustdoc
Fair point
11:53
@Shepmaster You mentioned that the whole getrandom std:: issue was a recurring problem the other day
is there a way to fix this permanently?
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.
Why would it be awkward?
Post that here
If you can throw it on the playground, it might be easier
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?
12:39
@hochl It is not unsafe, but it can return unexpected results
12:52
@hochl You don't need most of the trait bound: play.rust-lang.org/…
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.
I agree that the math operation traits in Rust can be quite impressive for a newcomer :P
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 ... :-(
@hochl Sorry, I didn't implied that you were a noob, I implied "Rust" newcomer.
13:08
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.
@hochl I agree. It's quite good if you compare it with some other documentations, but it can always be better
There should be another collaborative "Rust by example" book with much more examples
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 you clearly (or not) identify what is missing, you can maybe open an issue to help improving the documentation
@hochl That's typically the kind of project where using Rust is satisfying :p
13:15
Good question, atl east this type stuff could be somewhat extended. I will think about a good example if the time allows it.
I like it how the different token types from the grammar fit into an enum ... :D
I found the example complete, but maybe I'm biased since I've done some Rust for 2 years now
I like this option stuff too where u r forced to consider failures.
@hochl That's my preferred point in Rust. I hate exceptions now
I kind of agree. They are useful esp. in Python where there is zero extra cost. But this option stuff really feels good.
and it does not break the flow of the function at some point.
I'll keep an eye on rust for sure. We have safety-critical applications that kind of want to be ported from pointer-hell to rust.
ofc porting that code will be a hell of its own :D :D :D
@hochl If there is multithreading, I would rewrite a C code from scratch
13:21
fortunately (!!) there isn't. But I've seen Rust is quite suitable and I might try some MT stuff as a second example.
as always some sorting and tree management comes to mind :)
@LukasKalbertodt Sorry i couldn't respond, thanks for the playground link, i'll check as soon as i am available.
That's so easy to write it in Rust that you're tempted to sprinkle MT everywhere :P
Tree management in Rust can be frustrating, tho
Well I'll give it a try. Well, thanks for far, I need to tend to some legacy code now :D waves
@ÖmerErden No worries, no hurries
14:15
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
A vm for compilation ? Can't you do that in a container ? There's no way to rustup to a version ?
14:39
I reckon I could, just requires tons of work when I want to test one component of the entire thing
15:00
@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
only rustup is using it or also rustc ?
@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)
ok, so having rustup and this file should basically solve Sébastien's problem, no ? What am I missing ?
15:17
@LukasKalbertodt just tested it, that's amazing
Sweet!
It still doesn't enforce anything if the user does not have rustup installed. So yeah... not an optimal solution I guess.
this won't be a problem
even the final build pipeline has rustup installed
Ah ok! I used it for a project containing benchmarks. Thought that fixing the rust version is good for reproducability.
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
I hate dependency hell
it's also a dependency of tokio
 
2 hours later…
17:30
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.
Seems wrong to me...
CC @mcarton @PeterHall
17:42
@LukasKalbertodt weird
I agree with the dupe though
@PeterHall Ok great. I already felt bad for "overruling" your vote :D
actually it's not weird because you just dupe-hammered it
It's not ideal that it lists the other close-voters who had other reasons. But I couldn't really say how else it could work
@PeterHall Yeah, me neither. Those damn edge cases!
@LukasKalbertodt the dependency nightmare is sorted
the more I run into this the more I wonder what is going on with getrandom 0.7 though
@SébastienRenauld Nice. No idea what getrandom is tho :P
And why it isn't spelled get-random or something
 
2 hours later…
20:14
I just posted a question, if there is any feedback on making it better please let me know: stackoverflow.com/questions/57929505/…
closest thing i could find was stackoverflow.com/questions/51397872/…
@LukasKalbertodt it's the crate rand rides on, basically
provides different ways to get random values based on what platform you're on, even in no_std envs
up to 0.6 the way std stuff was done was sane
now it looks like it has gone full doolally

« first day (1795 days earlier)      last day (1914 days later) »