Skip to content

Commit 2f8c881

Browse files
authored
Merge pull request #78 from orbitinghail/feat/remove-culprit
remove culprit
2 parents 944fec0 + af5fb02 commit 2f8c881

File tree

9 files changed

+18
-47
lines changed

9 files changed

+18
-47
lines changed

Cargo.lock

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ assert_matches = "1.5.0"
2323
bitvec = "1.0.1"
2424
bytes = "1.10"
2525
crc64fast-nvme = "1.2.0"
26-
culprit = "0.4"
2726
either = "1.15"
2827
itertools = "0.14"
2928
num = "0.4"

src/codec.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use bytes::{BufMut, Bytes, BytesMut};
2-
use culprit::Culprit;
32
use thiserror::Error;
43
use zerocopy::{ConvertError, SizeError};
54

@@ -94,9 +93,9 @@ pub enum DecodeErr {
9493

9594
impl DecodeErr {
9695
#[inline]
97-
fn ensure_bytes_available(data: &[u8], len: usize) -> culprit::Result<(), DecodeErr> {
96+
fn ensure_bytes_available(data: &[u8], len: usize) -> Result<(), DecodeErr> {
9897
if data.len() < len {
99-
Err(Culprit::new(Self::Length))
98+
Err(Self::Length)
10099
} else {
101100
Ok(())
102101
}

src/codec/partition_ref.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use bitvec::{order::Lsb0, slice::BitSlice};
2-
use culprit::ResultExt;
32
use either::Either;
43
use num::traits::{AsPrimitive, Bounded};
54
use zerocopy::{FromBytes, TryFromBytes};
@@ -14,9 +13,7 @@ use crate::{
1413
util::{RangeExt, RangeIter},
1514
};
1615

17-
pub(super) fn decode_len_from_suffix<L: Level>(
18-
data: &[u8],
19-
) -> culprit::Result<(&[u8], usize), DecodeErr> {
16+
pub(super) fn decode_len_from_suffix<L: Level>(data: &[u8]) -> Result<(&[u8], usize), DecodeErr> {
2017
let (data, len) = L::ValueUnaligned::try_read_from_suffix(data)?;
2118
// length is decremented when stored
2219
Ok((data, len.into().as_() + 1))
@@ -33,10 +30,7 @@ pub enum NonRecursivePartitionRef<'a, L: Level> {
3330
}
3431

3532
impl<'a, L: Level> NonRecursivePartitionRef<'a, L> {
36-
pub fn from_suffix_with_kind(
37-
kind: PartitionKind,
38-
data: &'a [u8],
39-
) -> culprit::Result<Self, DecodeErr> {
33+
pub fn from_suffix_with_kind(kind: PartitionKind, data: &'a [u8]) -> Result<Self, DecodeErr> {
4034
match kind {
4135
PartitionKind::Empty => Ok(Self::Empty),
4236
PartitionKind::Full => Ok(Self::Full),
@@ -57,9 +51,7 @@ impl<'a, L: Level> NonRecursivePartitionRef<'a, L> {
5751
values: <[L::ValueUnaligned]>::ref_from_bytes_with_elems(&data[range], len)?,
5852
})
5953
}
60-
PartitionKind::Run => Ok(Self::Run {
61-
runs: RunsRef::from_suffix(data).or_into_ctx()?,
62-
}),
54+
PartitionKind::Run => Ok(Self::Run { runs: RunsRef::from_suffix(data)? }),
6355
PartitionKind::Tree => unreachable!("non-recursive"),
6456
}
6557
}
@@ -81,7 +73,7 @@ impl<'a> NonRecursivePartitionRef<'a, Block> {
8173
kind: PartitionKind,
8274
num_children: usize,
8375
data: &'a [u8],
84-
) -> culprit::Result<Self, DecodeErr> {
76+
) -> Result<Self, DecodeErr> {
8577
match kind {
8678
PartitionKind::Full => Ok(Self::Full),
8779
PartitionKind::Bitmap => {
@@ -326,12 +318,12 @@ pub enum PartitionRef<'a, L: Level> {
326318
}
327319

328320
impl<'a, L: Level> PartitionRef<'a, L> {
329-
pub fn from_suffix(data: &'a [u8]) -> culprit::Result<Self, DecodeErr> {
321+
pub fn from_suffix(data: &'a [u8]) -> Result<Self, DecodeErr> {
330322
let (data, kind) = PartitionKind::try_read_from_suffix(data)?;
331323
match kind {
332-
PartitionKind::Tree => Ok(Self::Tree(TreeRef::from_suffix(data).or_into_ctx()?)),
324+
PartitionKind::Tree => Ok(Self::Tree(TreeRef::from_suffix(data)?)),
333325
kind => Ok(Self::NonRecursive(
334-
NonRecursivePartitionRef::from_suffix_with_kind(kind, data).or_into_ctx()?,
326+
NonRecursivePartitionRef::from_suffix_with_kind(kind, data)?,
335327
)),
336328
}
337329
}

src/codec/runs_ref.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{iter::FusedIterator, ops::RangeInclusive};
22

3-
use culprit::ResultExt;
43
use range_set_blaze::{SortedDisjoint, SortedStarts};
54
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, Unaligned};
65

@@ -18,8 +17,8 @@ pub struct RunsRef<'a, L: Level> {
1817
}
1918

2019
impl<'a, L: Level> RunsRef<'a, L> {
21-
pub(super) fn from_suffix(data: &'a [u8]) -> culprit::Result<Self, DecodeErr> {
22-
let (data, runs) = decode_len_from_suffix::<L>(data).or_into_ctx()?;
20+
pub(super) fn from_suffix(data: &'a [u8]) -> Result<Self, DecodeErr> {
21+
let (data, runs) = decode_len_from_suffix::<L>(data)?;
2322
let bytes = runs * size_of::<L::ValueUnaligned>() * 2;
2423
DecodeErr::ensure_bytes_available(data, bytes)?;
2524
let range = (data.len() - bytes)..data.len();

src/codec/tree_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct TreeRef<'a, L: Level> {
2626
}
2727

2828
impl<'a, L: Level> TreeRef<'a, L> {
29-
pub(super) fn from_suffix(data: &'a [u8]) -> culprit::Result<Self, DecodeErr> {
29+
pub(super) fn from_suffix(data: &'a [u8]) -> Result<Self, DecodeErr> {
3030
let (data, num_children) = decode_len_from_suffix::<Block>(data)?;
3131
assert_ne!(
3232
num_children, 0,

src/cow.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::ops::{
55
};
66

77
use bytes::{BufMut, Bytes};
8-
use culprit::Culprit;
98
use either::Either;
109

1110
use crate::{
@@ -185,7 +184,7 @@ impl<B: Deref<Target = [u8]>> CowSplinter<B> {
185184
/// let cow = CowSplinter::from_bytes(bytes).unwrap();
186185
/// assert!(cow.contains(42));
187186
/// ```
188-
pub fn from_bytes(data: B) -> Result<Self, Culprit<DecodeErr>> {
187+
pub fn from_bytes(data: B) -> Result<Self, DecodeErr> {
189188
Ok(Self::Ref(SplinterRef::from_bytes(data)?))
190189
}
191190

src/splinter_ref.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{
44
};
55

66
use bytes::Bytes;
7-
use culprit::Culprit;
87
use zerocopy::FromBytes;
98

109
use crate::{
@@ -239,19 +238,19 @@ impl<B: Deref<Target = [u8]>> SplinterRef<B> {
239238
///
240239
/// let invalid_bytes = vec![0u8; 5]; // Too short
241240
/// let result = SplinterRef::from_bytes(invalid_bytes);
242-
/// assert!(matches!(result.unwrap_err().ctx(), DecodeErr::Length));
241+
/// assert!(matches!(result.unwrap_err(), DecodeErr::Length));
243242
/// ```
244-
pub fn from_bytes(data: B) -> culprit::Result<Self, DecodeErr> {
243+
pub fn from_bytes(data: B) -> Result<Self, DecodeErr> {
245244
pub(crate) const SPLINTER_V1_MAGIC: [u8; 4] = [0xDA, 0xAE, 0x12, 0xDF];
246245
if data.len() >= 4
247246
&& data.starts_with(&SPLINTER_V1_MAGIC)
248247
&& !data.ends_with(&SPLINTER_V2_MAGIC)
249248
{
250-
return Err(Culprit::new(DecodeErr::SplinterV1));
249+
return Err(DecodeErr::SplinterV1);
251250
}
252251

253252
if data.len() < Footer::SIZE {
254-
return Err(Culprit::new(DecodeErr::Length));
253+
return Err(DecodeErr::Length);
255254
}
256255
let (partitions, footer) = data.split_at(data.len() - Footer::SIZE);
257256
Footer::ref_from_bytes(footer)?.validate(partitions)?;

src/testutil.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ pub fn mksplinter_buf(values: &[u32]) -> BytesMut {
378378
#[macro_export]
379379
macro_rules! assert_error {
380380
($expr:expr, $err:path$(, $($rest:tt),+)?) => {
381-
assert_matches::assert_matches!(($expr).expect_err("expected an error").ctx(), $err $(, $($rest),+)?)
381+
assert_matches::assert_matches!(($expr).expect_err("expected an error"), $err $(, $($rest),+)?)
382382
};
383383
}
384384

0 commit comments

Comments
 (0)