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

pub struct Scope { /* fields omitted */ }
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

Parses a Scope from a series of atoms separated by dot (.) characters

Example: Scope::new("meta.rails.controller")

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.

Returns the number of atoms in the scope

Returns a string representation of this scope

This requires locking a global repo and shouldn’t be done frequently.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.