From e7fc234fdf9506fa1f7a3cd63800c00336770b1c Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 23 Aug 2021 10:13:40 -0400 Subject: [PATCH] Remove unstable library features --- .github/workflows/build.yaml | 3 ++- src/bin.rs | 4 +--- src/disc/gcn.rs | 12 +++++------ src/disc/wii.rs | 12 +++++------ src/io/nfs.rs | 12 +++++------ src/lib.rs | 2 -- src/streams.rs | 39 ++++++++++++++++++++++++------------ 7 files changed, 47 insertions(+), 37 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ec924be..0901be1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,6 +9,7 @@ jobs: matrix: platform: [ ubuntu-latest, macos-latest, windows-latest ] toolchain: [ stable, 1.35.0, nightly ] + fail-fast: false runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v2 @@ -22,7 +23,7 @@ jobs: args: --release --all-features - uses: actions/upload-artifact@v2 with: - name: ${{ matrix.platform }} + name: ${{ matrix.platform }}-${{ matrix.toolchain }} path: | target/release/nodtool target/release/nodtool.exe diff --git a/src/bin.rs b/src/bin.rs index 7ac94f8..ce804f0 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -1,5 +1,3 @@ -#![feature(with_options)] - use std::{env, fs, io}; use std::io::BufWriter; use std::path::{Path, PathBuf}; @@ -8,10 +6,10 @@ use std::time::Instant; use clap::{AppSettings, clap_app}; use file_size; -use nod::Result; use nod::disc::{new_disc_base, PartReadStream}; use nod::fst::NodeType; use nod::io::{has_extension, new_disc_io}; +use nod::Result; fn main() -> Result<()> { let matches = clap_app!(nodtool => diff --git a/src/disc/gcn.rs b/src/disc/gcn.rs index e9fa344..cd889da 100644 --- a/src/disc/gcn.rs +++ b/src/disc/gcn.rs @@ -75,7 +75,7 @@ impl<'a> Seek for GCPartReadStream<'a> { fn seek(&mut self, pos: SeekFrom) -> io::Result { self.offset = match pos { SeekFrom::Start(v) => v, - SeekFrom::End(v) => (self.stream_len()? as i64 + v) as u64, + SeekFrom::End(v) => (self.stable_stream_len()? as i64 + v) as u64, SeekFrom::Current(v) => (self.offset as i64 + v) as u64, }; let block = self.offset / BUFFER_SIZE as u64; @@ -86,16 +86,16 @@ impl<'a> Seek for GCPartReadStream<'a> { io::Result::Ok(self.offset) } - fn stream_len(&mut self) -> io::Result { - self.stream.stream_len() - } - fn stream_position(&mut self) -> io::Result { io::Result::Ok(self.offset) } } -impl<'a> ReadStream for GCPartReadStream<'a> {} +impl<'a> ReadStream for GCPartReadStream<'a> { + fn stable_stream_len(&mut self) -> io::Result { + self.stream.stable_stream_len() + } +} impl<'a> PartReadStream for GCPartReadStream<'a> { fn begin_file_stream(&mut self, node: &Node) -> io::Result { diff --git a/src/disc/wii.rs b/src/disc/wii.rs index ac68e00..5254422 100644 --- a/src/disc/wii.rs +++ b/src/disc/wii.rs @@ -361,7 +361,7 @@ impl<'a> Seek for WiiPartReadStream<'a> { fn seek(&mut self, pos: SeekFrom) -> io::Result { self.offset = match pos { SeekFrom::Start(v) => v, - SeekFrom::End(v) => (self.stream_len()? as i64 + v) as u64, + SeekFrom::End(v) => (self.stable_stream_len()? as i64 + v) as u64, SeekFrom::Current(v) => (self.offset as i64 + v) as u64, }; let block = self.offset / BLOCK_SIZE as u64; @@ -372,16 +372,16 @@ impl<'a> Seek for WiiPartReadStream<'a> { io::Result::Ok(self.offset) } - fn stream_len(&mut self) -> io::Result { - io::Result::Ok(to_block_size(self.stream.stream_len()?)) - } - fn stream_position(&mut self) -> io::Result { io::Result::Ok(self.offset) } } -impl<'a> ReadStream for WiiPartReadStream<'a> {} +impl<'a> ReadStream for WiiPartReadStream<'a> { + fn stable_stream_len(&mut self) -> io::Result { + io::Result::Ok(to_block_size(self.stream.stable_stream_len()?)) + } +} #[derive(Clone, Debug, PartialEq, BinRead)] pub(crate) struct WiiPartition { diff --git a/src/io/nfs.rs b/src/io/nfs.rs index 25950eb..cb7ce5f 100644 --- a/src/io/nfs.rs +++ b/src/io/nfs.rs @@ -211,7 +211,7 @@ impl<'a> Seek for NFSReadStream<'a> { fn seek(&mut self, pos: SeekFrom) -> io::Result { self.offset = match pos { SeekFrom::Start(v) => v, - SeekFrom::End(v) => (self.stream_len()? as i64 + v) as u64, + SeekFrom::End(v) => (self.stable_stream_len()? as i64 + v) as u64, SeekFrom::Current(v) => (self.offset as i64 + v) as u64, }; self.set_logical_addr(self.offset) @@ -222,16 +222,16 @@ impl<'a> Seek for NFSReadStream<'a> { io::Result::Ok(self.offset) } - fn stream_len(&mut self) -> io::Result { - todo!() - } - fn stream_position(&mut self) -> io::Result { io::Result::Ok(self.offset) } } -impl<'a> ReadStream for NFSReadStream<'a> {} +impl<'a> ReadStream for NFSReadStream<'a> { + fn stable_stream_len(&mut self) -> io::Result { + todo!() + } +} impl DiscIO for DiscIONFS { fn begin_read_stream(&self, offset: u64) -> io::Result> { diff --git a/src/lib.rs b/src/lib.rs index d3bc59b..abfef3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,8 +26,6 @@ //! println!(s); //! } //! ``` -#![feature(seek_stream_len)] - pub mod fst; pub mod disc; pub mod io; diff --git a/src/streams.rs b/src/streams.rs index fc837f7..161d8e5 100644 --- a/src/streams.rs +++ b/src/streams.rs @@ -15,9 +15,22 @@ macro_rules! array_ref { }} } -pub trait ReadStream: Read + Seek {} +pub trait ReadStream: Read + Seek { + /// Replace with [`Read.stream_len`] when stabilized. + /// + /// + fn stable_stream_len(&mut self) -> io::Result; +} -impl ReadStream for File {} +impl ReadStream for File { + fn stable_stream_len(&mut self) -> io::Result { + let before = self.stream_position()?; + let result = self.seek(SeekFrom::End(0)); + // Try to restore position even if the above failed + self.seek(SeekFrom::Start(before))?; + result + } +} trait WindowedReadStream: ReadStream { fn base_stream(&mut self) -> &mut dyn ReadStream; @@ -39,7 +52,7 @@ pub struct SharedWindowedReadStream<'a> { #[inline(always)] fn windowed_read(stream: &mut dyn WindowedReadStream, buf: &mut [u8]) -> io::Result { let pos = stream.stream_position()?; - let size = stream.stream_len()?; + let size = stream.stable_stream_len()?; stream.base_stream().read(if pos + buf.len() as u64 > size { &mut buf[..(size - pos) as usize] } else { @@ -73,16 +86,16 @@ impl<'a> Seek for OwningWindowedReadStream<'a> { windowed_seek(self, pos) } - fn stream_len(&mut self) -> io::Result { - Result::Ok(self.end - self.begin) - } - fn stream_position(&mut self) -> io::Result { Result::Ok(self.base.stream_position()? - self.begin) } } -impl<'a> ReadStream for OwningWindowedReadStream<'a> {} +impl<'a> ReadStream for OwningWindowedReadStream<'a> { + fn stable_stream_len(&mut self) -> io::Result { + Result::Ok(self.end - self.begin) + } +} impl<'a> WindowedReadStream for OwningWindowedReadStream<'a> { fn base_stream(&mut self) -> &mut dyn ReadStream { @@ -105,16 +118,16 @@ impl<'a> Seek for SharedWindowedReadStream<'a> { windowed_seek(self, pos) } - fn stream_len(&mut self) -> io::Result { - Result::Ok(self.end - self.begin) - } - fn stream_position(&mut self) -> io::Result { Result::Ok(self.base.stream_position()? - self.begin) } } -impl<'a> ReadStream for SharedWindowedReadStream<'a> {} +impl<'a> ReadStream for SharedWindowedReadStream<'a> { + fn stable_stream_len(&mut self) -> io::Result { + Result::Ok(self.end - self.begin) + } +} impl<'a> WindowedReadStream for SharedWindowedReadStream<'a> { fn base_stream(&mut self) -> &mut dyn ReadStream {