2013-03-13 22:02:48 -05:00
|
|
|
// 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::*;
|
2013-04-17 19:55:21 -05:00
|
|
|
use super::misc::PathLike;
|
|
|
|
use super::{Reader, Writer, Seekable, Closeable};
|
|
|
|
use super::{IoError, SeekStyle};
|
|
|
|
|
|
|
|
/// Open a file with the default FileMode and FileAccess
|
|
|
|
/// # TODO are there sane defaults here?
|
|
|
|
pub fn open_file<P: PathLike>(_path: &P) -> FileStream { fail!() }
|
|
|
|
|
|
|
|
/// # TODO
|
|
|
|
/// * Ugh, this is ridiculous. What is the best way to represent these options?
|
|
|
|
enum FileMode {
|
|
|
|
/// Opens an existing file. IoError if file does not exist.
|
|
|
|
Open,
|
|
|
|
/// Creates a file. IoError if file exists.
|
|
|
|
Create,
|
|
|
|
/// Opens an existing file or creates a new one.
|
|
|
|
OpenOrCreate,
|
|
|
|
/// Opens an existing file or creates a new one, positioned at EOF.
|
|
|
|
Append,
|
|
|
|
/// Opens an existing file, truncating it to 0 bytes.
|
|
|
|
Truncate,
|
|
|
|
/// Opens an existing file or creates a new one, truncating it to 0 bytes.
|
|
|
|
CreateOrTruncate,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum FileAccess {
|
|
|
|
Read,
|
|
|
|
Write,
|
|
|
|
ReadWrite
|
|
|
|
}
|
2013-03-13 22:02:48 -05:00
|
|
|
|
|
|
|
pub struct FileStream;
|
|
|
|
|
2013-04-17 19:55:21 -05:00
|
|
|
impl FileStream {
|
|
|
|
pub fn open<P: PathLike>(_path: &P,
|
|
|
|
_mode: FileMode,
|
|
|
|
_access: FileAccess
|
|
|
|
) -> Result<FileStream, IoError> {
|
2013-03-13 22:02:48 -05:00
|
|
|
fail!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 19:55:21 -05:00
|
|
|
impl Reader for FileStream {
|
|
|
|
fn read(&mut self, _buf: &mut [u8]) -> Option<uint> {
|
2013-03-13 22:02:48 -05:00
|
|
|
fail!()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn eof(&mut self) -> bool {
|
|
|
|
fail!()
|
|
|
|
}
|
2013-04-17 19:55:21 -05:00
|
|
|
}
|
2013-03-13 22:02:48 -05:00
|
|
|
|
2013-04-17 19:55:21 -05:00
|
|
|
impl Writer for FileStream {
|
|
|
|
fn write(&mut self, _v: &[u8]) { fail!() }
|
|
|
|
|
|
|
|
fn flush(&mut self) { fail!() }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Seekable for FileStream {
|
|
|
|
fn tell(&self) -> u64 { fail!() }
|
|
|
|
|
|
|
|
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Closeable for FileStream {
|
|
|
|
fn close(&mut self) { fail!() }
|
2013-03-13 22:02:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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";
|
2013-04-17 19:55:21 -05:00
|
|
|
let filename = &Path("test.txt");
|
|
|
|
let mut outstream = FileStream::open(filename, Create, Read).unwrap();
|
2013-03-13 22:02:48 -05:00
|
|
|
outstream.write(message.to_bytes());
|
|
|
|
}
|