pub struct Source { /* private fields */ }Expand description
A single source file.
Implementations§
Source§impl Source
impl Source
Sourcepub fn new(name: impl AsRef<str>, source: impl AsRef<str>) -> Result<Self>
pub fn new(name: impl AsRef<str>, source: impl AsRef<str>) -> Result<Self>
Construct a new source with the given name.
Sourcepub fn memory(source: impl AsRef<str>) -> Result<Self>
pub fn memory(source: impl AsRef<str>) -> Result<Self>
Construct a new anonymously named <memory> source.
§Examples
use rune::Source;
let source = Source::memory("pub fn main() { 42 }")?;
assert_eq!(source.name(), "<memory>");Sourcepub fn from_path(path: impl AsRef<Path>) -> Result<Self, FromPathError>
Available on crate feature std only.
pub fn from_path(path: impl AsRef<Path>) -> Result<Self, FromPathError>
std only.Read and load a source from the given filesystem path.
Sourcepub fn with_path(
name: impl AsRef<str>,
source: impl AsRef<str>,
path: impl AsRef<Path>,
) -> Result<Self>
pub fn with_path( name: impl AsRef<str>, source: impl AsRef<str>, path: impl AsRef<Path>, ) -> Result<Self>
Construct a new source with the given content and path.
§Examples
use std::path::Path;
use rune::Source;
let source = Source::with_path("test", "pub fn main() { 42 }", "test.rn")?;
assert_eq!(source.name(), "test");
assert_eq!(source.path(), Some(Path::new("test.rn")));Sourcepub fn path(&self) -> Option<&Path>
pub fn path(&self) -> Option<&Path>
Get the path associated with the source.
§Examples
use std::path::Path;
use rune::Source;
let source = Source::with_path("test", "pub fn main() { 42 }", "test.rn")?;
assert_eq!(source.name(), "test");
assert_eq!(source.path(), Some(Path::new("test.rn")));Sourcepub fn find_line_column(&self, position: usize) -> (usize, usize)
pub fn find_line_column(&self, position: usize) -> (usize, usize)
Convert the given position to a utf-8 line position in code units.
A position is a character offset into the source in utf-8 characters.
Note that utf-8 code units is what you’d count when using the
str::chars() iterator.
Sourcepub fn find_utf16cu_line_column(&self, position: usize) -> (usize, usize)
pub fn find_utf16cu_line_column(&self, position: usize) -> (usize, usize)
Convert the given position to a utf-16 code units line and character.
A position is a character offset into the source in utf-16 characters.
Note that utf-16 code units is what you’d count when iterating over the
string in terms of characters as-if they would have been encoded with
char::encode_utf16().
Sourcepub fn source_line(&self, span: Span) -> Option<SourceLine<'_>>
pub fn source_line(&self, span: Span) -> Option<SourceLine<'_>>
Fetch SourceLine information for the given span.