Skip to content

Commit acc0815

Browse files
authored
Merge pull request #47 from LebedevRI/develop
Extract fixed_length_load crate
2 parents 9b78d15 + a193ab2 commit acc0815

File tree

12 files changed

+111
-38
lines changed

12 files changed

+111
-38
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"src/memory/bitstreamcache",
1111
"src/memory/bitstreamer",
1212
"src/memory/variable_length_load",
13+
"src/memory/fixed_length_load",
1314
"src/memory/bytevacuumer",
1415
"src/memory/bytestreamer",
1516
"src/misc/md5",

src/codecs/packed/decoder/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ rawspeed-memory-bitstreamcache = { path = "../../../memory/bitstreamcache" }
1919
rawspeed-memory-bitstreamer = { path = "../../../memory/bitstreamer" }
2020
rawspeed-memory-endianness = { path = "../../../memory/endianness" }
2121
rawspeed-memory-variable_length_load = { path = "../../../memory/variable_length_load" }
22+
rawspeed-memory-fixed_length_load = { path = "../../../memory/fixed_length_load" }
2223
rawspeed-std = { path = "../../../std" }
2324
rawspeed-std-ndslice = { path = "../../../std/ndslice" }
2425

src/codecs/packed/decoder/packed_decoder/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use rawspeed_common::bit_transmutation::CopyFromSlice;
21
use rawspeed_common::bit_transmutation::FromNeBytes;
3-
use rawspeed_common::bit_transmutation::LoadFromSlice;
42
use rawspeed_common::common::Bitwidth;
53
use rawspeed_memory_bitstream::bitstream;
64
use rawspeed_memory_bitstream::bitstream::BitOrder;
@@ -11,6 +9,8 @@ use rawspeed_memory_bitstreamer::bitstreamer::BitStreamerBase;
119
use rawspeed_memory_bitstreamer::bitstreamer::BitStreamerCacheFillImpl;
1210
use rawspeed_memory_bitstreamer::bitstreamer::BitStreamerTraits;
1311
use rawspeed_memory_endianness::endianness::SwapBytes;
12+
use rawspeed_memory_fixed_length_load::fixed_length_load::CopyFromSlice;
13+
use rawspeed_memory_fixed_length_load::fixed_length_load::LoadFromSlice;
1414
use rawspeed_memory_variable_length_load::variable_length_load::VariableLengthLoad;
1515
use rawspeed_std::coord_common::RowIndex;
1616
use rawspeed_std_ndslice::array2dref::Array2DRef;

src/common/bit_transmutation/mod.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -94,38 +94,6 @@ impl_to_ne_bytes!(u16);
9494
impl_to_ne_bytes!(u32);
9595
impl_to_ne_bytes!(u64);
9696

97-
pub trait CopyFromSlice {
98-
fn copy_from_slice_(&mut self, src: &[u8]);
99-
}
100-
101-
impl CopyFromSlice for [u8] {
102-
#[inline]
103-
fn copy_from_slice_(&mut self, src: &[u8]) {
104-
self.copy_from_slice(src);
105-
}
106-
}
107-
108-
pub trait LoadFromSlice<T>
109-
where
110-
T: Default + core::ops::IndexMut<core::ops::RangeFull>,
111-
<T as core::ops::Index<core::ops::RangeFull>>::Output: CopyFromSlice,
112-
{
113-
fn load_from_slice(&self) -> T;
114-
}
115-
116-
impl<T> LoadFromSlice<T> for [u8]
117-
where
118-
T: Default + core::ops::IndexMut<core::ops::RangeFull>,
119-
<T as core::ops::Index<core::ops::RangeFull>>::Output: CopyFromSlice,
120-
{
121-
#[inline]
122-
fn load_from_slice(&self) -> T {
123-
let mut out: T = Default::default();
124-
out[..].copy_from_slice_(self);
125-
out
126-
}
127-
}
128-
12997
pub trait FromNeBytes {
13098
type Output;
13199

src/memory/bitstreamer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rawspeed-memory-bitstream = { path = "../bitstream" }
1818
rawspeed-memory-endianness = { path = "../endianness" }
1919
rawspeed-memory-bitstreamcache = { path = "../bitstreamcache" }
2020
rawspeed-memory-variable_length_load = { path = "../variable_length_load" }
21+
rawspeed-memory-fixed_length_load = { path = "../fixed_length_load" }
2122

2223
[lib]
2324
path = "mod.rs"

src/memory/bitstreamer/bitstreamer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use core::marker::PhantomData;
22
use core::ops::RangeFull;
3-
use rawspeed_common::bit_transmutation::CopyFromSlice;
43
use rawspeed_common::bit_transmutation::FromNeBytes;
5-
use rawspeed_common::bit_transmutation::LoadFromSlice;
64
use rawspeed_common::common::Bitwidth;
75
use rawspeed_memory_bitstream::bitstream::BitOrder;
86
use rawspeed_memory_bitstream::bitstream::BitOrderTrait;
97
use rawspeed_memory_bitstream::bitstream::BitStreamTraits;
108
use rawspeed_memory_bitstreamcache::bitstreamcache::BitStreamCache;
119
use rawspeed_memory_endianness::endianness::SwapBytes;
1210
use rawspeed_memory_endianness::endianness::get_host_endianness;
11+
use rawspeed_memory_fixed_length_load::fixed_length_load::CopyFromSlice;
12+
use rawspeed_memory_fixed_length_load::fixed_length_load::LoadFromSlice;
1313
use rawspeed_memory_variable_length_load::variable_length_load::VariableLengthLoad;
1414

1515
pub trait BitStreamerTraits {

src/memory/bytestreamer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ workspace = true
1414

1515
[dependencies]
1616
rawspeed-memory-endianness = { path = "../endianness" }
17+
rawspeed-memory-fixed_length_load = { path = "../fixed_length_load" }
1718
rawspeed-common = { path = "../../common" }
1819

1920
[lib]

src/memory/bytestreamer/bytestreamer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use rawspeed_common::bit_transmutation::CopyFromSlice;
21
use rawspeed_common::bit_transmutation::FromBits;
32
use rawspeed_common::bit_transmutation::FromNeBytes;
4-
use rawspeed_common::bit_transmutation::LoadFromSlice;
53
use rawspeed_common::bit_transmutation::ToBits;
64
use rawspeed_common::bit_transmutation::ToNeBytes;
75
use rawspeed_memory_endianness::endianness::Endianness;
86
use rawspeed_memory_endianness::endianness::SwapBytes;
97
use rawspeed_memory_endianness::endianness::get_host_endianness;
8+
use rawspeed_memory_fixed_length_load::fixed_length_load::CopyFromSlice;
9+
use rawspeed_memory_fixed_length_load::fixed_length_load::LoadFromSlice;
1010

1111
pub struct ByteStreamer<'a> {
1212
slice: &'a [u8],
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "rawspeed-memory-fixed_length_load"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
rust-version.workspace = true
7+
documentation.workspace = true
8+
homepage.workspace = true
9+
repository.workspace = true
10+
license.workspace = true
11+
12+
[lints]
13+
workspace = true
14+
15+
[dependencies]
16+
17+
[lib]
18+
path = "mod.rs"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pub trait CopyFromSlice {
2+
fn copy_from_slice_(&mut self, src: &[u8]);
3+
}
4+
5+
impl CopyFromSlice for [u8] {
6+
#[inline]
7+
fn copy_from_slice_(&mut self, src: &[u8]) {
8+
self.copy_from_slice(src);
9+
}
10+
}
11+
12+
pub trait LoadFromSlice<T>
13+
where
14+
T: Default + core::ops::IndexMut<core::ops::RangeFull>,
15+
<T as core::ops::Index<core::ops::RangeFull>>::Output: CopyFromSlice,
16+
{
17+
fn load_from_slice(&self) -> T;
18+
}
19+
20+
impl<T> LoadFromSlice<T> for [u8]
21+
where
22+
T: Default + core::ops::IndexMut<core::ops::RangeFull>,
23+
<T as core::ops::Index<core::ops::RangeFull>>::Output: CopyFromSlice,
24+
{
25+
#[inline]
26+
fn load_from_slice(&self) -> T {
27+
let mut out: T = Default::default();
28+
out[..].copy_from_slice_(self);
29+
out
30+
}
31+
}
32+
33+
#[cfg(test)]
34+
mod tests;

0 commit comments

Comments
 (0)