-
Notifications
You must be signed in to change notification settings - Fork 30
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
Consider taking writers by value #20
Comments
This seems very plausible! I'll check it out. |
Investigation suggests that while this is fine for This seems like it would confound structural recursion through tree-structured data, e.g. struct Tree {
children: Vec<Tree>,
} |
Let's not do this then, as I said it's not a big issue ;) |
Wait. Given that &mut W implements Write since W implements Write, what prevents you from sending around an &mut writer while traversing a tree ? |
I think that is what happens now, isn't it? We could allow |
To clarify, I meant that because &mut W implements Write just like owned writers, this code is legal:
Therefore, there is no problem with accepting "owned" writers, and using them multiple times. |
Yup, I agree. However, pub fn takes_write_impl(mut w: impl std::io::Write) {
takes_write_impl(&mut w)
}
fn main() {
let mut bytes = Vec::new();
takes_write_impl(&mut bytes);
} trips a recursion limit
This is the problem I think exists, as we seem to need to use |
Oh, I see. This could cause problems with deep object trees indeed, especially as it also implies that the compiler is generating O(N) copies of take_write_impl when using this pattern, which is a compilation time liability. Then I agree with you: |
&mut T
whereT: Write
implementsWrite
, so there is no reason to ask for a borrowed writer in the API. But this is unlikely to be a problem in practice because owned writers are rarely used.The text was updated successfully, but these errors were encountered: