Skip to content

Commit 57e85b5

Browse files
committed
core: Add rt::io and start sketching the API
1 parent 5e6dacf commit 57e85b5

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ $(foreach target,$(CFG_TARGET_TRIPLES),\
238238

239239
CORELIB_CRATE := $(S)src/libcore/core.rc
240240
CORELIB_INPUTS := $(wildcard $(addprefix $(S)src/libcore/, \
241-
core.rc *.rs */*.rs))
241+
core.rc *.rs */*.rs */*/*rs))
242242

243243
######################################################################
244244
# Standard library variables

src/libcore/rt/io/file.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 prelude::*;
12+
use super::super::sched::*;
13+
use super::super::rtio::*;
14+
use super::Stream;
15+
16+
pub struct FileStream;
17+
18+
pub impl FileStream {
19+
static fn new(path: Path) -> FileStream {
20+
fail!()
21+
}
22+
}
23+
24+
impl Stream for FileStream {
25+
fn read(&mut self, buf: &mut [u8]) -> uint {
26+
fail!()
27+
}
28+
29+
fn eof(&mut self) -> bool {
30+
fail!()
31+
}
32+
33+
fn write(&mut self, v: &const [u8]) {
34+
fail!()
35+
}
36+
}
37+
38+
#[test]
39+
#[ignore]
40+
fn super_simple_smoke_test_lets_go_read_some_files_and_have_a_good_time() {
41+
let message = "it's alright. have a good time";
42+
let filename = Path("test.txt");
43+
let mut outstream = FileStream::new(filename);
44+
outstream.write(message.to_bytes());
45+
}

src/libcore/rt/io/mod.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

src/libcore/rt/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ mod rtio;
3434
pub mod uvll;
3535
mod uvio;
3636
mod uv;
37+
#[path = "io/mod.rs"]
38+
mod io;
3739
// FIXME #5248: The import in `sched` doesn't resolve unless this is pub!
3840
pub mod thread_local_storage;
3941
mod work_queue;

0 commit comments

Comments
 (0)