oracle/
io.rs

1// Rust-oracle - Rust binding for Oracle database
2//
3// URL: https://github.com/kubo/rust-oracle
4//
5//-----------------------------------------------------------------------------
6// Copyright (c) 2017-2021 Kubo Takehiro <kubo@jiubao.org>. All rights reserved.
7// This program is free software: you can modify it and/or redistribute it
8// under the terms of:
9//
10// (i)  the Universal Permissive License v 1.0 or at your option, any
11//      later version (http://oss.oracle.com/licenses/upl); and/or
12//
13// (ii) the Apache License v 2.0. (http://www.apache.org/licenses/LICENSE-2.0)
14//-----------------------------------------------------------------------------
15
16//! Type definitions for I/O in characters
17use std::io::{Result, SeekFrom};
18
19/// A cursor which can be moved within a stream of characters.
20///
21/// This is same with [`Seek`] except positions are numbered in characters, not in bytes.
22///
23/// [`Seek`]: std::io::Seek
24pub trait SeekInChars {
25    /// Seek to an offset, in characters, in a stream.
26    ///
27    /// A seek beyond the end of a stream is allowed, but behavior is defined
28    /// by the implementation.
29    ///
30    /// If the seek operation completed successfully,
31    /// this method returns the new position from the start of the stream.
32    /// That position can be used later with [`SeekFrom::Start`].
33    ///
34    /// # Errors
35    ///
36    /// Seeking to a negative offset is considered an error.
37    fn seek_in_chars(&mut self, pos: SeekFrom) -> Result<u64>;
38
39    /// Returns the current seek position from the start of the stream.
40    ///
41    /// This is equivalent to `self.seek_in_chars(SeekFrom::Current(0))`.
42    fn stream_position_in_chars(&mut self) -> Result<u64> {
43        self.seek_in_chars(SeekFrom::Current(0))
44    }
45}