Skip to main content

Pattern

Enum Pattern 

Source
pub enum Pattern {
    Glob(GlobPattern),
    Regex(RegexPattern),
    Exact(ExactPattern),
}
Expand description

Pattern for matching symbol names.

§Examples

use ryo_analysis::Pattern;

// Glob pattern
let pattern = Pattern::glob("*Config");
assert!(pattern.matches("AppConfig"));
assert!(pattern.matches("UserConfig"));
assert!(!pattern.matches("config"));

// Regex pattern
let pattern = Pattern::regex(r"^(get|set)_.*").unwrap();
assert!(pattern.matches("get_name"));
assert!(pattern.matches("set_value"));
assert!(!pattern.matches("fetch_data"));

// Case-insensitive
let pattern = Pattern::glob_with_options("*config",
    ryo_analysis::pattern::CaseOptions::new().with_ignore_case());
assert!(pattern.matches("AppConfig"));
assert!(pattern.matches("APPCONFIG"));

// Word-separate-insensitive
let pattern = Pattern::glob_with_options("get_user*",
    ryo_analysis::pattern::CaseOptions::new().with_ignore_word_separate());
assert!(pattern.matches("get_user_name"));
assert!(pattern.matches("getUserName"));
assert!(pattern.matches("GetUserName"));

Variants§

§

Glob(GlobPattern)

Glob pattern (supports * and ? wildcards).

§

Regex(RegexPattern)

Regular expression pattern.

§

Exact(ExactPattern)

Exact match.

Implementations§

Source§

impl Pattern

Source

pub fn glob(pattern: impl Into<String>) -> Self

Create a glob pattern.

Supports:

  • *: Matches any sequence of characters
  • ?: Matches any single character
  • [abc]: Matches any character in the brackets
  • [!abc]: Matches any character not in the brackets
§Examples
use ryo_analysis::Pattern;

let pattern = Pattern::glob("*Config");
assert!(pattern.matches("AppConfig"));
Source

pub fn glob_with_options( pattern: impl Into<String>, case_options: CaseOptions, ) -> Self

Create a glob pattern with case options.

§Examples
use ryo_analysis::{Pattern, pattern::CaseOptions};

let pattern = Pattern::glob_with_options("*config",
    CaseOptions::new().with_ignore_case());
assert!(pattern.matches("AppConfig"));
assert!(pattern.matches("APPCONFIG"));
Source

pub fn regex(pattern: impl Into<String>) -> Result<Self, PatternError>

Create a regex pattern.

§Errors

Returns Err(PatternError::InvalidRegex) if the pattern is invalid.

§Examples
use ryo_analysis::Pattern;

let pattern = Pattern::regex(r"^(get|set)_.*").unwrap();
assert!(pattern.matches("get_name"));
Source

pub fn regex_with_options( pattern: impl Into<String>, case_options: CaseOptions, ) -> Result<Self, PatternError>

Create a regex pattern with case options.

§Examples
use ryo_analysis::{Pattern, pattern::CaseOptions};

let pattern = Pattern::regex_with_options(r"config",
    CaseOptions::new().with_ignore_case()).unwrap();
assert!(pattern.matches("AppConfig"));
Source

pub fn exact(name: impl Into<String>) -> Self

Create an exact match pattern.

§Examples
use ryo_analysis::Pattern;

let pattern = Pattern::exact("Config");
assert!(pattern.matches("Config"));
assert!(!pattern.matches("config"));
Source

pub fn exact_with_options( name: impl Into<String>, case_options: CaseOptions, ) -> Self

Create an exact match pattern with case options.

§Examples
use ryo_analysis::{Pattern, pattern::CaseOptions};

let pattern = Pattern::exact_with_options("config",
    CaseOptions::new().with_ignore_case());
assert!(pattern.matches("Config"));
assert!(pattern.matches("CONFIG"));
Source

pub fn matches(&self, s: &str) -> bool

Check if the pattern matches a string.

Source

pub fn as_str(&self) -> &str

Get the pattern string.

Source

pub fn case_options(&self) -> CaseOptions

Get the case options for this pattern.

Source

pub fn is_glob(&self) -> bool

Check if this is a glob pattern.

Source

pub fn is_regex(&self) -> bool

Check if this is a regex pattern.

Source

pub fn is_exact(&self) -> bool

Check if this is an exact match pattern.

Source

pub fn has_wildcards(&self) -> bool

Check if this pattern contains wildcards.

Trait Implementations§

Source§

impl Clone for Pattern

Source§

fn clone(&self) -> Pattern

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 Debug for Pattern

Source§

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

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

impl<'de> Deserialize<'de> for Pattern

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Pattern

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,