Skip to content

Commit

Permalink
rust: Use std::io instead of deku::no_std_io
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Jan 24, 2025
1 parent ab1b93f commit 1059205
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rust/src/unity/types/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub struct ByteArray {
}

impl<'a, Ctx> DekuReader<'a, Ctx> for ByteArray where Ctx: Copy {
fn from_reader_with_ctx<R: deku::no_std_io::Read + deku::no_std_io::Seek>(reader: &mut Reader<R>, _ctx: Ctx) -> Result<Self, DekuError> {
fn from_reader_with_ctx<R: std::io::Read + std::io::Seek>(reader: &mut Reader<R>, _ctx: Ctx) -> Result<Self, DekuError> {
let count = i32::from_reader_with_ctx(reader, ())? as usize;
let mut buf = vec![0x00; count];
reader.read_bytes(count, &mut buf)?;
Expand Down
10 changes: 5 additions & 5 deletions rust/src/unity/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn check_count(count: usize, limit: usize) -> Result<(), DekuError> {
}

impl<'a, T, Ctx> DekuReader<'a, Ctx> for UnityArray<T> where T: DekuReader<'a, Ctx>, Ctx: Clone {
fn from_reader_with_ctx<R: deku::no_std_io::Read + deku::no_std_io::Seek>(reader: &mut Reader<R>, ctx: Ctx) -> Result<Self, DekuError> {
fn from_reader_with_ctx<R: std::io::Read + std::io::Seek>(reader: &mut Reader<R>, ctx: Ctx) -> Result<Self, DekuError> {
let count = i32::from_reader_with_ctx(reader, ())? as usize;
let mut values = Vec::new();
for _ in 0..count {
Expand All @@ -56,7 +56,7 @@ pub struct Map<K, V> {
impl<'a, K, V, Ctx> DekuReader<'a, Ctx> for Map<K, V>
where K: DekuReader<'a, Ctx>, V: DekuReader<'a, Ctx>, Ctx: Clone
{
fn from_reader_with_ctx<R: deku::no_std_io::Read + deku::no_std_io::Seek>(reader: &mut Reader<R>, ctx: Ctx) -> Result<Self, DekuError> {
fn from_reader_with_ctx<R: std::io::Read + std::io::Seek>(reader: &mut Reader<R>, ctx: Ctx) -> Result<Self, DekuError> {
let count = i32::from_reader_with_ctx(reader, ())?;
let mut keys = Vec::new();
let mut values = Vec::new();
Expand Down Expand Up @@ -199,7 +199,7 @@ pub struct Matrix4x4 {
pub e3: Vec4,
}

fn unpack_i32s<R: deku::no_std_io::Read + deku::no_std_io::Seek>(reader: &mut Reader<R>, num_items: usize, bit_size: usize) -> Result<Vec<i32>, DekuError> {
fn unpack_i32s<R: std::io::Read + std::io::Seek>(reader: &mut Reader<R>, num_items: usize, bit_size: usize) -> Result<Vec<i32>, DekuError> {
let mut result = Vec::new();
for _ in 0..num_items {
let value = i32::from_reader_with_ctx(reader, BitSize(bit_size))?;
Expand All @@ -220,7 +220,7 @@ impl From<Packedi32Vec> for Vec<i32> {
}

impl<'a, Ctx> DekuReader<'a, Ctx> for Packedi32Vec where Ctx: Clone {
fn from_reader_with_ctx<R: deku::no_std_io::Read + deku::no_std_io::Seek>(reader: &mut Reader<R>, _ctx: Ctx) -> Result<Self, DekuError> {
fn from_reader_with_ctx<R: std::io::Read + std::io::Seek>(reader: &mut Reader<R>, _ctx: Ctx) -> Result<Self, DekuError> {
let num_items = u32::from_reader_with_ctx(reader, ())? as usize;
let byte_array_count = u32::from_reader_with_ctx(reader, ())? as usize;
reader.seek(SeekFrom::Current(byte_array_count as i64)).unwrap();
Expand Down Expand Up @@ -248,7 +248,7 @@ impl From<Packedf32Vec> for Vec<f32> {
}

impl<'a, Ctx> DekuReader<'a, Ctx> for Packedf32Vec where Ctx: Clone {
fn from_reader_with_ctx<R: deku::no_std_io::Read + deku::no_std_io::Seek>(reader: &mut Reader<R>, _ctx: Ctx) -> Result<Self, DekuError> {
fn from_reader_with_ctx<R: std::io::Read + std::io::Seek>(reader: &mut Reader<R>, _ctx: Ctx) -> Result<Self, DekuError> {
let num_items = u32::from_reader_with_ctx(reader, ())?;
let scale = f32::from_reader_with_ctx(reader, ())?;
let start = f32::from_reader_with_ctx(reader, ())?;
Expand Down
2 changes: 1 addition & 1 deletion rust/src/unity/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use deku::prelude::*;
use std::fmt::Debug;

pub fn deku_peek<'a, T, R: deku::no_std_io::Read + deku::no_std_io::Seek>(reader: &mut Reader<R>, msg: &str) -> Result<T, DekuError>
pub fn deku_peek<'a, T, R: std::io::Read + std::io::Seek>(reader: &mut Reader<R>, msg: &str) -> Result<T, DekuError>
where for<'b> T: DekuReader<'b, ()> + Debug
{
println!("deku_peek - {}", msg);
Expand Down
12 changes: 6 additions & 6 deletions rust/src/wow/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn from_u32<T>(v: u32) -> Result<T, DekuError>
T::from_reader_with_ctx(&mut reader, ())
}

fn read_field_to_u32<R: deku::no_std_io::Read + deku::no_std_io::Seek>(reader: &mut Reader<R>, field_offset_bits: usize, field_size_bits: usize) -> Result<u32, DekuError> {
fn read_field_to_u32<R: std::io::Read + std::io::Seek>(reader: &mut Reader<R>, field_offset_bits: usize, field_size_bits: usize) -> Result<u32, DekuError> {
// Assumes the reader points to the start of the record
let old = reader.seek(std::io::SeekFrom::Current(0))
.map_err(|err| DekuError::Io(err.kind()))?;
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Wdc4Db2File {
}
}

pub fn read_vec<'a, T, R: deku::no_std_io::Read + deku::no_std_io::Seek>(&self, reader: &mut Reader<R>, field_number: usize) -> Result<Vec<T>, DekuError>
pub fn read_vec<'a, T, R: std::io::Read + std::io::Seek>(&self, reader: &mut Reader<R>, field_number: usize) -> Result<Vec<T>, DekuError>
where for<'b> T: DekuReader<'b, ()>
{
let field_offset = self.field_storage_info[field_number].field_offset_bits as usize;
Expand All @@ -196,7 +196,7 @@ impl Wdc4Db2File {
Ok(result)
}

pub fn read_string_helper<'a, R: deku::no_std_io::Read + deku::no_std_io::Seek>(&self, reader: &mut Reader<R>, string_offset: u32) -> Result<String, DekuError> {
pub fn read_string_helper<'a, R: std::io::Read + std::io::Seek>(&self, reader: &mut Reader<R>, string_offset: u32) -> Result<String, DekuError> {
let mut string = String::new();
let old = reader.seek(std::io::SeekFrom::Current(0))
.map_err(|err| DekuError::Io(err.kind()))?;
Expand All @@ -219,7 +219,7 @@ impl Wdc4Db2File {
Ok(string)
}

pub fn read_string_direct<'a, R: deku::no_std_io::Read + deku::no_std_io::Seek>(&self, reader: &mut Reader<R>, field_number: usize, extra_offset: usize) -> Result<String, DekuError> {
pub fn read_string_direct<'a, R: std::io::Read + std::io::Seek>(&self, reader: &mut Reader<R>, field_number: usize, extra_offset: usize) -> Result<String, DekuError> {
let field_offset = (self.field_storage_info[field_number].field_offset_bits as usize) + (extra_offset * 8);
let old = reader.seek(std::io::SeekFrom::Current(0))
.map_err(|err| DekuError::Io(err.kind()))?;
Expand All @@ -231,12 +231,12 @@ impl Wdc4Db2File {
v
}

pub fn read_string<'a, R: deku::no_std_io::Read + deku::no_std_io::Seek>(&self, reader: &mut Reader<R>, field_number: usize) -> Result<String, DekuError> {
pub fn read_string<'a, R: std::io::Read + std::io::Seek>(&self, reader: &mut Reader<R>, field_number: usize) -> Result<String, DekuError> {
let string_offset = self.read_field::<u32, R>(reader, field_number)?;
self.read_string_helper(reader, string_offset)
}

pub fn read_field<'a, T, R: deku::no_std_io::Read + deku::no_std_io::Seek>(&self, reader: &mut Reader<R>, field_number: usize) -> Result<T, DekuError>
pub fn read_field<'a, T, R: std::io::Read + std::io::Seek>(&self, reader: &mut Reader<R>, field_number: usize) -> Result<T, DekuError>
where for<'b> T: DekuReader<'b, ()>
{
let field_offset = self.field_storage_info[field_number].field_offset_bits as usize;
Expand Down

0 comments on commit 1059205

Please sign in to comment.