pub struct TagSet { /* private fields */ }Expand description
Implementations§
Source§impl TagSet
impl TagSet
Sourcepub const fn new() -> Self
pub const fn new() -> Self
The empty set (same as TagSet::EMPTY).
Sourcepub fn from_names<I, S>(names: I) -> Result<Self, UnknownTagError>
pub fn from_names<I, S>(names: I) -> Result<Self, UnknownTagError>
Build a set from tag names, failing with every unknown name.
§Errors
Returns UnknownTagError listing all names not in ALL_TAGS.
Sourcepub const fn contains_tag(&self, tag: Tag) -> bool
pub const fn contains_tag(&self, tag: Tag) -> bool
Sourcepub fn contains(&self, tag: impl IntoTag) -> bool
pub fn contains(&self, tag: impl IntoTag) -> bool
Whether the set contains tag, given as a Tag or a tag name.
use file_identify::{Tag, tags_from_filename};
let tags = tags_from_filename("setup.py");
assert!(tags.contains("python"));
assert!(tags.contains(Tag::TEXT));
assert!(!tags.contains("no-such-tag"));Sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
self ∩ other.
Sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
self \ other.
Sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
Tags in exactly one of self and other.
Sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
Every known tag that is not in self.
Sourcepub const fn is_superset(&self, other: &Self) -> bool
pub const fn is_superset(&self, other: &Self) -> bool
Whether every tag of other is in self (Python’s self >= other).
Sourcepub const fn is_disjoint(&self, other: &Self) -> bool
pub const fn is_disjoint(&self, other: &Self) -> bool
Whether self and other share no tag.
Sourcepub const fn intersects(&self, other: &Self) -> bool
pub const fn intersects(&self, other: &Self) -> bool
Whether self and other share at least one tag.
Sourcepub const fn matches_types(
&self,
types: &Self,
types_or: &Self,
exclude_types: &Self,
) -> bool
pub const fn matches_types( &self, types: &Self, types_or: &Self, exclude_types: &Self, ) -> bool
pre-commit’s file-type filter (Classifier.by_types) applied to the
tags of one file:
self ⊇ types && (types_or = ∅ || self ∩ types_or ≠ ∅) && self ∩ exclude_types = ∅
use file_identify::TagSet;
let file: TagSet = "file, non-executable, python, text".parse()?;
let none = TagSet::EMPTY;
let types: TagSet = "file".parse()?;
let types_or: TagSet = "python, pyi".parse()?;
let exclude: TagSet = "binary".parse()?;
assert!(file.matches_types(&types, &types_or, &exclude));
assert!(!file.matches_types(&types, &none, &"python".parse()?));Sourcepub const fn has_encoding(&self) -> bool
pub const fn has_encoding(&self) -> bool
Whether the set contains text or binary (identify’s invariant for
a classified regular file).
Sourcepub fn names(
&self,
) -> impl DoubleEndedIterator<Item = &'static str> + ExactSizeIterator
pub fn names( &self, ) -> impl DoubleEndedIterator<Item = &'static str> + ExactSizeIterator
Iterate over the tag names in sorted order.
Trait Implementations§
Source§impl BitAndAssign for TagSet
impl BitAndAssign for TagSet
Source§fn bitand_assign(&mut self, rhs: TagSet)
fn bitand_assign(&mut self, rhs: TagSet)
&= operation. Read moreSource§impl BitAndAssign<Tag> for TagSet
impl BitAndAssign<Tag> for TagSet
Source§fn bitand_assign(&mut self, rhs: Tag)
fn bitand_assign(&mut self, rhs: Tag)
&= operation. Read moreSource§impl BitOrAssign for TagSet
impl BitOrAssign for TagSet
Source§fn bitor_assign(&mut self, rhs: TagSet)
fn bitor_assign(&mut self, rhs: TagSet)
|= operation. Read moreSource§impl BitOrAssign<Tag> for TagSet
impl BitOrAssign<Tag> for TagSet
Source§fn bitor_assign(&mut self, rhs: Tag)
fn bitor_assign(&mut self, rhs: Tag)
|= operation. Read moreSource§impl BitXorAssign for TagSet
impl BitXorAssign for TagSet
Source§fn bitxor_assign(&mut self, rhs: TagSet)
fn bitxor_assign(&mut self, rhs: TagSet)
^= operation. Read moreSource§impl BitXorAssign<Tag> for TagSet
impl BitXorAssign<Tag> for TagSet
Source§fn bitxor_assign(&mut self, rhs: Tag)
fn bitxor_assign(&mut self, rhs: Tag)
^= operation. Read moreimpl Copy for TagSet
Source§impl Display for TagSet
Tag names in name order separated by ", ", e.g.
file, non-executable, python, text (the empty set prints nothing).
FromStr accepts the same format.
impl Display for TagSet
Tag names in name order separated by ", ", e.g.
file, non-executable, python, text (the empty set prints nothing).
FromStr accepts the same format.
impl Eq for TagSet
Source§impl Extend<Tag> for TagSet
impl Extend<Tag> for TagSet
Source§fn extend<I: IntoIterator<Item = Tag>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Tag>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<Tag> for TagSet
impl FromIterator<Tag> for TagSet
Source§impl FromStr for TagSet
Parse comma-separated tag names (surrounding whitespace is ignored, empty
items are skipped), the format produced by Display.
impl FromStr for TagSet
Parse comma-separated tag names (surrounding whitespace is ignored, empty
items are skipped), the format produced by Display.
Source§impl IntoIterator for TagSet
impl IntoIterator for TagSet
Source§impl IntoIterator for &TagSet
impl IntoIterator for &TagSet
impl StructuralPartialEq for TagSet
Source§impl SubAssign for TagSet
impl SubAssign for TagSet
Source§fn sub_assign(&mut self, rhs: TagSet)
fn sub_assign(&mut self, rhs: TagSet)
-= operation. Read more