Struct syntect::parsing::Scope
[−]
[src]
pub struct Scope { /* fields omitted */ }
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]
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")
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.
fn len(self) -> u32
[src]
return the number of atoms in the scope
fn is_empty(&self) -> bool
[src]
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.
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]
fn clone(&self) -> Scope
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq for Scope
[src]
fn eq(&self, __arg_0: &Scope) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Scope) -> bool
[src]
This method tests for !=
.
impl Eq for Scope
[src]
impl PartialOrd for Scope
[src]
fn partial_cmp(&self, __arg_0: &Scope) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Scope) -> bool
[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Scope) -> bool
[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Scope) -> bool
[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Scope) -> bool
[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for Scope
[src]
fn cmp(&self, __arg_0: &Scope) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl Copy for Scope
[src]
impl Default for Scope
[src]
impl Hash for Scope
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
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]
Parses a string s
to return a value of this type. Read more
impl Display for Scope
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Debug for Scope
[src]
impl Serialize for Scope
[src]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
[src]
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Deserialize<'de> for Scope
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more