pub struct Scope { /* private fields */ }
Expand description
A hierarchy of atoms with semi-standardized names used to accord semantic information to a specific piece of text.
These are generally written with the atoms separated by dots, and - 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.
Implementations
sourceimpl Scope
impl Scope
sourcepub fn new(s: &str) -> Result<Scope, ParseScopeError>
pub fn new(s: &str) -> Result<Scope, ParseScopeError>
Parses a Scope
from a series of atoms separated by dot (.
) characters
Example: Scope::new("meta.rails.controller")
sourcepub fn atom_at(self, index: usize) -> u16
pub fn atom_at(self, index: usize) -> u16
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 is_empty(self) -> bool
sourcepub fn build_string(self) -> String
pub fn build_string(self) -> String
Returns a string representation of this scope
This requires locking a global repo and shouldn’t be done frequently.
sourcepub fn is_prefix_of(self, s: Scope) -> bool
pub fn is_prefix_of(self, s: Scope) -> bool
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
sourceimpl<'de> Deserialize<'de> for Scope
impl<'de> Deserialize<'de> for Scope
sourcefn 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
sourceimpl FromStr for Scope
impl FromStr for Scope
type Err = ParseScopeError
type Err = ParseScopeError
The associated error which can be returned from parsing.
sourceimpl Ord for Scope
impl Ord for Scope
sourceimpl PartialOrd<Scope> for Scope
impl PartialOrd<Scope> for Scope
sourcefn partial_cmp(&self, other: &Scope) -> Option<Ordering>
fn partial_cmp(&self, other: &Scope) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Scope
impl Eq for Scope
impl StructuralEq for Scope
impl StructuralPartialEq for Scope
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more