Skip to content

Commit f633f9e

Browse files
committed
Refactor gix-object parsers to look more winnow-ish
1 parent 7227410 commit f633f9e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

gix-object/src/commit/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ops::Range;
22

33
use bstr::{BStr, BString, ByteSlice};
4+
use winnow::prelude::*;
45

56
use crate::{Commit, CommitRef, TagRef};
67

@@ -60,7 +61,9 @@ mod write;
6061
impl<'a> CommitRef<'a> {
6162
/// Deserialize a commit from the given `data` bytes while avoiding most allocations.
6263
pub fn from_bytes(mut data: &'a [u8]) -> Result<CommitRef<'a>, crate::decode::Error> {
63-
decode::commit(&mut data).map_err(crate::decode::Error::with_err)
64+
decode::commit
65+
.parse_next(&mut data)
66+
.map_err(crate::decode::Error::with_err)
6467
}
6568
}
6669

gix-object/src/tag/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use winnow::prelude::*;
2+
13
use crate::TagRef;
24

35
mod decode;
@@ -11,7 +13,9 @@ pub mod ref_iter;
1113
impl<'a> TagRef<'a> {
1214
/// Deserialize a tag from `data`.
1315
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::with_err)
16+
decode::git_tag
17+
.parse_next(&mut data)
18+
.map_err(crate::decode::Error::with_err)
1519
}
1620
/// The object this tag points to as `Id`.
1721
pub fn target(&self) -> gix_hash::ObjectId {

gix-object/src/tree/ref_iter.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::convert::TryFrom;
22

33
use bstr::BStr;
44
use winnow::error::ParserError;
5+
use winnow::prelude::*;
56

67
use crate::{tree, tree::EntryRef, TreeRef, TreeRefIter};
78

@@ -15,7 +16,9 @@ impl<'a> TreeRefIter<'a> {
1516
impl<'a> TreeRef<'a> {
1617
/// Deserialize a Tree from `data`.
1718
pub fn from_bytes(mut data: &'a [u8]) -> Result<TreeRef<'a>, crate::decode::Error> {
18-
decode::tree(&mut data).map_err(crate::decode::Error::with_err)
19+
decode::tree
20+
.parse_next(&mut data)
21+
.map_err(crate::decode::Error::with_err)
1922
}
2023

2124
/// Find an entry named `name` knowing if the entry is a directory or not, using a binary search.

0 commit comments

Comments
 (0)