pub struct Spec {Show 21 fields
pub name: String,
pub description: Option<String>,
pub documentation: Option<String>,
pub notes: Vec<(String, ColumnNote)>,
pub path: Option<PathBuf>,
pub globs: Vec<String>,
pub magic: Vec<u8>,
pub magic_offset: u64,
pub expect: Vec<(String, Expected)>,
pub endian: Endian,
pub endian_auto: bool,
pub layout: Layout,
pub header: Header,
pub records: Records,
pub delimited: Option<Arc<Delimited>>,
pub footer: Option<Footer>,
pub blocks: Option<Blocks>,
pub capture: Option<Capture>,
pub files: Option<Files>,
pub sections: Vec<Section>,
pub variant: Option<String>,
/* private fields */
}Expand description
One format, as its spec describes it.
Fields§
§name: String§description: Option<String>§documentation: Option<String>An https:// link to the format’s own documentation.
notes: Vec<(String, ColumnNote)>A delimited spec’s [columns] notes: what each column of the file means.
path: Option<PathBuf>The file it was read from.
globs: Vec<String>§magic: Vec<u8>§magic_offset: u64§expect: Vec<(String, Expected)>Header fields and the values a file must hold in them to match.
endian: Endian§endian_auto: boolThe byte order is the one the magic reads in: as written, little-endian, and reversed, big-endian.
layout: Layout§header: Header§records: Records§delimited: Option<Arc<Delimited>>For kind = "delimited": the reading options of a CSV-like file. A delimited
spec has no header or record fields.
blocks: Option<Blocks>§capture: Option<Capture>§files: Option<Files>§sections: Vec<Section>§variant: Option<String>The variant read alone (--table), when one is.
Implementations§
Source§impl Spec
impl Spec
Sourcepub fn parse(text: &str, path: Option<&Path>) -> Result<Self, SpecError>
pub fn parse(text: &str, path: Option<&Path>) -> Result<Self, SpecError>
Read a spec from its text. path names it in errors.
Sourcepub fn is_delimited(&self) -> bool
pub fn is_delimited(&self) -> bool
Whether the spec is kind = "delimited".
Sourcepub fn load(path: &Path) -> Result<Self, SpecError>
pub fn load(path: &Path) -> Result<Self, SpecError>
Read the spec in path, which may be no more than MAX_SPEC_BYTES.
Sourcepub fn from_bytes(bytes: &[u8], from: &Path) -> Result<Self, SpecError>
pub fn from_bytes(bytes: &[u8], from: &Path) -> Result<Self, SpecError>
The spec in bytes, read from from (a file or a URL), refused past
MAX_SPEC_BYTES.
Sourcepub fn glob_matches(&self, path: &Path) -> bool
pub fn glob_matches(&self, path: &Path) -> bool
Whether path’s name matches one of the spec’s globs. A glob with a / is
matched against the whole path, one without against the name.
Sourcepub fn magic_matches(&self, head: &[u8]) -> bool
pub fn magic_matches(&self, head: &[u8]) -> bool
Whether head, the first bytes of a file, carries the spec’s magic. A delimited
spec’s magic is the start of the first line, after any byte-order mark.
Sourcepub fn header_matches(&self, head: &[u8]) -> bool
pub fn header_matches(&self, head: &[u8]) -> bool
Whether head holds the header values match.where asks for.
Sourcepub fn match_reach(&self) -> u64
pub fn match_reach(&self) -> u64
Bytes from the front of a file that settle the spec’s magic and where.
Sourcepub fn match_chips(&self) -> Vec<MatchChip>
pub fn match_chips(&self) -> Vec<MatchChip>
What the spec says files of it look like, one chip per condition: its magic,
its header values, then its globs. Empty when only --format picks it.
Sourcepub fn match_chips_for(&self, path: &Path) -> Vec<MatchChip>
pub fn match_chips_for(&self, path: &Path) -> Vec<MatchChip>
The chips that named path on the home screen: the glob alone when it names the
file, since a listing names a file by its glob without reading its header; else
the magic and the header values it was checked against. All of them when
neither does.
Sourcepub fn match_chips_chosen(&self, by: Chosen) -> Vec<MatchChip>
pub fn match_chips_chosen(&self, by: Chosen) -> Vec<MatchChip>
The chips of the rule that chose the spec: Chosen::Glob or Chosen::Magic
leave the other out; any other choice keeps every chip.
Sourcepub fn lists_variants(&self) -> bool
pub fn lists_variants(&self) -> bool
Whether the spec reads a file’s records as several variants, each listed as a table inside the file.
Sourcepub fn static_columns(&self) -> Option<Vec<(String, DataType)>>
pub fn static_columns(&self) -> Option<Vec<(String, DataType)>>
The columns a file of the spec opens with, when the spec alone says them: fixed
records of one file whose fields take nothing from the file (no sizes, symbols or
dates from its header). None when the open has to read the file to know.
Source§impl Spec
impl Spec
Sourcepub fn open_rows(
&self,
bytes: Arc<Bytes>,
named: &str,
) -> Result<Opened, String>
pub fn open_rows( &self, bytes: Arc<Bytes>, named: &str, ) -> Result<Opened, String>
Read bytes, one file of the rows layout, named named in what it says.
Sourcepub fn for_file(&self, head: &[u8]) -> Cow<'_, Spec>
pub fn for_file(&self, head: &[u8]) -> Cow<'_, Spec>
The spec with its byte order settled by head, for endian = "auto": as the
spec says when the magic reads as written, big-endian when it reads reversed.
Sourcepub fn reads_directory(&self) -> bool
pub fn reads_directory(&self) -> bool
Whether the spec reads a directory: column files, or a tree of its files.
Sourcepub fn with_variant(&self, name: &str) -> Result<Spec, String>
pub fn with_variant(&self, name: &str) -> Result<Spec, String>
The spec reading the variant name alone: only its records, and only its columns.
Sourcepub fn open_rows_in(
&self,
bytes: Arc<Bytes>,
named: &str,
path: Option<&Path>,
) -> Result<Opened, String>
pub fn open_rows_in( &self, bytes: Arc<Bytes>, named: &str, path: Option<&Path>, ) -> Result<Opened, String>
Read bytes, one file, named named in what it says; a symbol list a field
names is looked for beside path, the file the bytes are, which also keeps the
walk of its records for the next open of it.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Spec
impl !UnwindSafe for Spec
impl Freeze for Spec
impl Send for Spec
impl Sync for Spec
impl Unpin for Spec
impl UnsafeUnpin for Spec
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more