Skip to content

Commit be1f4b5

Browse files
committed
Remove From<winnow> for (small) step towards stable API
1 parent 62f7bc6 commit be1f4b5

File tree

6 files changed

+35
-21
lines changed

6 files changed

+35
-21
lines changed

gix-object/src/commit/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mod write;
5959
impl<'a> CommitRef<'a> {
6060
/// Deserialize a commit from the given `data` bytes while avoiding most allocations.
6161
pub fn from_bytes(mut data: &'a [u8]) -> Result<CommitRef<'a>, crate::decode::Error> {
62-
decode::commit(&mut data).map_err(crate::decode::Error::from)
62+
decode::commit(&mut data).map_err(crate::decode::Error::with_err)
6363
}
6464
}
6565

gix-object/src/commit/ref_iter.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,15 @@ fn missing_field() -> crate::decode::Error {
151151
}
152152

153153
impl<'a> CommitRefIter<'a> {
154-
fn next_inner(mut i: &'a [u8], state: &mut State) -> Result<(&'a [u8], Token<'a>), crate::decode::Error> {
154+
#[inline]
155+
fn next_inner(i: &'a [u8], state: &mut State) -> Result<(&'a [u8], Token<'a>), crate::decode::Error> {
156+
Self::next_inner_(i, state).map_err(crate::decode::Error::with_err)
157+
}
158+
159+
fn next_inner_(
160+
mut i: &'a [u8],
161+
state: &mut State,
162+
) -> Result<(&'a [u8], Token<'a>), winnow::error::ErrMode<crate::decode::ParseError>> {
155163
use State::*;
156164
Ok(match state {
157165
Tree => {
@@ -181,7 +189,7 @@ impl<'a> CommitRefIter<'a> {
181189
*state = State::Signature {
182190
of: SignatureKind::Author,
183191
};
184-
return Self::next_inner(i, state);
192+
return Self::next_inner_(i, state);
185193
}
186194
}
187195
}
@@ -215,7 +223,7 @@ impl<'a> CommitRefIter<'a> {
215223
*state = State::ExtraHeaders;
216224
match encoding {
217225
Some(encoding) => (i, Token::Encoding(encoding.as_bstr())),
218-
None => return Self::next_inner(i, state),
226+
None => return Self::next_inner_(i, state),
219227
}
220228
}
221229
ExtraHeaders => {
@@ -232,7 +240,7 @@ impl<'a> CommitRefIter<'a> {
232240
Some(extra_header) => (i, Token::ExtraHeader(extra_header)),
233241
None => {
234242
*state = State::Message;
235-
return Self::next_inner(i, state);
243+
return Self::next_inner_(i, state);
236244
}
237245
}
238246
}

gix-object/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ pub mod decode {
274274
pub inner: ParseError,
275275
}
276276

277-
impl From<winnow::error::ErrMode<ParseError>> for Error {
278-
fn from(v: winnow::error::ErrMode<ParseError>) -> Self {
279-
Error {
280-
inner: v.into_inner().expect("we don't have streaming parsers"),
277+
impl Error {
278+
pub(crate) fn with_err(err: winnow::error::ErrMode<ParseError>) -> Self {
279+
Self {
280+
inner: err.into_inner().expect("we don't have streaming parsers"),
281281
}
282282
}
283283
}
@@ -306,10 +306,10 @@ pub mod decode {
306306
pub inner: ParseError,
307307
}
308308

309-
impl From<winnow::error::ErrMode<ParseError>> for Error {
310-
fn from(v: winnow::error::ErrMode<ParseError>) -> Self {
311-
Error {
312-
inner: v.into_inner().expect("we don't have streaming parsers"),
309+
impl Error {
310+
pub(crate) fn with_err(err: winnow::error::ErrMode<ParseError>) -> Self {
311+
Self {
312+
inner: err.into_inner().expect("we don't have streaming parsers"),
313313
}
314314
}
315315
}

gix-object/src/tag/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub mod ref_iter;
1111
impl<'a> TagRef<'a> {
1212
/// Deserialize a tag from `data`.
1313
pub fn from_bytes(mut data: &'a [u8]) -> Result<TagRef<'a>, crate::decode::Error> {
14-
decode::git_tag(&mut data).map_err(crate::decode::Error::from)
14+
decode::git_tag(&mut data).map_err(crate::decode::Error::with_err)
1515
}
1616
/// The object this tag points to as `Id`.
1717
pub fn target(&self) -> gix_hash::ObjectId {

gix-object/src/tag/ref_iter.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ fn missing_field() -> crate::decode::Error {
6060
}
6161

6262
impl<'a> TagRefIter<'a> {
63-
fn next_inner(mut i: &'a [u8], state: &mut State) -> Result<(&'a [u8], Token<'a>), crate::decode::Error> {
63+
#[inline]
64+
fn next_inner(i: &'a [u8], state: &mut State) -> Result<(&'a [u8], Token<'a>), crate::decode::Error> {
65+
Self::next_inner_(i, state).map_err(crate::decode::Error::with_err)
66+
}
67+
68+
fn next_inner_(
69+
mut i: &'a [u8],
70+
state: &mut State,
71+
) -> Result<(&'a [u8], Token<'a>), winnow::error::ErrMode<crate::decode::ParseError>> {
6472
use State::*;
6573
Ok(match state {
6674
Target => {

gix-object/src/tree/ref_iter.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl<'a> TreeRefIter<'a> {
1515
impl<'a> TreeRef<'a> {
1616
/// Deserialize a Tree from `data`.
1717
pub fn from_bytes(mut data: &'a [u8]) -> Result<TreeRef<'a>, crate::decode::Error> {
18-
decode::tree(&mut data).map_err(crate::decode::Error::from)
18+
decode::tree(&mut data).map_err(crate::decode::Error::with_err)
1919
}
2020

2121
/// Find an entry named `name` knowing if the entry is a directory or not, using a binary search.
@@ -70,11 +70,9 @@ impl<'a> Iterator for TreeRefIter<'a> {
7070
self.data = &[];
7171
let empty = &[] as &[u8];
7272
#[allow(clippy::unit_arg)]
73-
Some(Err(winnow::error::ErrMode::from_error_kind(
74-
&empty,
75-
winnow::error::ErrorKind::Verify,
76-
)
77-
.into()))
73+
Some(Err(crate::decode::Error::with_err(
74+
winnow::error::ErrMode::from_error_kind(&empty, winnow::error::ErrorKind::Verify),
75+
)))
7876
}
7977
}
8078
}

0 commit comments

Comments
 (0)