From 57e85b5f947387195cec1338fcb94b7cfb88bd86 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 13 Mar 2013 20:02:48 -0700 Subject: [PATCH] core: Add rt::io and start sketching the API --- Makefile.in | 2 +- src/libcore/rt/io/file.rs | 45 +++++++++++++++++++++++++++++++++++++++ src/libcore/rt/io/mod.rs | 45 +++++++++++++++++++++++++++++++++++++++ src/libcore/rt/mod.rs | 2 ++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/libcore/rt/io/file.rs create mode 100644 src/libcore/rt/io/mod.rs diff --git a/Makefile.in b/Makefile.in index 268a25d72fc1..dd2e6a95861b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 diff --git a/src/libcore/rt/io/file.rs b/src/libcore/rt/io/file.rs new file mode 100644 index 000000000000..02ad6a00a149 --- /dev/null +++ b/src/libcore/rt/io/file.rs @@ -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 or the MIT license +// , 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()); +} diff --git a/src/libcore/rt/io/mod.rs b/src/libcore/rt/io/mod.rs new file mode 100644 index 000000000000..f82092b829c9 --- /dev/null +++ b/src/libcore/rt/io/mod.rs @@ -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 or the MIT license +// , 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]); +} diff --git a/src/libcore/rt/mod.rs b/src/libcore/rt/mod.rs index bc0efc01fbb7..c00162287fd3 100644 --- a/src/libcore/rt/mod.rs +++ b/src/libcore/rt/mod.rs @@ -34,6 +34,8 @@ mod rtio; 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;