diff options
Diffstat (limited to 'vendor/gix-object/src/lib.rs')
-rw-r--r-- | vendor/gix-object/src/lib.rs | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/vendor/gix-object/src/lib.rs b/vendor/gix-object/src/lib.rs index d6c9fb760..56e0019fd 100644 --- a/vendor/gix-object/src/lib.rs +++ b/vendor/gix-object/src/lib.rs @@ -14,6 +14,8 @@ use std::borrow::Cow; /// For convenience to allow using `bstr` without adding it to own cargo manifest. pub use bstr; use bstr::{BStr, BString, ByteSlice}; +/// For convenience to allow using `gix-date` without adding it to own cargo manifest. +pub use gix_date as date; use smallvec::SmallVec; /// @@ -213,6 +215,8 @@ pub enum Object { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TreeRef<'a> { /// The directories and files contained in this tree. + /// + /// Beware that the sort order isn't *quite* by name, so one may bisect only with a [`tree::EntryRef`] to handle ordering correctly. #[cfg_attr(feature = "serde", serde(borrow))] pub entries: Vec<tree::EntryRef<'a>>, } @@ -229,6 +233,8 @@ pub struct TreeRefIter<'a> { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Tree { /// The directories and files contained in this tree. They must be and remain sorted by [`filename`][tree::Entry::filename]. + /// + /// Beware that the sort order isn't *quite* by name, so one may bisect only with a [`tree::Entry`] to handle ordering correctly. pub entries: Vec<tree::Entry>, } @@ -252,16 +258,12 @@ pub struct Data<'a> { pub mod decode { #[cfg(feature = "verbose-object-parsing-errors")] mod _decode { - use crate::bstr::{BString, ByteSlice}; - /// The type to be used for parse errors. - pub type ParseError<'a> = nom::error::VerboseError<&'a [u8]>; - /// The owned type to be used for parse errors. - pub type ParseErrorOwned = nom::error::VerboseError<BString>; + pub type ParseError = winnow::error::ContextError<winnow::error::StrContext>; pub(crate) fn empty_error() -> Error { Error { - inner: nom::error::VerboseError::<BString> { errors: Vec::new() }, + inner: winnow::error::ContextError::new(), } } @@ -269,22 +271,13 @@ pub mod decode { #[derive(Debug, Clone)] pub struct Error { /// The actual error - pub inner: ParseErrorOwned, + pub inner: ParseError, } - impl<'a> From<nom::Err<ParseError<'a>>> for Error { - fn from(v: nom::Err<ParseError<'a>>) -> Self { - Error { - inner: match v { - nom::Err::Error(err) | nom::Err::Failure(err) => nom::error::VerboseError { - errors: err - .errors - .into_iter() - .map(|(i, v)| (i.as_bstr().to_owned(), v)) - .collect(), - }, - nom::Err::Incomplete(_) => unreachable!("we don't have streaming parsers"), - }, + impl Error { + pub(crate) fn with_err(err: winnow::error::ErrMode<ParseError>) -> Self { + Self { + inner: err.into_inner().expect("we don't have streaming parsers"), } } } @@ -300,9 +293,7 @@ pub mod decode { #[cfg(not(feature = "verbose-object-parsing-errors"))] mod _decode { /// The type to be used for parse errors, discards everything and is zero size - pub type ParseError<'a> = (); - /// The owned type to be used for parse errors, discards everything and is zero size - pub type ParseErrorOwned = (); + pub type ParseError = (); pub(crate) fn empty_error() -> Error { Error { inner: () } @@ -312,16 +303,13 @@ pub mod decode { #[derive(Debug, Clone)] pub struct Error { /// The actual error - pub inner: ParseErrorOwned, + pub inner: ParseError, } - impl<'a> From<nom::Err<ParseError<'a>>> for Error { - fn from(v: nom::Err<ParseError<'a>>) -> Self { - Error { - inner: match v { - nom::Err::Error(err) | nom::Err::Failure(err) => err, - nom::Err::Incomplete(_) => unreachable!("we don't have streaming parsers"), - }, + impl Error { + pub(crate) fn with_err(err: winnow::error::ErrMode<ParseError>) -> Self { + Self { + inner: err.into_inner().expect("we don't have streaming parsers"), } } } @@ -333,7 +321,7 @@ pub mod decode { } } pub(crate) use _decode::empty_error; - pub use _decode::{Error, ParseError, ParseErrorOwned}; + pub use _decode::{Error, ParseError}; impl std::error::Error for Error {} /// Returned by [`loose_header()`] |