[−][src]Struct syntect::parsing::Scope
A hierarchy of atoms with semi-standardized names used to accord semantic information to a specific piece of text. Generally written with the atoms separated by dots. By convention atoms are all lowercase alphanumeric.
Example scopes: text.plain
, punctuation.definition.string.begin.ruby
,
meta.function.parameters.rust
syntect
uses an optimized format for storing these that allows super fast comparison
and determining if one scope is a prefix of another. It also always takes 16 bytes of space.
It accomplishes this by using a global repository to store string values and using bit-packed
16 bit numbers to represent and compare atoms. Like "atoms" or "symbols" in other languages.
This means that while comparing and prefix are fast, extracting a string is relatively slower
but ideally should be very rare.
Methods
impl Scope
[src]
pub fn new(s: &str) -> Result<Scope, ParseScopeError>
[src]
Parses a Scope
from a series of atoms separated by
.
characters. Example: Scope::new("meta.rails.controller")
pub fn atom_at(self, index: usize) -> u16
[src]
Gets the atom number at a given index. I can't think of any reason you'd find this useful. It is used internally for turning a scope back into a string.
pub fn len(self) -> u32
[src]
return the number of atoms in the scope
pub fn is_empty(&self) -> bool
[src]
pub fn build_string(self) -> String
[src]
returns a string representation of this scope, this requires locking a global repo and shouldn't be done frequently.
pub fn is_prefix_of(self, s: Scope) -> bool
[src]
Tests if this scope is a prefix of another scope. Note that the empty scope is always a prefix.
This operation uses bitwise operations and is very fast
Examples
use syntect::parsing::Scope; assert!( Scope::new("string").unwrap() .is_prefix_of(Scope::new("string.quoted").unwrap())); assert!( Scope::new("string.quoted").unwrap() .is_prefix_of(Scope::new("string.quoted").unwrap())); assert!( Scope::new("").unwrap() .is_prefix_of(Scope::new("meta.rails.controller").unwrap())); assert!(!Scope::new("source.php").unwrap() .is_prefix_of(Scope::new("source").unwrap())); assert!(!Scope::new("source.php").unwrap() .is_prefix_of(Scope::new("source.ruby").unwrap())); assert!(!Scope::new("meta.php").unwrap() .is_prefix_of(Scope::new("source.php").unwrap())); assert!(!Scope::new("meta.php").unwrap() .is_prefix_of(Scope::new("source.php.wow").unwrap()));
Trait Implementations
impl Clone for Scope
[src]
impl Copy for Scope
[src]
impl Debug for Scope
[src]
impl Default for Scope
[src]
impl<'de> Deserialize<'de> for Scope
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl Display for Scope
[src]
impl Eq for Scope
[src]
impl FromStr for Scope
[src]
type Err = ParseScopeError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Scope, ParseScopeError>
[src]
impl Hash for Scope
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Scope
[src]
fn cmp(&self, other: &Scope) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Scope> for Scope
[src]
impl PartialOrd<Scope> for Scope
[src]
fn partial_cmp(&self, other: &Scope) -> Option<Ordering>
[src]
fn lt(&self, other: &Scope) -> bool
[src]
fn le(&self, other: &Scope) -> bool
[src]
fn gt(&self, other: &Scope) -> bool
[src]
fn ge(&self, other: &Scope) -> bool
[src]
impl Serialize for Scope
[src]
impl StructuralEq for Scope
[src]
impl StructuralPartialEq for Scope
[src]
Auto Trait Implementations
impl RefUnwindSafe for Scope
impl Send for Scope
impl Sync for Scope
impl Unpin for Scope
impl UnwindSafe for Scope
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,