- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Add Reader impl for &[u8] and Writer impl for &mut [u8] #18980
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
Conversation
| Needs a rebase. | 
| Rebased, and ready for a re-review. | 
30fdb60    to
    b1a1688      
    Compare
  
            
          
                src/libstd/io/mem.rs
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't this be a ShortWrite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does an EndOfFile if self.len() is 0, and ShortWrite if it was able to partially right the file sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should writing a &[] to a &[] be an EndOfFile, or be okay?
| The  let mut buf = vec![];
write!(&mut buf, "hello world"); // Calls Vec's impl
write(buf, "hello world"); // Calls &mut [u8]'s impl | 
| @sfackler: That is... weird. I would have expected  | 
| @erickt it's due to this line, which was apparently added to force people to pass references in like you would a function: https://github.com/rust-lang/rust/blob/master/src/libstd/macros.rs#L266 | 
| While it's possible to implement  Other than that this looks great though, thanks @erickt! | 
| I've updated my PR to factor out the  | 
        
          
                src/libcore/result.rs
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be let mut buffer = b"...";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch.
| Looks great, thanks @erickt! I think there may be a waiting failure in the doctest, but otherwise r=me | 
        
          
                src/libcore/result.rs
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a .as_bytes().
This continues the work @thestinger started in #18885 (which hasn't landed yet, so wait for that to land before landing this one). Instead of adding more methods to `BufReader`, this just allows a `&[u8]` to be used directly as a `Reader`. It also adds an impl of `Writer` for `&mut [u8]`.
rust-lang/rust#18980 This implements Reader for us. With this commit we finished using both MemWriter & MemReader.
minor: Sync from downstream
This continues the work @thestinger started in #18885 (which hasn't landed yet, so wait for that to land before landing this one). Instead of adding more methods to
BufReader, this just allows a&[u8]to be used directly as aReader. It also adds an impl ofWriterfor&mut [u8].