diff options
| author | FenrirWolf <[email protected]> | 2018-04-21 16:39:03 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-04-21 16:39:03 -0600 |
| commit | 159b5b9e62ce074bbbd1900137670a9f5426a8bd (patch) | |
| tree | 4fecd0ca00b754c494e96b13e9837db48de93109 /ctr-std/src/io/cursor.rs | |
| parent | Move more implementation details to `imp` module (diff) | |
| parent | Update for Rust nightly 2018-04-19 (diff) | |
| download | archived-ctru-rs-159b5b9e62ce074bbbd1900137670a9f5426a8bd.tar.xz archived-ctru-rs-159b5b9e62ce074bbbd1900137670a9f5426a8bd.zip | |
Merge pull request #64 from FenrirWolf/nightly-update
Update for Rust nightly 2018-04-19
Diffstat (limited to 'ctr-std/src/io/cursor.rs')
| -rw-r--r-- | ctr-std/src/io/cursor.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/ctr-std/src/io/cursor.rs b/ctr-std/src/io/cursor.rs index 76bcb5f..2673f3c 100644 --- a/ctr-std/src/io/cursor.rs +++ b/ctr-std/src/io/cursor.rs @@ -10,7 +10,6 @@ use io::prelude::*; -use core::convert::TryInto; use cmp; use io::{self, Initializer, SeekFrom, Error, ErrorKind}; @@ -260,9 +259,26 @@ 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 = (*pos_mut).try_into().map_err(|_| { + let pos: usize = try_into(*pos_mut).map_err(|_| { Error::new(ErrorKind::InvalidInput, "cursor position exceeds maximum possible vector length") })?; |