-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SliceSeekableStream #1815
Comments
I don't understand. What is it about SliceInStream and SliceOutStream that requires wrapping then in another struct? Here, I took your code and just removed the SliceWithCursor and replaced it with SliceInStream and it works fine:
|
What about SliceOutStream though? (allowing both seekable in streams and seekable out streams) |
What about it? As far as I can tell it should work just fine with a few changes:
|
I wish we didn't have to use ad hoc unwritten interfaces but ok. We are here now:
Could maybe move those error types out of the seekable struct, or just use vars instead of having to pass them explicitly. I suppose this is treading on other proposals about traits, constrained generic types etc. I don't have anything to add to those discussions since I'm not really up to speed. I'm not sure what the Zig idiom is / where it's heading. |
Well they could be predefined in the standard lib:
Passing the Errors around like this are an unfortunate consequence of how streams are done currently in std. They're written as runtime interfaces but are effectively comptime because of the ErrorSet information. I do think that's a separate, but important, issue to address though. See: #764 |
Another flaw with my idea - SliceInStream uses a I'm trying out some different things now, in light of #1829. My current idea is two structs,
There's also Anyways, code here: https://github.com/dbandstra/zigutils/tree/new-streams/src/streams Unfortunately, the SeekableStream implementations are copy-pasted between IConstSlice and ISlice. But on the positive side, this idea minimizes needless indirections. |
I'm going to close this, I don't have the interest to follow it up. It seems like other people have a better handle on the whole trait thing, so this will probably get improved as part of a larger sweeping change anyway. |
👍 you're not alone; lots of us agree this is a problem, and there are some other issues open to track this. |
I noticed that SeekableStream has been added to the zig std, which is nice. But it only seems to be useable with FileInStream currently. I get a lot of use out of SliceInStream so I was pondering how to get it working with that (then I can get rid of a lot of code in my personal zigutils library). So I propose a somewhat drastic change to SliceInStream - a new object type at the heart:
This is analogous to the File object for file streams. SliceInStream (and SliceOutStream?) holds a pointer to one of these, rather than the slice directly. Now you can easily implement SliceSeekableStream as well.
Downside: using these things becomes even more verbose. We end up with this:
Full code:
https://github.com/dbandstra/zigutils/blob/master/src/SliceStream.zig
Aside: Maybe SliceInStream, SliceOutStream, and SliceSeekableStream could be placed inside the SliceWithCursor struct namespace, like it is in the file code. I'm not personally a fan of that but Zig seems to go that way.
The text was updated successfully, but these errors were encountered: