History

Refactor gix-object parsers to look more winnow-ish

Ed Page committed 3 years ago

Commit f633f9e1 parent 72274103 files · +13 −3Browse files

Unified · Split

3 files
  1. gix-object/src/commit/mod.rs +4 −1
  2. gix-object/src/tag/mod.rs +5 −1
  3. gix-object/src/tree/ref_iter.rs +4 −1
gix-object/src/commit/mod.rs+4−1
@@ -1,6 +1,7 @@
1use std::ops::Range;1use std::ops::Range;
2 2
3use bstr::{BStr, BString, ByteSlice};3use bstr::{BStr, BString, ByteSlice};
4use winnow::prelude::*;
4 5
5use crate::{Commit, CommitRef, TagRef};6use crate::{Commit, CommitRef, TagRef};
6 7
@@ -60,7 +61,9 @@ mod write; · 53 unmodified lines
60impl<'a> CommitRef<'a> {61impl<'a> CommitRef<'a> {
61 /// Deserialize a commit from the given `data` bytes while avoiding most allocations.62 /// Deserialize a commit from the given `data` bytes while avoiding most allocations.
62 pub fn from_bytes(mut data: &'a [u8]) -> Result<CommitRef<'a>, crate::decode::Error> {63 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)
64 }67 }
65}68}
66 69
gix-object/src/tag/mod.rs+5−1
@@ -1,3 +1,5 @@
1use winnow::prelude::*;
2
1use crate::TagRef;3use crate::TagRef;
2 4
3mod decode;5mod decode;
@@ -11,7 +13,9 @@ pub mod ref_iter; · 7 unmodified lines
11impl<'a> TagRef<'a> {13impl<'a> TagRef<'a> {
12 /// Deserialize a tag from `data`.14 /// Deserialize a tag from `data`.
13 pub fn from_bytes(mut data: &'a [u8]) -> Result<TagRef<'a>, crate::decode::Error> {15 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)
15 }19 }
16 /// The object this tag points to as `Id`.20 /// The object this tag points to as `Id`.
17 pub fn target(&self) -> gix_hash::ObjectId {21 pub fn target(&self) -> gix_hash::ObjectId {
gix-object/src/tree/ref_iter.rs+4−1
@@ -2,6 +2,7 @@ use std::convert::TryFrom; · 1 unmodified line
2 2
3use bstr::BStr;3use bstr::BStr;
4use winnow::error::ParserError;4use winnow::error::ParserError;
5use winnow::prelude::*;
5 6
6use crate::{tree, tree::EntryRef, TreeRef, TreeRefIter};7use crate::{tree, tree::EntryRef, TreeRef, TreeRefIter};
7 8
@@ -15,7 +16,9 @@ impl<'a> TreeRefIter<'a> { · 7 unmodified lines
15impl<'a> TreeRef<'a> {16impl<'a> TreeRef<'a> {
16 /// Deserialize a Tree from `data`.17 /// Deserialize a Tree from `data`.
17 pub fn from_bytes(mut data: &'a [u8]) -> Result<TreeRef<'a>, crate::decode::Error> {18 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)
19 }22 }
20 23
21 /// Find an entry named `name` knowing if the entry is a directory or not, using a binary search.24 /// Find an entry named `name` knowing if the entry is a directory or not, using a binary search.