pub struct ScriptOrigin { /* private fields */ }
Expand description
A representation of a range within Script source code.
This object points to specific span within the ScriptModule’s source code text, often highlighting identifiers and similar syntactic constructs. Generally, it can span arbitrary range of text tokens.
Unlike absolute ranges (such as 10..20
or
Position::new(1, 4)..Position::new(3, 8)
), the ScriptOrigin range is
relative. If you edit the script’s text before, after, or inside the
referenced range, this range will realign accordingly. However, if the
text edits affect the ScriptOrigin bounds directly, the object will
become obsolete.
In general, ScriptOrigin may represent an invalid range or become
invalid over time if the source code is edited. You can check the range’s
validity using the is_valid_span method, passing
an instance of ModuleText:
script_origin.is_valid_span(&module_text)
.
Note that ScriptOrigin belongs to a specific ScriptModule instance and is valid only for that module. The id function of ScriptOrigin returns a globally unique identifier for the script module to which this ScriptOrigin object belongs.
Implementations§
Source§impl ScriptOrigin
impl ScriptOrigin
Sourcepub const fn nil() -> Self
pub const fn nil() -> Self
Creates an instance of ScriptOrigin that intentionally does not point to any Script code. This serves as the Default constructor for this object.
Sourcepub fn package(&self) -> Option<&'static PackageMeta>
pub fn package(&self) -> Option<&'static PackageMeta>
Returns the script package metadata of the ScriptModule that this ScriptOrigin points to.
Returns None if the package cannot be found, for instance, if the corresponding ScriptModule has been dropped.
Sourcepub const fn is_nil(&self) -> bool
pub const fn is_nil(&self) -> bool
Returns true if this instance is the Nil ScriptOrigin.
Trait Implementations§
Source§impl Clone for ScriptOrigin
impl Clone for ScriptOrigin
Source§fn clone(&self) -> ScriptOrigin
fn clone(&self) -> ScriptOrigin
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more