|
| 1 | +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use option::*; |
| 12 | +use comm::{GenericPort, GenericChan}; |
| 13 | + |
| 14 | +pub mod file; |
| 15 | + |
| 16 | +// FIXME #5370 Strongly want this to be StreamError(&mut Stream) |
| 17 | +pub struct StreamError; |
| 18 | + |
| 19 | +// XXX: Can't put doc comments on macros |
| 20 | +// Raised by `Stream` instances on error. Returning `true` from the handler |
| 21 | +// indicates that the `Stream` should continue, `false` that it should fail. |
| 22 | +condition! { |
| 23 | + stream_error: super::StreamError -> bool; |
| 24 | +} |
| 25 | + |
| 26 | +pub trait Stream { |
| 27 | + /// Read bytes, up to the length of `buf` and place them in `buf`, |
| 28 | + /// returning the number of bytes read or an `IoError`. Reads |
| 29 | + /// 0 bytes on EOF. |
| 30 | + /// |
| 31 | + /// # Failure |
| 32 | + /// |
| 33 | + /// Raises the `reader_error` condition on error |
| 34 | + fn read(&mut self, buf: &mut [u8]) -> uint; |
| 35 | + |
| 36 | + /// Return whether the Reader has reached the end of the stream |
| 37 | + fn eof(&mut self) -> bool; |
| 38 | + |
| 39 | + /// Write the given buffer |
| 40 | + /// |
| 41 | + /// # Failure |
| 42 | + /// |
| 43 | + /// Raises the `writer_error` condition on error |
| 44 | + fn write(&mut self, v: &const [u8]); |
| 45 | +} |
0 commit comments