while read < min {
let mut zeroes = 0;
loop {
- match self.read(buf[mut read..]) {
+ match self.read(buf.slice_from_mut(read)) {
Ok(0) => {
zeroes += 1;
if zeroes >= NO_PROGRESS_LIMIT {
// API yet. If so, it should be a method on Vec.
unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec<T>, start: uint, end: uint) -> &'a mut [T] {
use raw::Slice;
- use ptr::RawPtr;
+ use ptr::PtrExt;
assert!(start <= end);
assert!(end <= v.capacity());
/// decide whether their stream needs to be buffered or not.
fn flush(&mut self) -> IoResult<()> { Ok(()) }
+ // NOTE(stage0): Remove cfg after a snapshot
+ #[cfg(not(stage0))]
+ /// Writes a formatted string into this writer, returning any error
+ /// encountered.
+ ///
+ /// This method is primarily used to interface with the `format_args!`
+ /// macro, but it is rare that this should explicitly be called. The
+ /// `write!` macro should be favored to invoke this method instead.
+ ///
+ /// # Errors
+ ///
+ /// This function will return any I/O error reported while formatting.
+ fn write_fmt(&mut self, fmt: fmt::Arguments) -> IoResult<()> {
+ // Create a shim which translates a Writer to a FormatWriter and saves
+ // off I/O errors. instead of discarding them
+ struct Adaptor<'a, T:'a> {
+ inner: &'a mut T,
+ error: IoResult<()>,
+ }
+
+ impl<'a, T: Writer> fmt::FormatWriter for Adaptor<'a, T> {
+ fn write(&mut self, bytes: &[u8]) -> fmt::Result {
+ match self.inner.write(bytes) {
+ Ok(()) => Ok(()),
+ Err(e) => {
+ self.error = Err(e);
+ Err(fmt::Error)
+ }
+ }
+ }
+ }
+
+ let mut output = Adaptor { inner: self, error: Ok(()) };
+ match fmt::write(&mut output, fmt) {
+ Ok(()) => Ok(()),
+ Err(..) => output.error
+ }
+ }
+
+
+ // NOTE(stage0): Remove method after a snapshot
+ #[cfg(stage0)]
/// Writes a formatted string into this writer, returning any error
/// encountered.
///
#[inline]
fn write_char(&mut self, c: char) -> IoResult<()> {
let mut buf = [0u8, ..4];
- let n = c.encode_utf8(buf[mut]).unwrap_or(0);
+ let n = c.encode_utf8(buf.as_mut_slice()).unwrap_or(0);
self.write(buf[..n])
}
{
let mut start = 1;
while start < width {
- match try!(self.read(buf[mut start..width])) {
+ match try!(self.read(buf.slice_mut(start, width))) {
n if n == width - start => break,
n if n < width - start => { start += n; }
_ => return Err(standard_error(InvalidInput)),
/// A mode specifies how a file should be opened or created. These modes are
/// passed to `File::open_mode` and are used to control where the file is
/// positioned when it is initially opened.
- #[deriving(Copy)]
+ #[deriving(Copy, Clone, PartialEq, Eq)]
pub enum FileMode {
/// Opens a file positioned at the beginning.
Open,
/// Access permissions with which the file should be opened. `File`s
/// opened with `Read` will return an error if written to.
- #[deriving(Copy)]
+ #[deriving(Copy, Clone, PartialEq, Eq)]
pub enum FileAccess {
/// Read-only access, requests to write will result in an error
Read,