Skip to main content

FileMatcher

Struct FileMatcher 

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

A Copyright’s file patterns, compiled once for looking up many paths.

Built with Copyright::matcher. Unlike Copyright::find_files, which recompiles every pattern on every call, this compiles each pattern once and reuses it, and reports which pattern claimed a path.

Implementations§

Source§

impl FileMatcher

Source

pub fn find_files(&self, path: &Path) -> Option<&FilesParagraph>

Find the files paragraph that matches the given path.

Consistent with the specification, this returns the last paragraph that matches, which is the most specific one.

Source

pub fn find_match(&self, path: &Path) -> Option<(&FilesParagraph, &GlobPattern)>

Find the files paragraph that matches the given path, along with the pattern that claimed it.

§Examples
use debian_copyright::lossless::Copyright;
use std::path::Path;

let text = "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/\n\
            \n\
            Files: *\n\
            License: GPL-3+\n\
            Copyright: 2019 John Doe\n\
            \n\
            Files: debian/*\n\
            License: GPL-3+\n\
            Copyright: 2019 Jane Packager\n";
let copyright: Copyright = text.parse().unwrap();
let matcher = copyright.matcher().unwrap();
let (_, pattern) = matcher.find_match(Path::new("debian/rules")).unwrap();
assert_eq!(pattern.pattern(), "debian/*");

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> 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, 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.