-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Should Writer have a flush method? #9126
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
Comments
I wasn't sure about this when I declared it, but one thing I've noticed about I/O libraries is that the abstractions tend to be imperfect like this. I think I recall copying this decision from .NET, but I'm ok trying to move flush to its own trait. If we do that I don't think it necessarily needs to extend Writer though. My inclination though is that having a no-op flush is fine and convenient. Without the no-op flush, Writers that don't do buffering can't be used with code that expects to be able to flush. |
I think that everything calling Other than that, I'm a little bit in favor of having One problem that should be addressed though: If a |
@brson: it's a perfect use case for a default method, with a no-op as the default |
I'd rather make it clear that flush doesn't do anything so you shouldn't bother calling it. I'm not really sure why you would want a Flushable trait to not extend Writer. What can be flushed that can't be written to? I'd rather have BufferedWriter expect a Flushable and combine it with a newtype wrapper for Writer that does a no-op flush. That way it's explicit that flushing doesn't make sense on the underlying Writer and you're telling BufferedWriter to just do nothing instead. |
Something like this. BufferedWriter would impl both Writer and Flushable. |
I think it would be much simpler to just have a default method |
Separating them will give generic code the ability to differentiate between unbuffered writers and buffered writers, which could be useful. It basically assumes all I/O is buffered at the moment. |
I would think that pulling I think better options would be to either have a default no-op |
FWIW Go defines Where do we the see the need for a flush trait? |
So there was a PR/issue somewhere that mentions pulling in chris morgan's tl;dr -- i want to push Seek, flush, etc and all of that out of an UnbufferedStream (which basically would/behave like an fd accessed only w/ pread/pwrite) .. and we can do Seek, |
FWIW, Wr from Modula-3 has flush. The M3 interfaces for systems programming seem particularly well-thought-out and well-specified, though they're designed for use with threads, locks, and exceptions, which might make them not so relevant. |
`explicit_auto_deref` changes fixes rust-lang#9123 fixes rust-lang#9109 fixes rust-lang#9143 fixes rust-lang#9101 This avoid suggesting code which hits a rustc bug. Basically `&{x}` won't use auto-deref if the target type is `Sized`. changelog: Don't suggest using auto deref for block expressions when the target type is `Sized` changelog: Include the borrow in the suggestion for `explicit_auto_deref` changelog: Don't lint `explicit_auto_deref` on `dyn Trait` return changelog: Don't lint `explicit_auto_deref` when other adjustments are required changelog: Lint `explicit_auto_deref` in implicit return positions for closures
Currently,
rt::io::Writer
requires a methodflush(&mut self)
that flushes output. However, this does not make sense for every implementation of Writer. Specifically, libuv has no notion of flush, so none of the current I/O can do it anyway. Some implementationsfail!
when called (TcpStream
,UdpSocket
) while others do nothing at all (FileStream
).Rather than unifying the I/O system on the
fail!
option or the no-op option, I'd like to suggest removingflush
fromWriter
and creating a traitFlushable
that extendsWriter
. We really shouldn't be implementing methods where they don't make sense when we can do otherwise.The text was updated successfully, but these errors were encountered: