pub struct ParserRegistry { /* private fields */ }Expand description
An ordered set of format parsers.
Implementations§
Source§impl ParserRegistry
impl ParserRegistry
pub fn new() -> Self
pub fn register(&mut self, parser: Box<dyn FormatParser>) -> &mut Self
Sourcepub fn ids(&self) -> Vec<&'static str>
pub fn ids(&self) -> Vec<&'static str>
Registered parser ids, in order (handy for describe/tests).
Sourcepub fn resolve(
&self,
source: &str,
bytes: &[u8],
) -> Result<&dyn FormatParser, AxError>
pub fn resolve( &self, source: &str, bytes: &[u8], ) -> Result<&dyn FormatParser, AxError>
Resolves the parser for source/bytes: a matching file extension wins;
otherwise the highest-confidence content sniff (first registered on a
tie). An unrecognized stream is AxError::UnknownFormat, never a guess.
Sourcepub fn normalize(
&self,
source: &str,
bytes: &[u8],
) -> Result<RecordSet, AxError>
pub fn normalize( &self, source: &str, bytes: &[u8], ) -> Result<RecordSet, AxError>
Resolve, parse, and wrap into a RecordSet tagged with the parser id.
When the parser was picked by a weak (TEXT/FALLBACK) content sniff
and then fails to parse, the content guess was simply wrong — so the
stream is reported as AxError::UnknownFormat, not with that parser’s
internal error (e.g. a plain-text file that merely starts with [ is
“unrecognized”, not “invalid JSON”). An explicit extension or a
MAGIC/STRONG signature that then fails is a genuine malformed-file
error and is surfaced as-is.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ParserRegistry
impl !RefUnwindSafe for ParserRegistry
impl Send for ParserRegistry
impl Sync for ParserRegistry
impl Unpin for ParserRegistry
impl UnsafeUnpin for ParserRegistry
impl !UnwindSafe for ParserRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more