Finalize the Seek API
This adopts the rules posted in #10432: 1. If a seek position is negative, then an error is generated 2. Seeks beyond the end-of-file are allowed. Future writes will fill the gap with data and future reads will return errors. 3. Seeks within the bounds of a file are fine. Closes #10432
This commit is contained in:
parent
4c967e7041
commit
1b6a1e98a8
2 changed files with 80 additions and 31 deletions
|
@ -1192,19 +1192,21 @@ pub enum SeekStyle {
|
|||
SeekCur,
|
||||
}
|
||||
|
||||
/// # FIXME
|
||||
/// * Are `u64` and `i64` the right choices?
|
||||
pub trait Seek {
|
||||
/// Return position of file cursor in the stream
|
||||
fn tell(&self) -> IoResult<u64>;
|
||||
|
||||
/// Seek to an offset in a stream
|
||||
///
|
||||
/// A successful seek clears the EOF indicator.
|
||||
/// A successful seek clears the EOF indicator. Seeking beyond EOF is
|
||||
/// allowed, but seeking before position 0 is not allowed.
|
||||
///
|
||||
/// # FIXME
|
||||
/// # Errors
|
||||
///
|
||||
/// * What is the behavior when seeking past the end of a stream?
|
||||
/// * Seeking to a negative offset is considered an error
|
||||
/// * Seeking past the end of the stream does not modify the underlying
|
||||
/// stream, but the next write may cause the previous data to be filled in
|
||||
/// with a bit pattern.
|
||||
fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()>;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue