Struct wax::MatchedText

source ·
pub struct MatchedText<'t> { /* private fields */ }
Expand description

Text that has been matched by a Pattern and its captures.

To match a Glob or other Pattern against a CandidatePath and get the matched text, use the Pattern::matched function.

All Patterns provide an implicit capture of the complete text of a match. This implicit capture has index zero, and is exposed via the complete function as well as the get function using index zero. Capturing tokens are indexed starting at one, and can be used to isolate more specific sub-text.

Examples

Capturing tokens and matched text can be used to isolate sub-text in a match. For example, the file name of a match can be extracted using an alternative to group patterns.

use wax::{CandidatePath, Glob, Pattern};

let glob = Glob::new("src/**/{*.{go,rs}}").unwrap();
let candidate = CandidatePath::from("src/graph/link.rs");
let matched = glob.matched(&candidate).unwrap();

assert_eq!("link.rs", matched.get(2).unwrap());

Implementations§

source§

impl<'t> MatchedText<'t>

source

pub fn into_owned(self) -> MatchedText<'static>

Clones any borrowed data into an owning instance.

source

pub fn to_owned(&self) -> MatchedText<'static>

Clones any borrowed data to an owning instance.

This function is similar to into_owned, but does not consume its receiver. Due to a technical limitation, MatchedText cannot implement Clone, so this function is provided as a stop gap that allows a distinct instance to be created that owns its data.

source

pub fn complete(&self) -> &str

Gets the complete text of a match.

All Patterns have an implicit capture of the complete text at index zero. This function is therefore equivalent to unwrapping the output of the get function with index zero.

source

pub fn get(&self, index: usize) -> Option<&str>

Gets the matched text of a capture at the given index.

All Patterns have an implicit capture of the complete text at index zero. Capturing tokens are indexed from one, so any capturing sub-expression will be indexed after the implicit complete text. For example, the sub-expression * in the glob expression *.txt is at index one and will exclude the suffix .txt in its matched text.

Alternative and repetition patterns group their sub-globs into a single capture, so it is not possible to isolate matched text from their sub-globs. This can be used to explicitly group matched text, such as isolating an entire matched file name using an expression like {*.{go,rs}}.

source

pub fn to_candidate_path(&self) -> CandidatePath<'_>

Trait Implementations§

source§

impl<'t> Debug for MatchedText<'t>

source§

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

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

impl<'t> From<Captures<'t>> for MatchedText<'t>

source§

fn from(captures: BorrowedText<'t>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'t> RefUnwindSafe for MatchedText<'t>

§

impl<'t> Send for MatchedText<'t>

§

impl<'t> Sync for MatchedText<'t>

§

impl<'t> Unpin for MatchedText<'t>

§

impl<'t> UnwindSafe for MatchedText<'t>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.