« first day (1436 days earlier)      last day (2046 days later) » 

1:05 AM
@PeterHall do you know what this person is attempting to ask?
0
Q: Struggling with interior mutability

Phil LordI have a data structure like this: struct R { hmhs: HashMap<i64, HashSet<i64>>, } impl R { fn hs_for_hmhs(&mut self) -> &mut HashSet<i64> { if let None = self.hmhs.get(&0) { self.hmhs.insert(0, HashSet::new()); } self.hmhs.get_mut(&0).unwrap() } ...

 
 
8 hours later…
9:26 AM
I can't
friggin
decide!!
currently leaning LinkedSlotMap
or IterSlotMap
 
 
1 hour later…
10:35 AM
@Shepmaster Looking at his self-answer, I'm still not sure
 
 
1 hour later…
11:38 AM
@orlp Have you already considered something like SkipSlotMap or HopSlotMap?
 
@Calculator nope
 
BlockDirectedSlotMap
2
You can abbreviate that to an easy-to-remember 4 letters
 
12:09 PM
Has anyone here ever had to do approximate equality checks in doctests?
 
@E_net4 you mean for floats?
 
12:28 PM
@PeterHall yes, in case orlp decides to choose this name, just everyone make sure not to click on any of the prominent search results or to switch to image search when googling "BDSM Rust" ;)
 
@PeterHall Yes floats. The approx crate has macros for this, but I wonder if they are naturally employed in doctests.
 
12:45 PM
@E_net4 I don't thinks so
I mean, I'm not certain but I would be surprised. Can't you just check that?
 
@PeterHall Finding them is not like a single query, though.
Still, I found one occurrence. nalgebra has a visible extern crate approx; in a root doctest.
But they don't use it in any other doctest.
 
@E_net4 And you can hide it if it's not important
 
1:14 PM
@Shepmaster But then won't the user see an assert_ulps_eq!(x, y) and wonder what the heck it is? :(
 
@E_net4 If they see assert_eq! they might wonder how the heck that works with floats...
 
@E_net4 "if it's not important"
@E_net4 And I've never had an intuitive sense of what ulps are anyway, so I'd probably still be confused
assert_close_enough_for_government_work!(x, y)
but if your audience understand ulps, then maybe they will take it on faith
 
1:27 PM
Don't mollycoddle your users. Give it to them straight
2
If I saw that in your docs and didn't know what it is, I'd just type it into google
actually Duckduckgo, which really doesn't give good results actually....
But google takes you straight there
 
The thing is, I stumbled upon a situation where you'd like to give an idea of how a function works by providing an example and an expected value. This expected value has a messy fractional part, so a strict equality can be just wrong (in case of precision errors).
 
Could you make a #hidden macro which just calls the other, but name it assert_nearly_eq!
 
is there a version that works that you could just add a comment for?
 
1:57 PM
// This is a bad way of comparing floats but it works in this case
 
2:26 PM
@Shepmaster I fear that it might just work until they decide to use some compiler fastmath flag or something of the sort.
An assert_similar thingy might work here.
 
Is this function generic over num types?
 
3:27 PM
@PeterHall Not yet.
 
@E_net4 Ah. If it was then you could cheat by picking a num type with PartialEq
 
3:42 PM
@Stargateur that is not why a Mutex uses a box. — Shepmaster 6 mins ago
I don't get it
 
@Stargateur You are stating that Mutex uses a box to prevent needing to copy bits, yes?
 
no to prevent internel mutex to move
Ah, surely. So, just to confirm: any structure that has boxes inside, once moved, only copies the header (the constructor and fields of the enum); the boxed data itself isn't moved at all since it is just a pointer, and the enum owns the area it points to. Correct? — MaiaVictor 24 mins ago
or maybe I don't understand what he said
 
yeah, I deleted my comment because I don't want to try and think through either comment.
 
I think it depends on how you think of "move"
 
@trentcl as well as "copy", which is why I asked OP for clarification.
 
3:50 PM
if let x = y is a move, even though it doesn't do anything but re-label some bits behind the scenes, then saying "the boxed data isn't moved" is incorrect because moving a box is also a move
 
the box is moved but not the data in it
 
@trentcl 'saying "the boxed data isn't moved" is also a move'? - ah, you fix
 
@PeterHall Ugh.
 
@Shepmaster ah, I'm too slow :P
@Stargateur is it only a move if the data changes address?
because that's not consistent with the use of "move" elsewhere
 
@trentcl what do you mean by that?
 
3:53 PM
For me the data belong to the box, the box is moved but the data still belong to the same box
the data itself didn't move it's still belong to the same box
 
@Shepmaster let x = y again as an example
Is something moved from y to x?
 
but it is just how I see these things
 
It must be because you can't use y again (unless the type is Copy)
I started saying this with the wrong thing though.
 
There's logical / semantic moves as well as concrete / implementation moves.
 
@Shepmaster ^ yes that's pretty much what I'm saying
 
3:55 PM
let x = y is a logical move but highly unlikely to be an actual move
 
The data in a box is logically moved when you move the box
 
yep
Which is why this was a good related Q
13
Q: Can Rust optimise away the bit-wise copy during move of an object someday?

WiSaGaNConsider the snippet struct Foo { dummy: [u8; 65536], } fn bar(foo: Foo) { println!("{:p}", &foo) } fn main() { let o = Foo { dummy: [42u8; 65536] }; println!("{:p}", &o); bar(o); } A typical result of the program is 0x7fffc1239890 0x7fffc1229890 where the addresses ar...

 
@Shepmaster But array is different from box
array is the data itself
 
Meh, same difference.
 
@Stargateur This is why I wanted OP to clarify what they meant. There is still copying happening right now.
But there doesn't have to be
Through a combination of optimization and emplacement
 
4:09 PM
I think OP understood
 
@Stargateur I don't follow you; of course OP understood what OP was asking, it's the rest of us that might not.
 
No I think Op understood that there are still copy
 
They did, yes, but that information was in a comment that they have now deleted. Their original question was ambiguous and thus why I would have said the answer was not as correct as it could be
> Can I move a value to inside a struct without copying?
The answer to that, currently, is no
(slightly more expanded: you cannot guarantee that there will be no moves, the optimizer might remove all of them anyway)
 
4:30 PM
I have a developer writing an iphone app for me in Swift. Every time I look at a swift source file, I discover new syntax or keyword.
It's mad. I thought it was a new language
It's almost like their language design philosophy is exactly the opposite of Rust's
 
the hardest thing in swift is to not make the compiler crash
 
I never felt so lost when looking at source code before
 
@PeterHall We could find some gnarly Rust code for you ;-)
 
@Shepmaster Show us some gnarly Rust code.
 
some shell code ^^
 
4:40 PM
(that does not involve async/await)
 
pub fn map<P, E, S, F, C, T, U>(
    parser: F,
    convert: C,
) -> impl FnOnce(&mut ParseMaster<P, E, S>, P) -> Progress<P, U, E>
where
    F: FnOnce(&mut ParseMaster<P, E, S>, P) -> Progress<P, T, E>,
    C: FnOnce(T) -> U,
    P: Point,
    E: Recoverable,
 
I thought my answer here was pretty gnarly
 
@Shepmaster Pesfctu!
 
@E_net4 So easy to remember
Haskell Lenses have type variables s t a b, which I particularly enjoy typing
@Shepmaster It's not even gnarly. It's quite self-documenting
 
@PeterHall My favorite is that the more generic you have, the simpler the code seems to be
That one is
{
    move |pm, pt| parser(pm, pt).map(convert)
}
 
4:44 PM
Right. It's not like you'd ever write out all those concrete types in a turbofish
 
(I mean that's the implementation of fn map)
 
where is that from?
@Shepmaster That's the beauty of pushing everything out to types
 
@Shepmaster Is it named after: target.scene7.com/is/image/Target/… ?
 
5:24 PM
@PeterHall scientific name for "parsley"
 
6:13 PM
To be blunt, this is a terrible suggestion. If the replace_all call never needs to be run (and thus never needs to return Cow::Owned), then it shouldn't be there. Presumably OP actually does need to remove comments for some reason, thus this will always panic. It's also not "dangerous" at all. — Shepmaster 2 hours ago
^ This made me curious about whether replace_all can return a substring when it replaces all the way to the end of line.
(It doesn't.)
I guess it would probably be a pessimization in most cases
 
@Shepmaster clear
 
6:43 PM
@Shepmaster Or Estonian for "family" ?
 
7:41 PM
@PeterHall yay my reformatting was useful!
 
@Shepmaster ?
 
@PeterHall oh, I assumed that my editing of OP's error text let you see that it was slice matching, thus leading to your latest edit
perhaps I was over-assuming
 
@Shepmaster ah
No, I'd already tried to compile the same versions
So I had nice errors in my terminal :)
But your reformatting did make the question look nicer :)
 
7:58 PM
@Shepmaster Do you mind if I remove the quoting though? I don't know why it would be there..
 
@PeterHall I don't mind. I put it there cause OP had quotes.
 
@Shepmaster Yeah, I'd normally leave in stylistic things that OP does, which I don't care about, but he didn't format properly at all, so my view is that he either didn't care or didn't know how to do it.
 

« first day (1436 days earlier)      last day (2046 days later) »