Skip to content

Commit fb287af

Browse files
committed
refactor
1 parent 4498dff commit fb287af

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

git-object/src/parsed/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ quick_error! {
3333
}
3434

3535
impl Error {
36-
pub fn parse_context(mut self, ctx: &'static str) -> Self{
36+
fn set_parse_context(mut self, ctx: &'static str) -> Self {
3737
match self {
3838
Error::Nom(_, ref mut message) => *message = ctx,
3939
_ => {}
4040
};
4141
self
4242
}
43+
44+
fn context(msg: &'static str) -> impl Fn(nom::Err<Self>) -> nom::Err<Self> {
45+
move |e: nom::Err<Self>| e.map(|e| e.set_parse_context(msg))
46+
}
4347
}
4448

4549
impl ParseError<&[u8]> for Error {

git-object/src/parsed/tag.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use crate::{parsed::Signature, Time};
66
use bstr::{BStr, ByteSlice};
77
use btoi::btoi;
88
use hex::FromHex;
9-
use nom::{bytes::complete::tag, IResult, };
10-
use nom::sequence::{tuple, preceded, terminated};
119
use nom::bytes::complete::{take, take_while, take_while_m_n};
1210
use nom::combinator::map;
11+
use nom::sequence::{preceded, terminated, tuple};
12+
use nom::{bytes::complete::tag, IResult};
1313

1414
#[derive(PartialEq, Eq, Debug, Hash)]
1515
pub struct Tag<'data> {
@@ -75,10 +75,6 @@ fn parse_signature(d: &[u8]) -> Result<Signature, Error> {
7575
})
7676
}
7777

78-
fn context(msg: &'static str) -> impl Fn(nom::Err<Error>) -> nom::Err<Error> {
79-
move |e: nom::Err<Error>| e.map(|e| e.parse_context(msg))
80-
}
81-
8278
fn is_hex_digit_lc(b: u8) -> bool {
8379
match b {
8480
b'0'..=b'9' => true,
@@ -89,7 +85,14 @@ fn is_hex_digit_lc(b: u8) -> bool {
8985

9086
pub(crate) fn parse_tag_nom(i: &[u8]) -> IResult<&[u8], Tag, Error> {
9187
const NL: &[u8] = b"\n";
92-
let (i, _) = terminated(preceded(tag(b"object "), take_while_m_n(40usize, 40, is_hex_digit_lc)), tag(NL))(i).map_err(context("object <40 lowercase hex char>"))?;
88+
let (i, _) = terminated(
89+
preceded(
90+
tag(b"object "),
91+
take_while_m_n(40usize, 40, is_hex_digit_lc),
92+
),
93+
tag(NL),
94+
)(i)
95+
.map_err(Error::context("object <40 lowercase hex char>"))?;
9396
unimplemented!("parse message nom")
9497
}
9598

0 commit comments

Comments
 (0)