Skip to content

Commit b77c8a6

Browse files
committed
Overhaul error reporting
This PR overhauls error reporting, replacing our `Option` returns with `Result`s. The `Err` type of these results provide both the cause of the failure, and access to the underlying source of the conversion. Makes progress towards #1139.
1 parent dd7dc7d commit b77c8a6

File tree

8 files changed

+906
-284
lines changed

8 files changed

+906
-284
lines changed

src/byteorder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
//!
5555
//! impl<B: SplitByteSlice> UdpPacket<B> {
5656
//! fn parse(bytes: B) -> Option<UdpPacket<B>> {
57-
//! let (header, body) = Ref::new_from_prefix(bytes)?;
57+
//! let (header, body) = Ref::new_from_prefix(bytes).ok()?;
5858
//! Some(UdpPacket { header, body })
5959
//! }
6060
//!

src/deprecated.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ where
2121
#[doc(hidden)]
2222
#[inline]
2323
pub fn new_slice(bytes: B) -> Option<Ref<B, [T]>> {
24-
Self::new(bytes)
24+
Self::new(bytes).ok()
2525
}
2626
}
2727

@@ -34,7 +34,7 @@ where
3434
#[doc(hidden)]
3535
#[inline(always)]
3636
pub fn new_slice_unaligned(bytes: B) -> Option<Ref<B, [T]>> {
37-
Ref::new_unaligned(bytes)
37+
Ref::new_unaligned(bytes).ok()
3838
}
3939
}
4040

@@ -74,15 +74,15 @@ where
7474
#[doc(hidden)]
7575
#[inline]
7676
pub fn new_slice_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> {
77-
Ref::with_trailing_elements_from_prefix(bytes, count)
77+
Ref::with_trailing_elements_from_prefix(bytes, count).ok()
7878
}
7979

8080
#[deprecated(since = "0.8.0", note = "replaced by `Ref::with_trailing_elements_from_suffix`")]
8181
#[must_use = "has no side effects"]
8282
#[doc(hidden)]
8383
#[inline]
8484
pub fn new_slice_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> {
85-
Ref::with_trailing_elements_from_suffix(bytes, count)
85+
Ref::with_trailing_elements_from_suffix(bytes, count).ok()
8686
}
8787
}
8888

@@ -99,7 +99,7 @@ where
9999
#[must_use = "has no side effects"]
100100
#[inline(always)]
101101
pub fn new_slice_unaligned_from_prefix(bytes: B, count: usize) -> Option<(Ref<B, [T]>, B)> {
102-
Ref::with_trailing_elements_unaligned_from_prefix(bytes, count)
102+
Ref::with_trailing_elements_unaligned_from_prefix(bytes, count).ok()
103103
}
104104

105105
#[deprecated(
@@ -110,6 +110,6 @@ where
110110
#[must_use = "has no side effects"]
111111
#[inline(always)]
112112
pub fn new_slice_unaligned_from_suffix(bytes: B, count: usize) -> Option<(B, Ref<B, [T]>)> {
113-
Ref::with_trailing_elements_unaligned_from_suffix(bytes, count)
113+
Ref::with_trailing_elements_unaligned_from_suffix(bytes, count).ok()
114114
}
115115
}

0 commit comments

Comments
 (0)