-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Stream wrappers standardization #1568
Conversation
I do not think having these traits in some crate as opposed to the standard library precludes their de facto standardisation. If the crate turns out to be somewhat popular, it could be moved into nursery. In my eyes to include something like that into the standard library you’d need some use-case in said standard library. |
I'm sure, that nobody will use crate with two traits. Its just no one will find it.
I know only one struct from standard library for which this trait useful: std::io::BufWriter {
fn get_ref(&self) -> &W;
fn into_inner(self) -> Result<W, IntoInnerError<BufWriter<W>>>;
} It differ with
I don't known standard structs for |
Not if ~every compression library depends on it and implements them. There is a community perspective here that you need to have. Further efforts like stdx lower the barrier even further. The Rust Way ™️ is clear here: this belongs in a separate crate. The standard for something added to Ignoring that I don't think this is a good idea:
|
It is difficult to argue :)
This RFC has appeared due to the fact that most do not think about it. In many respects, this problem is specific to rust: in other languages I can simply store unsafe Write reference in some variable :)
Maybe.
Sorry, English is not my native language. I known, that my English is very poor.
Compression is original use case. But this trait is useful from any state full transformation. Distinctive feature: explicit needed to complete the work.
I could not think of another real use case.
I see no reason why it is not necessary to return Read/Write.
There is always an exotic usage scenario. At the moment, I can not think of.
I'm sure, that returning mutable reference is unsafe. Immutable reference guarantee that anyone can broken stream, but useful for getting statistics from wrapped stream.
In a perfect world, you want to return as much information as possible. But I think that in most cases this should be enough. For example, in generic case wrapped stream is useless on finish error, because it contains undefined state. In any case, it is always possible to implement a method different signature for specific case. |
While I do agree that the RFC needs more work, I think that making readers and writers from different projects easier to compose is a great idea. |
🔔 This RFC is now entering its week-long final comment period 🔔 The libs team discussed this RFC during triage yesterday and the conclusion was that this doesn't seem quite ripe for inclusion in the standard library yet (as-is). We've been toying with the idea of explicit |
Unfortunately, I can not bring this RFC to the required quality level because of problems with the English language :( |
I ran into this scenario myself once. There is one issue with the current proposal: Here’s an example: trait Consume {
fn consume(self);
}
let trait_obj: Box<Consume> = ...
trait_obj.consume(); // E0161 And the best workaround that I am aware of: trait ConsumeBox: Consume {
fn consume_box(self: Box< Self >);
}
impl <T: Consume > ConsumeBox for T {
fn consume_box(self: Box<T>) {
self.consume();
}
}
let trait_obj: Box<ConsumeBox > = ...
trait_obj.consume_box(); // Fine (Aside: I talked about this finish/finalize scenario at Rust Amsterdam. The slides are here, though they might be a bit cryptic without context.) |
I discover this rfc a bit late but I got this crate (not on cargo since I want to finish to implement some usecases before),where I also need an End method (see (ExtRead)[http://cheme.github.io/readwrite-comp/readwrite_comp/trait.ExtRead.html] and (ExtWrite)[http://cheme.github.io/readwrite-comp/readwrite_comp/trait.ExtRead.html] . The main purpose of the crate is to compose reader such as compression or encryption (my use case is writing some tunnels). The reader reference has been put out of the trait (to compose extread trait implementation without having to care about the reader lifetime). I drop the info here just in case it may interest anyone. The interesting point is that I implemented Read and Write for structure including reader and extreader. For such composition, I use (CompW)[http://cheme.github.io/readwrite-comp/readwrite_comp/struct.CompW.html] as a standard Write trait, I had to use very dirty drop implementation to end the writing operation (flush got a different semantic), this is a major dropback because I need to silence write error or panic if something wrong happen. In short, end method for writer and reader seems also really usefull to me (and I got direct use of them). +1 |
I'd like to note that streaming APIs of this type are often actively dangerous in cryptography, and should be avoided - they frequently open up many classes of attacks that should not even be on the table. |
Indeed, part of the 'never implement your own crypto' principle... (don't look at any tunnel.rs in some of my mydht crates). Composing crypto primitive being in itself the same. Regarding the rfc (original usecase was compression), I remember the reason why I externalize the actual Reader/Writer from ReaderExt/WriterExt trait. The point was that this way it was easier to design MultiW/MultiR which contains an array of the trait ReaderExt/WriteExt trait and use afterward a struct (CompW/CompR) to associate it with an actual reader. |
What problem would this proposal actually solve? The Motivation section mentions lack of consistency between the existing wrappers, but then it does not go on to provide any example where the consistency would actually be needed for anything. And I can't think about such example either: The only code that can reasonably call the @nagisa, if the use-case exists, anywhere, then the |
The libs team got a chance to discuss this RFC during triage yesterday and the conclusion was that like before we feel that the motivation of this RFC would be best served with a Thanks regardless though for the RFC @bozaro! |
I wrote simple binding for lz4 compression (https://github.com/bozaro/lz4-rs) and got issue bozaro/lz4-rs#9.
The main problem is: there are not best practices for writing compression (encryption and etc) libraries.
Compression libraries need some method for "finish" work: write end stream mark and flush data.
This work should not run in drop() method: I prefer unexpected end of stream instead of success on reading incomplete stream.
As result I create this PR :)