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
impl Pattern
Sourcepub fn glob(pattern: impl Into<String>) -> Self
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"));Sourcepub fn glob_with_options(
pattern: impl Into<String>,
case_options: CaseOptions,
) -> Self
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"));Sourcepub fn regex_with_options(
pattern: impl Into<String>,
case_options: CaseOptions,
) -> Result<Self, PatternError>
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"));Sourcepub fn exact(name: impl Into<String>) -> Self
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"));Sourcepub fn exact_with_options(
name: impl Into<String>,
case_options: CaseOptions,
) -> Self
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"));Sourcepub fn case_options(&self) -> CaseOptions
pub fn case_options(&self) -> CaseOptions
Get the case options for this pattern.
Sourcepub fn has_wildcards(&self) -> bool
pub fn has_wildcards(&self) -> bool
Check if this pattern contains wildcards.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Pattern
impl<'de> Deserialize<'de> for Pattern
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Pattern
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnsafeUnpin for Pattern
impl UnwindSafe for Pattern
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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