« first day (1982 days earlier)      last day (1497 days later) » 

12:32 AM
@mcarton <3
 
12:55 AM
Thoughts on this updated question β€” is it on-topic now?
Howdy @loganfsmyth! What's new in your neck of the woods?
 
1:08 AM
I do think the question is on topic. It is not opinion based as there are good well understood reasons for this choice.
 
1:20 AM
@Shepmaster Not a whole lot right now, my wife and I living in Japan right now and coronavirus is putting a damper on our plans to do some traveling which is too bad, otherwise mostly just working and doing my usual computery stuff
 
I just posted a Rust answer that took me many hours to write. I took an approach where I started with a naive solution, presented counterexamples to that solution, and then demonstrate a hardened solution that addresses them. Using that strategy, my answer ended up very long. Do you all have thoughts on that approach?

The answer: https://stackoverflow.com/a/60732300/7246614
 
1:48 AM
@timotree I have been known to write some long-winded answers myself.
I think showing a process is valuable, and the people that take the time to read and understand it will be better off for it.
However, it's also usual for people to not read it or glaze over while reading it
so it's always useful to put the most pertinent info first, ideally even with a TL;DR
 
@Shepmaster I like that.
Yeah I think I'll put a TL;DR
 
@Shepmaster I think it's a fair question, but I don't think it's a question for StackOverflow. Maybe one of the other realms
 
@NebulaFox fwiw, if you hover over a previous message and click the arrow on the far right, your reply will link back to the message you are replying to
Pseudo-threaded chat
 
@Shepmaster I feel like you're trying to tell me something XD
Related to you "thoughts on this update question - is it on-topic now?"
 
@NebulaFox I might be. (you can see what people reply to by the little arrow on the left)
 
2:04 AM
@timotree I find a long answer is warranted. But a TL;DR is always good for people who just want to get to the point
@Shepmaster I'm learning
Some code before bed or maybe one more game and then code and bed
 
Okay... Now I've added a TL;DR. Now I feel weird about the tone of the rest of the post though. It's written as though the reader doesn't already know the answer.
 
@timotree but ain't you explaining the process?
 
@NebulaFox hmm... yes. I think I could probably rephrase a few things and fix the tone problem that I was feeling
 
 
7 hours later…
9:16 AM
days 3 - OSKOUR
 
9:40 AM
Day 3: plop
 
 
2 hours later…
11:43 AM
Is my answer correct or should I delete it. It looks like the From trait is what is needed to be implemented but I got voted down, so I'm not too sure stackoverflow.com/a/60738777/398640
 
@NebulaFox I'm working on a more extensive answer myself. I'll look into it once I'm doe.
 
@NebulaFox test your answer :p
also first you forget impl from for
but I think you miss a into() call
 
you get into for free when you implement from
 
rule #1 always make an mcve
 
It's annoying cause in the documentation for From it shows an example of coercing a type
 
11:52 AM
no, example use ?
and ? use from
 
@NebulaFox The last line is missing an .into()
 
I'm so sad
I know how to answer this... nope
 
You did it !
 
It's a good first try
@E_net4removesmeta-commentary I didn't know you could use use like that
 
@NebulaFox Gotta know them tricks after using enums extensively. :)
 
12:00 PM
So in Rust I can't just implement a trait and get implicit type conversion?
 
@NebulaFox There are very few implicit conversions in Rust.
(we usually call these coercions)
 
I understand
 
It's better to be explicit
 
Still, we can name them: deref coercion, const coercion, pointer coercion,... are there any more..
 
12:04 PM
I need to look into how strings are coerced again
 
You probably mean deref coercion from a stringly type into a string slice?
They happen because these types implement Deref<Target = str>.
Oh. Unsized coercion. And lifetime coercion.
</nerdmode>
 
are these all traits?
or done in the compiler?
 
Done by the compiler, but some of these do involve traits.
 
Can I ask which ones?
 
Unsized coercion for example (e.g. turning a [T; N] into a [T]) is backed by the unstable CoerceUnsized and Unsize traits.
But these are not part of the public API, so you currently cannot add implementations to it.
Well, there's also never coercion. Such fun.
 
12:12 PM
never coercion?
 
Coercion from the never type ! to another type T.
 
😡
 
It's a source type. Since it never materializes, it can be safely converted to any other type.
 
we call it "don't ask close your eye but don't use unsafe and create !"
 
haha
 
12:19 PM
@Stargateur That sounds pretty close to the slogan for dtolnay's Rust quiz.
 
I just reading the CoerceUnsize and I get the impression that they want to make a more general Coerce github.com/rust-lang/rust/issues/27732#issuecomment-480073837. Does this mean, We can Coerce types?
 
It means the possibility of more coercions has not been entirely closed. But one should rather not expect much.
More important language features are on the way.
 
Like GAT?
 
@E_net4removesmeta-commentary So a coercion from T to S could be possible, implicit type conversions? Or am I not understanding coercion correctly?
 
@Shepmaster Nah, I can't think of ANYONE who is interested in GATs...
 
some things are way over my head
 
@NebulaFox only at the beginning, just like it was for the rest of us
 
@E_net4removesmeta-commentary oh it is what I thought it was, yay
 
12:26 PM
@E_net4removesmeta-commentary I tried to click this link and missed and went to your profile page and thought β€œwell I guess that makes sense”
2
 
@Shepmaster I am GAT
Const generics are cool too Did I say GATs?
 
I hope there is no danger of Rust getting overly complicated and ends up being like C++
Although, I hope there is such as things as Rust 2.0
 
@NebulaFox One would generally hope not. It would split the ecosystem.
 
@E_net4removesmeta-commentary But then there is a danger of not clearing trash out like Error.description
 
12:32 PM
@NebulaFox I expect that Rust will continue to accrue features and will eventually meet or exceed C++. The risk is when the functions start to conflict or contradict each other.
And some ways Rust is more complicated than C++ because of lifetime.
 
@Shepmaster But that came about naturally through ownership
Would Rust 2.0 be such a bad thing. Rust 1.0 can still compile, so it won't be a library problem. Just new features won't be added to 1.0 anymore.
 
@NebulaFox I would argue that you can conceive an ownership model without lifetime tracking, although it would definitely not boast the same characteristics.
@NebulaFox If Rust 2.0 implies that you can't use any crates from Rust 1.x, then yes, it's bad. The ecosystem is not very large as it is.
 
@E_net4removesmeta-commentary Why not test that theory and make a language in Rust. You're all working on parsers :D
 
@NebulaFox there are already a bunch of those ;-)
 
@NebulaFox The key expression here is "You're all working". ;)
 
12:38 PM
@NebulaFox I would disagree with this. C++ has some notions of ownership and move-semantics, for example (e.g. std::move)
 
See also Vlang and D, I suppose?
 
@E_net4removesmeta-commentary D uses ownership?
 
V is a weird one, its ownership model is not even well documented.
@NebulaFox To the best of my knowledge, it has some RAII.
The GC can also be disabled, but the effects are similar to dropping std in Rust.
 
@E_net4removesmeta-commentary correct
 
Sometimes it's not that much about how much they own things, but what they do with owned resources.
 
12:41 PM
@E_net4removesmeta-commentary and on what thread
@E_net4removesmeta-commentary I would expect major release numbers as in once in every couple of decades. Or just remove the 1 and Rust 42 like browsers XD
 
@NebulaFox Uhhh...
Browsers are end applications, so those version numbers can bump all they want.
Humans do not read semver.
 
@E_net4removesmeta-commentary By that definition, we're not Humans
 
I think by the time people start thinking about a Rust 2.0, they'd rather have a completely different language under a different name.
 
@E_net4removesmeta-commentary There is always that option as well, but it would be nice to keep all those libraries
 
@NebulaFox Fine. We don't interpret semver innately.
 
12:47 PM
@E_net4removesmeta-commentary Why didn't you just say NonProgrammers
 
@NebulaFox Because I'm obviously an unsafe Ferris.
 
XD
 
@Shepmaster <3
 
@NebulaFox I concur with this. When I do Rust training, I usually say "Display is for humans, Debug is for programmers"
 
1:13 PM
Why are there so many questions recently from people who don't understand when macro expansion happens.
 
@Shepmaster I would say it might because macros arn't a construct seen often
 
@NebulaFox in what context? Rust uses macros all the time (vec!, for one)
 
@Shepmaster In Rust, but not in Java, Swift, JavaScript...
 
@NebulaFox well, JS has compile-time concepts with all of the transpilers. I'd expect Swift to have the same.
"Things done at compile time"
 
The only preprocessing you get in Swift is #if
It was just an observation, that I've rarely had to use or create macros in such languages
So it's not a concept that get's taught
The closest we get is decorators in python
 
 
2 hours later…
3:08 PM
This trait object Q is reminding me of some old question
where someone asked if we could "deduplicate" the vtable of multiple trait objects if we knew they were the same.
e.g.
(box 1i32) as Box<dyn Debug> and (box 2i32) as Box<dyn Debug>
And then get something like (vtable, [data1, data2])
and it's answered already?
suspicious
 
3:41 PM
@E_net4removesmeta-commentary as you give me the idea I did the dtolnay.github.io/rust-quiz with some friend
well, we are not bad in Rust and we still struggle a lot ^^
this quiz is super hard
"You have answered 24 of 31 questions correctly." without cheat
then we stop :p
but very few first time answer
 
Isn't that the one that's deliberately the strange edge cases?
 
Yep, there are so many tricks or traps
@Shepmaster Yes. Some are even obviously traps put on purpose
 
@Shepmaster the rule of this quizz is, "if you think it doesn't compile you wrong"
 
@Stargateur Another helpful hint: if there is an obvious answer, that is also wrong.
There are some quite hard ones. But I really don't care about some of those about macro token coercion rules.
 
Why am I not surprised that most of them have coercions.
 
3:56 PM
@PeterHall well, the one with iterator are lazy was obvious so I doubt a little :p
 
@Stargateur Fair. But maybe not obvious to everyone
 
@PeterHall haha clearly half is "if I see that in some code I burn it"
 
heh
I wonder how well you did on the ones that I wrote
 
@PeterHall Did #30 just a moment ago. For a moment I felt that .clone() on an Rc would clone the value, but then again, this is why it's idiomatic to do Rc::clone.
Got #29 right the first time.
 
4:11 PM
I'm about to break a promise I made myself... the one to not build a rust/wasm/dom framework :(
 
@DenysSΓ©guret I'm sorry for your loss :(
@E_net4removesmeta-commentary #29 and #30 are both rated difficulty 1 (out of 3), so don't show off too much :P
 
@PeterHall They're all focusing on magically rendering macro based pseudo html instead of focusing on explicitly dealing with manipulation/rendering of in memory data that can be made of millions of complex nodes
 
@PeterHall yay i am lvl 1 Rust *writes on CV*
 
@E_net4removesmeta-commentary I honestly think the level 3 questions are of no practical value.
@E_net4removesmeta-commentary "did you know this highly obscure implementation detail, which is only observable for confusing legacy reasons?"
 
That is my sentiment. Real complexity emerges in other things: decomposing large problems idiomatically, trait design, async/await, etc.
 
4:57 PM
If I want to move the values of an array into an Iterator, I can do that with into_iter()?
Instead of doing .iter().cloned()
 
@NebulaFox Yes.
@NebulaFox Yes.
..Wait, no.
Arrays are an exception.
:$
 
@E_net4removesmeta-commentary Arrays but not Vec?
 
@NebulaFox Vec is fine.
 
That explains things
 
It's the arrays part that doesn't behave consistently.
 
5:02 PM
I assume it's because they are fixed and on the stack
 
@DenysSΓ©guret please do ! ^^
let's see what would happen
I think we need some (maybe)
@PeterHall hahahahahaha
 
@NebulaFox it's because every value in an array must always be valid
 
5:18 PM
@Shepmaster must always be valid? so an ownership thing?
 
@NebulaFox I don't know if I'd associate it with ownership per se
 
@NebulaFox uninitialized memory
 
more like "you can't have a value with ^
 
Time to sing the song of unsafe people.
 
@NebulaFox A Vec can have uninitialized memory within its allocation, but not within its 0..len
 
In safe code is that possible to have uninitialized memory?
 
@NebulaFox Arrays are not growable, and all elements are assumed to be initialized
 
@NebulaFox expect bug in Rust no
 
@NebulaFox Yes. But only with extreme care, using things like MaybeUninit
 
@PeterHall you would call unsafe at some point
 
5:21 PM
Ok, that was sneaky of me :)
You can't do anything useful without unsafe
Well... actually we have a serialization library, that takes a buffer of &[MaybeUninit<u8>]. You can use it entirely in safe code
 
So why does that affect `into_iter()`?
If all elements are initialized and then I move the array, why do I get a reference
@PeterHall Generally speaking in safe code you can't have an array with uninitialized memory unless you're being sneaky unsafe
 
Don't do sneaky unsafe. :(
 
@NebulaFox what are you exactly trying to do with moving/iterating an array ? What's the need behind ?
 
@DenysSΓ©guret curiosity mostly. I wonder why into_iter just doesn't move the array and give the elements
The use case is me pissing about with Rust XD
Semantics
 
Better bring @LukasKalbertodt in, he'll teach the carp out of you on the subject. ;)
 
5:28 PM
heh
That should start you down the rabbit hole
And check out
17
Q: How do I collect into an array?

rauschI want to call .map() on an array of enums: enum Foo { Value(i32), Nothing, } fn main() { let bar = [1, 2, 3]; let foos = bar.iter().map(|x| Foo::Value(*x)).collect::<[Foo; 3]>(); } but the compiler complains: error[E0277]: the trait bound `[Foo; 3]: std::iter::FromIterator<Foo>

 
not another rabbit hole
 
it's rabbit holes all the way down.
 
I'm in a bloody burrow right now
Thank you all
 
If you care, it's theoretically possible to move out of an array via iterator
 
You'll inevitably go down a lot of rabbit holes when building rust things
 
5:31 PM
but it's not stable
and it is related to const generics
 
how so?
 
OH NO
IT'S LUKAS
RUN FOR THE HILLS
 
That bell wrang hard in my head
I'm trying to collect into an Array
why am I doing that
false bell
I'm collecting into a Vec
 
Vecs are cool and easy. Use them
 
vec is 99% the way to go
 
5:33 PM
I'm just moving an array into Vec
 
@E_net4removesmeta-commentary I appreciate the pings :P
@Shepmaster YES HELLO THERE
 
Hah, collecting into an array is another similar beast.
 
@NebulaFox fom simplicity, do you need to start with an array
 
put simply ["a", "b", "c"].into_iter().collect::Vec<&str>()
 
The people fixing their code because the lint told them to never stops: github.com/rust-lang/rust/issues/66145
I like breaking code
 
5:36 PM
@NebulaFox be careful here. The words "array" and "vector" have very different meanings in rust
 
@NebulaFox triggered
Better use .iter() for now ;-)
 
@NebulaFox or vec!["a", "b", "c"]
 
@LukasKalbertodt why though is my question?
 
because lukas broke all the code
 
...
 
5:37 PM
@NebulaFox Ok here the explanation in short:
 
@Shepmaster The truth.
 
pull up a comfy chair
 
:D
 
.iter().copied()
 
Without const generics, it's hard or impossible to write an iterator that iterates over arrays by value. So there didn't exist one. Several months ago, const generics was ready enough to implement that iterator, so it was added (as unstable). So far so good. The problems comes from the trait IntoIterator. This is implemented for "collections" and everything that can be iterated over.
 
GATs
3
 
𝔾𝔸𝕋𝕀
3
 
IntoIterator is NOT implemented for arrays right now. That's fine. However, it is implemented for references to arrays. I.e. impl IntoIterator for &[T; N]. Sadly, this means that the expression [1, 2, 3].into_iter() compiles. Thats because of autoref trait resolution blabla yada yada something. It results in an iterator that iterates over references to the elements.
yeah yeah all you GAT people get my stars :P
 
@LukasKalbertodt that would explain why I'm getting references back, when I just want to move the array
I'll just stick with vectors
 
5:41 PM
But the problem is this: if we now want to add impl IntoIterator for [T; N] (arrays by value), the expression [1, 2, 3].into_iter() now suddenly results in an iterator iterating over the elements by value. So this is a breaking change! In the standard library!!!
 
I like breaking change
 
@LukasKalbertodt but isn't that what IntoIterator does? I have an Vec of structs and then into_iter I expect those structs
 
That's bad. Basically everyone agrees. But we also really want that IntoIterator impl. Basically everyone agrees here too. So right now we are trying to get everyone to use [1,2,3].iter() instead of into_iter(). That method doesn't have the problem and will always result in an iterator over references. We already have a lint for it and all. We hope that most occurences of array.into_iter() will be replaced soon so that we can add the impl everyone wants.
@NebulaFox Yes yes. That's what we want. We WANT [1, 2, 3].into_iter() to resolve to an iterator that iterates over the elements by value. The problem is just that the expression already compiles today but results in an iterator over references. The last part is the problem.
 
@LukasKalbertodt got ya
So Rust 2.0 XD
 
Ok gotta go again. Pretty busy atm. I now work in the field of "digital education". For some strange reason, many universities and lecturers have become very interested in this over the past week or so. I wonder why...
2
 
5:46 PM
@LukasKalbertodt haw haw
 
I'm enjoying my digital education
 
@NebulaFox We'll see.
@NebulaFox So what's you field of education?
 
@E_net4removesmeta-commentary I'm the student
 
@NebulaFox A student in what?
:>
 
Rust programming
 
5:48 PM
Ah, you mean this.
But off this chatroom, are you also a student?
 
School of hard knocks.
And just like that, Lukas vanished into the night.
 
@E_net4removesmeta-commentary No I'm a freelance App developer
 
I'm a squirrel
2
 
@NebulaFox Alrighty.
 
@Shepmaster In response to this
 
5:53 PM
@LukasKalbertodt But unlike Tuxedo Mask, you did something
 
@LukasKalbertodt I thought about finding that picture, actually
But I expected it to come from @Stargateur
 
@Shepmaster I love it
@LukasKalbertodt haha I just saw the number of reference xd
 
I'm just looking at the starred stuff and I can't stop laughing
Especially @E_net4removesmeta-commentary being a GAT
Excuse me. I need a moment
I'm okay now
 
6:43 PM
@mcarton you didn't want to go all the way and make const HELIUM: Element = ...? :-)
 
There is duplicate of this question
 
 
2 hours later…
8:32 PM
offtopic / crate recommendations stackoverflow.com/q/60745783/155423
 
8:53 PM
@Shepmaster maybe here would be better. So I understand V just so happens to be a reference but it doesn't have to be. So there is example where V is a just a type.
Which is really powerful when I think about it
So I shouldn't bother trying to force it to be a reference
 

« first day (1982 days earlier)      last day (1497 days later) »