mirror of
https://github.com/rust-lang/rust
synced 2024-10-06 08:40:35 +00:00
core: Add rt::io and start sketching the API
This commit is contained in:
parent
5e6dacf32e
commit
57e85b5f94
|
@ -238,7 +238,7 @@ $(foreach target,$(CFG_TARGET_TRIPLES),\
|
|||
|
||||
CORELIB_CRATE := $(S)src/libcore/core.rc
|
||||
CORELIB_INPUTS := $(wildcard $(addprefix $(S)src/libcore/, \
|
||||
core.rc *.rs */*.rs))
|
||||
core.rc *.rs */*.rs */*/*rs))
|
||||
|
||||
######################################################################
|
||||
# Standard library variables
|
||||
|
|
45
src/libcore/rt/io/file.rs
Normal file
45
src/libcore/rt/io/file.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use prelude::*;
|
||||
use super::super::sched::*;
|
||||
use super::super::rtio::*;
|
||||
use super::Stream;
|
||||
|
||||
pub struct FileStream;
|
||||
|
||||
pub impl FileStream {
|
||||
static fn new(path: Path) -> FileStream {
|
||||
fail!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Stream for FileStream {
|
||||
fn read(&mut self, buf: &mut [u8]) -> uint {
|
||||
fail!()
|
||||
}
|
||||
|
||||
fn eof(&mut self) -> bool {
|
||||
fail!()
|
||||
}
|
||||
|
||||
fn write(&mut self, v: &const [u8]) {
|
||||
fail!()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn super_simple_smoke_test_lets_go_read_some_files_and_have_a_good_time() {
|
||||
let message = "it's alright. have a good time";
|
||||
let filename = Path("test.txt");
|
||||
let mut outstream = FileStream::new(filename);
|
||||
outstream.write(message.to_bytes());
|
||||
}
|
45
src/libcore/rt/io/mod.rs
Normal file
45
src/libcore/rt/io/mod.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use option::*;
|
||||
use comm::{GenericPort, GenericChan};
|
||||
|
||||
pub mod file;
|
||||
|
||||
// FIXME #5370 Strongly want this to be StreamError(&mut Stream)
|
||||
pub struct StreamError;
|
||||
|
||||
// XXX: Can't put doc comments on macros
|
||||
// Raised by `Stream` instances on error. Returning `true` from the handler
|
||||
// indicates that the `Stream` should continue, `false` that it should fail.
|
||||
condition! {
|
||||
stream_error: super::StreamError -> bool;
|
||||
}
|
||||
|
||||
pub trait Stream {
|
||||
/// Read bytes, up to the length of `buf` and place them in `buf`,
|
||||
/// returning the number of bytes read or an `IoError`. Reads
|
||||
/// 0 bytes on EOF.
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
/// Raises the `reader_error` condition on error
|
||||
fn read(&mut self, buf: &mut [u8]) -> uint;
|
||||
|
||||
/// Return whether the Reader has reached the end of the stream
|
||||
fn eof(&mut self) -> bool;
|
||||
|
||||
/// Write the given buffer
|
||||
///
|
||||
/// # Failure
|
||||
///
|
||||
/// Raises the `writer_error` condition on error
|
||||
fn write(&mut self, v: &const [u8]);
|
||||
}
|
|
@ -34,6 +34,8 @@ macro_rules! rtdebug (
|
|||
pub mod uvll;
|
||||
mod uvio;
|
||||
mod uv;
|
||||
#[path = "io/mod.rs"]
|
||||
mod io;
|
||||
// FIXME #5248: The import in `sched` doesn't resolve unless this is pub!
|
||||
pub mod thread_local_storage;
|
||||
mod work_queue;
|
||||
|
|
Loading…
Reference in a new issue