11use bytemuck:: { Pod , cast_slice} ;
22
3- use crate :: FastPForError ;
3+ use crate :: FastPForResult ;
44
55/// Internal default for max decompressed length. Used by trait defaults and C++ FFI.
66#[ inline]
@@ -23,13 +23,15 @@ pub(crate) fn default_max_decoded_len(compressed_words: usize) -> usize {
2323///
2424/// # Implementing this trait
2525///
26- /// ```rust,ignore
26+ /// ```
27+ /// # use fastpfor::{BlockCodec, FastPForResult};
28+ /// struct MyCodec;
2729/// impl BlockCodec for MyCodec {
2830/// type Block = [u32; 256];
29- /// fn encode_blocks(&self, blocks: &[[u32; 256]], out: &mut Vec<u32>)
30- /// -> Result <(), FastPForError > { ... }
31- /// fn decode_blocks(&self, input: &[u32], expected_len: Option<u32>,
32- /// out: &mut Vec<u32>) -> Result <usize, FastPForError > { ... }
31+ /// fn encode_blocks(&mut self, blocks: &[[u32; 256]], out: &mut Vec<u32>)
32+ /// -> FastPForResult <()> { todo!() }
33+ /// fn decode_blocks(&mut self, input: &[u32], expected_len: Option<u32>,
34+ /// out: &mut Vec<u32>) -> FastPForResult <usize> { todo!() }
3335/// }
3436/// ```
3537pub trait BlockCodec {
@@ -54,11 +56,7 @@ pub trait BlockCodec {
5456 ///
5557 /// No remainder is possible — the caller must split the input first using
5658 /// [`slice_to_blocks`] and handle any remainder separately.
57- fn encode_blocks (
58- & mut self ,
59- blocks : & [ Self :: Block ] ,
60- out : & mut Vec < u32 > ,
61- ) -> Result < ( ) , FastPForError > ;
59+ fn encode_blocks ( & mut self , blocks : & [ Self :: Block ] , out : & mut Vec < u32 > ) -> FastPForResult < ( ) > ;
6260
6361 /// Decompress blocks from `input`, using the length stored in the header.
6462 ///
@@ -75,7 +73,7 @@ pub trait BlockCodec {
7573 input : & [ u32 ] ,
7674 expected_len : Option < u32 > ,
7775 out : & mut Vec < u32 > ,
78- ) -> Result < usize , FastPForError > ;
76+ ) -> FastPForResult < usize > ;
7977
8078 /// Maximum decompressed element count for a given compressed input length.
8179 /// Reject `expected_len` values exceeding this to avoid allocation from bad data.
@@ -100,9 +98,9 @@ pub trait BlockCodec {
10098#[ cfg( feature = "cpp" ) ]
10199pub trait BlockCodec64 {
102100 /// Compress 64-bit integers into a 32-bit word stream.
103- fn encode64 ( & mut self , input : & [ u64 ] , out : & mut Vec < u32 > ) -> Result < ( ) , FastPForError > ;
101+ fn encode64 ( & mut self , input : & [ u64 ] , out : & mut Vec < u32 > ) -> FastPForResult < ( ) > ;
104102 /// Decompress 64-bit integers from a 32-bit word stream.
105- fn decode64 ( & mut self , input : & [ u32 ] , out : & mut Vec < u64 > ) -> Result < ( ) , FastPForError > ;
103+ fn decode64 ( & mut self , input : & [ u32 ] , out : & mut Vec < u64 > ) -> FastPForResult < ( ) > ;
106104}
107105
108106/// Compresses and decompresses an arbitrary-length `&[u32]` slice.
@@ -113,7 +111,7 @@ pub trait BlockCodec64 {
113111/// to produce an `AnyLenCodec`.
114112pub trait AnyLenCodec {
115113 /// Compress an arbitrary-length slice of `u32` values.
116- fn encode ( & mut self , input : & [ u32 ] , out : & mut Vec < u32 > ) -> Result < ( ) , FastPForError > ;
114+ fn encode ( & mut self , input : & [ u32 ] , out : & mut Vec < u32 > ) -> FastPForResult < ( ) > ;
117115
118116 /// Maximum decompressed element count for a given compressed input length.
119117 /// Reject `expected_len` values exceeding this to avoid allocation from bad data.
@@ -140,7 +138,7 @@ pub trait AnyLenCodec {
140138 input : & [ u32 ] ,
141139 out : & mut Vec < u32 > ,
142140 expected_len : Option < u32 > ,
143- ) -> Result < ( ) , FastPForError > ;
141+ ) -> FastPForResult < ( ) > ;
144142}
145143
146144/// Split a flat `&[u32]` into `(&[Blocks::Block], &[u32])` without copying.
@@ -154,7 +152,8 @@ pub trait AnyLenCodec {
154152///
155153/// # Example
156154///
157- /// ```rust,ignore
155+ /// ```ignore
156+ /// # use fastpfor::{slice_to_blocks, FastPForBlock256};
158157/// let data: Vec<u32> = (0..600).collect(); // 2 × 256 + 88 remainder
159158/// let (blocks, remainder) = slice_to_blocks::<FastPForBlock256>(&data);
160159/// assert_eq!(blocks.len(), 2); // 2 blocks of [u32; 256]
0 commit comments