aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/io/cursor.rs
diff options
context:
space:
mode:
authorFenrirWolf <[email protected]>2018-08-19 18:01:18 -0600
committerGitHub <[email protected]>2018-08-19 18:01:18 -0600
commit15cb3c1e91842a68a8e50e1e1a42aefab13cc25e (patch)
treea514fde042ff2a504a03305bfe0894ff8cd8d47e /ctr-std/src/io/cursor.rs
parentUpdate for latest nightly 2018-06-09 (#70) (diff)
parentUpdate for nightly-2018-08-18 (diff)
downloadctru-rs-15cb3c1e91842a68a8e50e1e1a42aefab13cc25e.tar.xz
ctru-rs-15cb3c1e91842a68a8e50e1e1a42aefab13cc25e.zip
Merge pull request #73 from FenrirWolf/update-2018-08-18
Update for nightly-2018-08-18
Diffstat (limited to 'ctr-std/src/io/cursor.rs')
-rw-r--r--ctr-std/src/io/cursor.rs57
1 files changed, 11 insertions, 46 deletions
diff --git a/ctr-std/src/io/cursor.rs b/ctr-std/src/io/cursor.rs
index 8ac5257..14f2015 100644
--- a/ctr-std/src/io/cursor.rs
+++ b/ctr-std/src/io/cursor.rs
@@ -10,15 +10,17 @@
use io::prelude::*;
+use core::convert::TryInto;
use cmp;
use io::{self, Initializer, SeekFrom, Error, ErrorKind};
-/// A `Cursor` wraps another type and provides it with a
+/// A `Cursor` wraps an in-memory buffer and provides it with a
/// [`Seek`] implementation.
///
-/// `Cursor`s are typically used with in-memory buffers to allow them to
-/// implement [`Read`] and/or [`Write`], allowing these buffers to be used
-/// anywhere you might use a reader or writer that does actual I/O.
+/// `Cursor`s are used with in-memory buffers, anything implementing
+/// `AsRef<[u8]>`, to allow them to implement [`Read`] and/or [`Write`],
+/// allowing these buffers to be used anywhere you might use a reader or writer
+/// that does actual I/O.
///
/// The standard library implements some I/O traits on various types which
/// are commonly used as a buffer, like `Cursor<`[`Vec`]`<u8>>` and
@@ -86,11 +88,11 @@ pub struct Cursor<T> {
}
impl<T> Cursor<T> {
- /// Creates a new cursor wrapping the provided underlying I/O object.
+ /// Creates a new cursor wrapping the provided underlying in-memory buffer.
///
- /// Cursor initial position is `0` even if underlying object (e.
- /// g. `Vec`) is not empty. So writing to cursor starts with
- /// overwriting `Vec` content, not with appending to it.
+ /// Cursor initial position is `0` even if underlying buffer (e.g. `Vec`)
+ /// is not empty. So writing to cursor starts with overwriting `Vec`
+ /// content, not with appending to it.
///
/// # Examples
///
@@ -259,26 +261,9 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result<us
Ok(amt)
}
-/// Compensate removal of some impls per
-/// https://github.com/rust-lang/rust/pull/49305#issuecomment-376293243
-#[cfg(any(target_pointer_width = "16",
- target_pointer_width = "32"))]
-fn try_into(n: u64) -> Result<usize, ()> {
- if n <= (<usize>::max_value() as u64) {
- Ok(n as usize)
- } else {
- Err(())
- }
-}
-
-#[cfg(any(target_pointer_width = "64"))]
-fn try_into(n: u64) -> Result<usize, ()> {
- Ok(n as usize)
-}
-
// Resizing write implementation
fn vec_write(pos_mut: &mut u64, vec: &mut Vec<u8>, buf: &[u8]) -> io::Result<usize> {
- let pos: usize = try_into(*pos_mut).map_err(|_| {
+ let pos: usize = (*pos_mut).try_into().map_err(|_| {
Error::new(ErrorKind::InvalidInput,
"cursor position exceeds maximum possible vector length")
})?;
@@ -566,26 +551,6 @@ mod tests {
}
#[test]
- #[allow(deprecated)]
- fn test_read_char() {
- let b = &b"Vi\xE1\xBB\x87t"[..];
- let mut c = Cursor::new(b).chars();
- assert_eq!(c.next().unwrap().unwrap(), 'V');
- assert_eq!(c.next().unwrap().unwrap(), 'i');
- assert_eq!(c.next().unwrap().unwrap(), 'ệ');
- assert_eq!(c.next().unwrap().unwrap(), 't');
- assert!(c.next().is_none());
- }
-
- #[test]
- #[allow(deprecated)]
- fn test_read_bad_char() {
- let b = &b"\x80"[..];
- let mut c = Cursor::new(b).chars();
- assert!(c.next().unwrap().is_err());
- }
-
- #[test]
fn seek_past_end() {
let buf = [0xff];
let mut r = Cursor::new(&buf[..]);