pub struct FilePattern { /* private fields */ }Expand description
A file_patterns entry: either an optional directory part followed by a
final segment of the form *.EXT, or the bare name of an extensionless
file written as NAME or **/NAME.
The extension or name is the only part mcpls reads, so the directory part
of an extension pattern (such as **/) is kept for display and ignored for
routing. A name pattern admits no directory part other than **/, so it
never claims every file of that name below one directory. Every other form
(brace expansion, character classes, ?, dotted names, dotfiles, single
files below a directory) has nothing to map and is rejected rather than
dropped silently. Self::parse is the only constructor, so the config
validator and the language-map builder cannot disagree on what is
supported.
§Examples
use std::assert_matches;
use mcpls_core::config::{FilePattern, PatternTarget};
let pattern = FilePattern::parse("**/*.rs").unwrap();
assert_matches!(pattern.target(), PatternTarget::Extension(e) if e == "rs");
assert_eq!(pattern.as_str(), "**/*.rs");
let makefile = FilePattern::parse("**/Makefile").unwrap();
assert_matches!(makefile.target(), PatternTarget::Name(n) if n == "Makefile");
assert!(FilePattern::parse("**/*.{cpp,h}").is_err());
assert!(FilePattern::parse("src/main.rs").is_err());
assert!(FilePattern::parse("docs/Makefile").is_err());
assert!(FilePattern::parse("/Makefile").is_err());Implementations§
Source§impl FilePattern
impl FilePattern
Sourcepub fn parse(pattern: &str) -> Result<Self, UnsupportedFilePattern>
pub fn parse(pattern: &str) -> Result<Self, UnsupportedFilePattern>
Parses pattern.
§Errors
Returns UnsupportedFilePattern if the final path segment (after the
last /) is neither *.EXT with a valid FileExtension nor a valid
FileName reached through no directory part but **/.
Sourcepub fn from_static(pattern: &'static str) -> Self
pub fn from_static(pattern: &'static str) -> Self
Parses a literal known to be supported, such as a built-in default.
§Panics
Panics if pattern is not a supported form.
Sourcepub const fn target(&self) -> &PatternTarget
pub const fn target(&self) -> &PatternTarget
The extension or file name this pattern maps.
Trait Implementations§
Source§impl Clone for FilePattern
impl Clone for FilePattern
Source§impl Debug for FilePattern
impl Debug for FilePattern
Source§impl Display for FilePattern
impl Display for FilePattern
impl Eq for FilePattern
Source§impl From<FilePattern> for String
impl From<FilePattern> for String
Source§fn from(pattern: FilePattern) -> Self
fn from(pattern: FilePattern) -> Self
Source§impl Hash for FilePattern
impl Hash for FilePattern
Source§impl PartialEq for FilePattern
impl PartialEq for FilePattern
Source§impl PartialEq<&str> for FilePattern
impl PartialEq<&str> for FilePattern
Source§impl PartialEq<str> for FilePattern
impl PartialEq<str> for FilePattern
Source§impl Serialize for FilePattern
impl Serialize for FilePattern
impl StructuralPartialEq for FilePattern
Auto Trait Implementations§
impl Freeze for FilePattern
impl RefUnwindSafe for FilePattern
impl Send for FilePattern
impl Sync for FilePattern
impl Unpin for FilePattern
impl UnsafeUnpin for FilePattern
impl UnwindSafe for FilePattern
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.