[][src]Struct syntect::parsing::Scope

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.

Implementations

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]

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.

impl Hash for Scope[src]

impl Ord for Scope[src]

impl PartialEq<Scope> for Scope[src]

impl PartialOrd<Scope> for Scope[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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.