Skip to main content

TagSet

Struct TagSet 

Source
pub struct TagSet { /* private fields */ }
Expand description

A set of Tags: a Copy bitset with one bit per known tag.

All operations are allocation-free; the binary operators |, &, -, ^ and ! (complement relative to all known tags) are available as well as the named methods. Iteration, Debug and Display list tags in name order.

Implementations§

Source§

impl TagSet

Source

pub const EMPTY: Self

The empty set.

Source

pub const ALL: Self

Every known tag (identify.ALL_TAGS).

Source

pub const fn new() -> Self

The empty set (same as TagSet::EMPTY).

Source

pub const fn from_tag(tag: Tag) -> Self

The set containing only tag.

Source

pub fn from_names<I, S>(names: I) -> Result<Self, UnknownTagError>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Build a set from tag names, failing with every unknown name.

§Errors

Returns UnknownTagError listing all names not in ALL_TAGS.

Source

pub const fn with(self, tag: Tag) -> Self

This set plus tag.

Source

pub const fn without(self, tag: Tag) -> Self

This set minus tag.

Source

pub const fn contains_tag(&self, tag: Tag) -> bool

Whether tag is in the set (const version of contains for Tag values).

Source

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"));
Source

pub fn insert(&mut self, tag: Tag) -> bool

Add tag; returns whether it was newly inserted.

Source

pub fn remove(&mut self, tag: Tag) -> bool

Remove tag; returns whether it was present.

Source

pub fn clear(&mut self)

Remove every tag.

Source

pub const fn len(&self) -> usize

Number of tags in the set.

Source

pub const fn is_empty(&self) -> bool

Whether the set is empty.

Source

pub const fn union(self, other: Self) -> Self

self ∪ other.

Source

pub const fn intersection(self, other: Self) -> Self

self ∩ other.

Source

pub const fn difference(self, other: Self) -> Self

self \ other.

Source

pub const fn symmetric_difference(self, other: Self) -> Self

Tags in exactly one of self and other.

Source

pub const fn complement(self) -> Self

Every known tag that is not in self.

Source

pub const fn is_subset(&self, other: &Self) -> bool

Whether every tag of self is in other.

Source

pub const fn is_superset(&self, other: &Self) -> bool

Whether every tag of other is in self (Python’s self >= other).

Source

pub const fn is_disjoint(&self, other: &Self) -> bool

Whether self and other share no tag.

Source

pub const fn intersects(&self, other: &Self) -> bool

Whether self and other share at least one tag.

Source

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()?));
Source

pub const fn has_encoding(&self) -> bool

Whether the set contains text or binary (identify’s invariant for a classified regular file).

Source

pub const fn iter(&self) -> Iter ⓘ

Iterate over the tags in name order.

Source

pub fn names( &self, ) -> impl DoubleEndedIterator<Item = &'static str> + ExactSizeIterator

Iterate over the tag names in sorted order.

Source

pub fn first(&self) -> Option<Tag>

The first tag in name order.

Source

pub fn last(&self) -> Option<Tag>

The last tag in name order.

Trait Implementations§

Source§

impl BitAnd for TagSet

Source§

type Output = TagSet

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: TagSet) -> TagSet

Performs the & operation. Read more
Source§

impl BitAnd<Tag> for TagSet

Source§

type Output = TagSet

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Tag) -> TagSet

Performs the & operation. Read more
Source§

impl BitAndAssign for TagSet

Source§

fn bitand_assign(&mut self, rhs: TagSet)

Performs the &= operation. Read more
Source§

impl BitAndAssign<Tag> for TagSet

Source§

fn bitand_assign(&mut self, rhs: Tag)

Performs the &= operation. Read more
Source§

impl BitOr for TagSet

Source§

type Output = TagSet

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: TagSet) -> TagSet

Performs the | operation. Read more
Source§

impl BitOr<Tag> for TagSet

Source§

type Output = TagSet

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Tag) -> TagSet

Performs the | operation. Read more
Source§

impl BitOrAssign for TagSet

Source§

fn bitor_assign(&mut self, rhs: TagSet)

Performs the |= operation. Read more
Source§

impl BitOrAssign<Tag> for TagSet

Source§

fn bitor_assign(&mut self, rhs: Tag)

Performs the |= operation. Read more
Source§

impl BitXor for TagSet

Source§

type Output = TagSet

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: TagSet) -> TagSet

Performs the ^ operation. Read more
Source§

impl BitXor<Tag> for TagSet

Source§

type Output = TagSet

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Tag) -> TagSet

Performs the ^ operation. Read more
Source§

impl BitXorAssign for TagSet

Source§

fn bitxor_assign(&mut self, rhs: TagSet)

Performs the ^= operation. Read more
Source§

impl BitXorAssign<Tag> for TagSet

Source§

fn bitxor_assign(&mut self, rhs: Tag)

Performs the ^= operation. Read more
Source§

impl Clone for TagSet

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TagSet

Source§

impl Debug for TagSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TagSet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
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.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TagSet

Source§

impl Extend<Tag> for TagSet

Source§

fn extend<I: IntoIterator<Item = Tag>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<Tag> for TagSet

Source§

fn from(tag: Tag) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<[Tag; N]> for TagSet

Source§

fn from(tags: [Tag; N]) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Tag> for TagSet

Source§

fn from_iter<I: IntoIterator<Item = Tag>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for TagSet

Parse comma-separated tag names (surrounding whitespace is ignored, empty items are skipped), the format produced by Display.

Source§

type Err = UnknownTagError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for TagSet

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoIterator for TagSet

Source§

type Item = Tag

The type of the elements being iterated over.
Source§

type IntoIter = Iter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter ⓘ

Creates an iterator from a value. Read more
Source§

impl IntoIterator for &TagSet

Source§

type Item = Tag

The type of the elements being iterated over.
Source§

type IntoIter = Iter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter ⓘ

Creates an iterator from a value. Read more
Source§

impl Not for TagSet

Source§

type Output = TagSet

The resulting type after applying the ! operator.
Source§

fn not(self) -> TagSet

Performs the unary ! operation using logical or bitwise negation. Read more
Source§

impl PartialEq for TagSet

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TagSet

Source§

impl Sub for TagSet

Source§

type Output = TagSet

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: TagSet) -> TagSet

Performs the - operation. Read more
Source§

impl Sub<Tag> for TagSet

Source§

type Output = TagSet

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Tag) -> TagSet

Performs the - operation. Read more
Source§

impl SubAssign for TagSet

Source§

fn sub_assign(&mut self, rhs: TagSet)

Performs the -= operation. Read more
Source§

impl SubAssign<Tag> for TagSet

Source§

fn sub_assign(&mut self, rhs: Tag)

Performs the -= operation. Read more
Source§

impl TryFrom<&[&str]> for TagSet

Source§

type Error = UnknownTagError

The type returned in the event of a conversion error.
Source§

fn try_from(names: &[&str]) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.