« first day (2096 days earlier)      last day (1394 days later) » 

7:30 AM
@Ghostff &init() ?
 
 
3 hours later…
acr
10:50 AM
I'm looking for advice on lifetimes: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=95694defe1a2c8b56146f9be0bcd3067. Basically, this is a minimal example of my 'real' design issue in a library.

In line 14, I would like to express that Self::Item (which has to be a reference type, I just chose &[u8] for simplicity) is valid until the next call to next(). A call to next() will invalidate the buffer, create a new one and return a reference to it. In the real code, this 'reference' is a memory mapped region.
How would I best solve this?
 
11:33 AM
@acr I highly doubt this design will work in the long run (very "unrusty") (I sort of tried to warn you about this the last time :see_no_evil:) but if you must, so far it would look like this
 
acr
12:12 PM
@PeterVaro well, how would you solve this?
I know it looks "unrusty" but I don't see a better way to share memory mapped regions without copy.
 
@acr I would build on Rust's moving semantics wherever possible. For example, in your above snippet: why do you keep a reference to the buffer that you created? You can't modify it because you gave away a shared reference, and if you would've given away a unique reference, then you couldn't modify it internally.
 
acr
@PeterVaro I don't actually create the buffer, this is just for illustration purposes.
As I said, in the real use case, this is a memory mapped regions which I get from somewhere else.
So I can't "move" anything but share the refs instead.
 
Well, in that case as always: it's hard to help without seeing the actual thing. (No, I don't mean that repo you linked last time, I mean, a full, but minimal example of your actual problem.)
(Also, if it works for you, by all means go on and use it as is, don't bother my concerns. It's just, I did several similar things in the past and they worked every step of the way, except when I put everything together, because that's not how I should've solved the problem in the first place, but the design patterns I inherited form C (and alike) gave me the idea that this is how things should be designed in the first place)
 
acr
Okay, let me show you the real code.
And by the way - this works for me right now. I just have a few unsafe areas that I'd like to clean up so I'm specifically looking for Rust best practices here.
I have an iterator implementation handing out the references here: github.com/raymanfx/libv4l-rs/blob/master/src/buffers/….
Please let me know whether you think this is the "Rust" way to go so far.
The unsafe block I was talking about earlier is here: github.com/raymanfx/libv4l-rs/blob/master/src/buffers/….
@PeterVaro What I'd really like to (safely?) express here is that Views returned by dequeue() are valid until the next call to dequeue() - in line 155.
 
12:29 PM
@acr Well, you can only express, that nothing could get a second batch of your buffer -- you could give away a wrapped buffer type, that mutually borrows from the stream, so stream cannot advance until the wrapped buffer type got dropped..
 
acr
If that's the only possibility, it still sounds like a potential improvement over my current design.
 
I will look at the links later on today, maybe tomorrow. I just skimmed the first two links and by the looks of it there's nothing obviously wrong there! (Well as far as I can tell at least ;))
 
acr
Do you now see the relation between this code and the minimal example I posted? I hope it became a bit clearer.
Thanks for taking a look!
 
@acr I cannot think of anything else atm: you want to give away a reference, which should be valid until you call for the next one, that's almost the same as: you can only call for the next one, when the current reference cannot be reached anymore
 
acr
Yeah, I think that is a valid approach.
Maybe you can modify the playground example to show me how you would change the design accordingly. I have my own ideas but only just got started writing Rust.
 
12:38 PM
@acr Like so, except I would likely wrap the &'a mut [u8] into something else that could be either deref'd into the wrapped slice (immutably ofc!) or it would just implement all the accessors and methods you need on it..
So now if you try to use it as:
let i1 = stream.next();
let i2 = stream.next();
println!("{:?} {:?}", i1, i2);
You can't, because you now you want to have two unique references which is impossible..
 
@acr But if you do it like so:
{
    let item = stream.next();
    println!("{:?}", item);
}
{
    let item = stream.next();
    println!("{:?}", item);
}
It will work just fine.
 
acr
Thanks, that looks good.
 
1:06 PM
@acr I was thinking a bit more, and look, this is a bit of cheating: you don't actually borrow anything exclusively, yet you tell compiler just that by using PhantomData
In this scenario, your internal buffer is safe, Wrapper cannot modify it, but also S::next cannot be called until the previous Wrapper has been dropped
How 'bout that? ;)
 
 
2 hours later…
2:54 PM
Y'all talking streaming iterators?
28
Q: How do I write an iterator that returns references to itself?

elszbenI am having trouble expressing the lifetime of the return value of an Iterator implementation. How can I compile this code without changing the return value of the iterator? I'd like it to return a vector of references. It is obvious that I am not using the lifetime parameter correctly but after...

Maybe also called "lending iterators" or "attached iterators".
(to avoid the future problem of calling it a "streaming Stream" for async work)
 
@Shepmaster Intriguing.
 
So, we get from this that the name "streaming iterator" is a pity?
 
@Shepmaster Unless it's going to be added to the prelude, I don't see any problem here (other than the million times overloaded expression, where quite frankly file streams are a much older concept than "streaming" in the modern async terms) -- we have namespaces (just) for this, no?
@Shepmaster Sort of..
 
Are the two names "lending iterators" and "attached iterators" up for debate? :)
 
3:06 PM
@PeterVaro I don't follow your point. Rust doesn't have X. Why introduce X as a confusing name instead of an unconfusing name?
 
@Shepmaster Beg your pardon? What is it that Rust doesn't have?
@E_net4theclosevoter Hope so :) Though lending iterators as a pattern would work for me actually.
 
Rust the standard library doesn't support streaming iterators, where streaming iterator means "returns references to the iterator itself". Rust the ecosystem barely supports this.

Rust the standard library doesn't support async `Stream`s, but it wants to. Rust the ecosystem doesn't support streams that return references to the stream itself. Rust the standard library wants to leave room for this concept.

Naming the concept "streams that return references to itself" as "streaming streams" is a poor idea. The proposed alternatives so far are "lending" / "attached".
 
@PeterVaro But attached iterator is also interesting, as you can imagine attaching the source of the items into the returned item itself.
 
If such a path is chosen, then we might as well rename the analogous concept for iterators to the same
 
So then we would have iterators, streams, lending/attached iterators and lending/attached streams.
 
3:13 PM
@E_net4theclosevoter those are alternatives for each other, but I assume so.
 
Can't we put all of these in the same family with GATs?
 
@PeterVaro now, you could make an argument that the trait from the futures crate shouldn't be called Stream when it's moved to the standard library. I think such a argument is in scope for the eventual RFC, but I'd expect a large amount of pushback.
 
@Shepmaster Well, it really depends on your definition of iterators. If it is Iterator then it doesn't, if it is just 'iterator' then you can implement whatever your heart desires -- though it won't be convenient to use, nor practical in most scenarios. Iterator is just a pattern / concept that happens to be a crucial part of Rust but that doesn't mean you couldn't crave for more and implement your own. Otherwise I don't get your naming comment
 
@E_net4theclosevoter sounds right to me.
 
@Shepmaster That's what I was talking about in the first place, yes
 
3:16 PM
@PeterVaro Which isn't what I'm talking about. I'm talking about calling a subset "streaming streams".
@PeterVaro sure, but people want "iterators that return references to themselves" to be a part of the standard library as they are indeed useful.
> though it won't be convenient to use, nor practical in most scenarios

Indeed: https://crates.io/crates/streaming-iterator
 
Great, got you. I believe acr above called his stuff Stream because he was following this concept called (file) streaming -- has nothing to do with "streaming iterators"
(Though the two concepts are not mutually exclusive)
 
@PeterVaro This is almost the exact expression of what has been known as a streaming iterator
although it tends to split the next and advance methods to work better
 
@Shepmaster That's how I was familiar with this concept -- mainly because of the above linked crate
 
@PeterVaro specifically, I never even saw the word "stream" above; I didn't even scroll that high up. I literally just looked at the code and said "oh, that's a streaming iterator"
 
I don't know, not sure where you are going or what's your point tbf
:D
@Shepmaster Not even in C++ as iostream for example?
 
3:26 PM
@PeterVaro "I never even saw the word "stream" above; I didn't even scroll that high up" — I did not scroll the Stack Overflow chat browser window to see that anyone had (or had not) typed the word "stream".
> I believe acr above called his stuff Stream because he was following this concept called (file) streaming -- has nothing to do with "streaming iterators"
You seem to be implying that I called it a streaming iterator because I saw the word "stream". I am denying that claim. I'm saying that I saw the code block and identified it as the concept of a streaming iterator.
 
Right
 
I'm not stating that I've never heard the term "stream" in other contexts.
 
Behold this cursed pseudocode. play.rust-lang.org/…
 
@E_net4theclosevoter You would need &'a mut self, no?
 
Yes, right. Somehow that got off my rewrite.
 
3:42 PM
@E_net4theclosevoter As well as the rename: ItemGuard -> Guard
 
either way.. we need GAT so much.. SOOOO MUUUUUCCCHHH!
2
 
harvesting stars ?
 
"starvesting"
 
LOL
 
3:50 PM
sounds like starving
 
Well, someone ought to grab them other than me.
 
let's try
gas
damn...
 
acr
4:02 PM
@PeterVaro what benefits does this have over the earlier solution?
(the PhantomData trick)
 
@acr It cleanly communicates that Wrapper doesn't want to mutate the buffer, it just acts as a guard by "holding" an exclusive reference
 
(Also, this is all happening at compile time, the size of Wrapper is the same as &[T])
@E_net4theclosevoter Ain't that the prettiest thing we wish we could have in stable?
 
@PeterVaro Aye. It seems that nightly has enough for generic lock guards.
I wonder if it has enough for the object/attribute abstraction I have in mind for DICOM-rs...
 
@E_net4theclosevoter still cursed
 
4:09 PM
@Shepmaster >:[
 
fite me
 
Why are you doing this to us.
 
lulz
Where are your antistars
 
Well..
1 message moved to Trash can
2
There's the antistar. :>
 
@E_net4theclosevoter 2:1
 
4:11 PM
(note to future readers: do not use this incident to justify RO power abuse please)
 
@E_net4theclosevoter /me is tempted to delete this message just to abuse his "power"
 
It was one. isolated. well justified situation.
For the honour of GATs.
Oh, without boats is looking for a job. Consider RTing this.
3
 
@E_net4theclosevoter Glorious Anomalous Thing, you mean..
@E_net4theclosevoter I have no idea who they are :cold_sweat_smile:
 
@PeterVaro Got Additional Trumps, I see.
 
ahh, I could've used Triumph
Oh well..
 
4:21 PM
Gaming Augmented Tabletops
 
sure, sure, there are plenty, but mine actually described what you just said above
That's a next level backronym skill
:shameless_self_promotion:
 
(those last stars are more useful IMO)
 
Yes, I just pinned it.
 
5:14 PM
Now this is cursed. Taking the overload pattern to the extreme.
 
5:45 PM
You shouldn't use twitter in unsafe mode. Here's what I see:
 
6:20 PM
It's safe.
Trust me, the unsafe Ferris.
 
In any case, if your vector contains concrete structs and you want one at two positions, you have to clone it one way or another
 
Thanks. Exactly what I wanted. A separate copy of struct.
 
 
2 hours later…
acr
9:15 PM
@PeterVaro could you explain to me why the following does not work? play.rust-lang.org/… (it's related to our discussion earlier)
 
 
2 hours later…
11:35 PM
@DenysSéguret twitter has unsafe mode?)
 

« first day (2096 days earlier)      last day (1394 days later) »