pub struct Source { /* private fields */ }
Expand description
A single source file.
Implementations§
Source§impl Source
impl Source
Sourcepub fn source_line(&self, span: Span) -> Option<SourceLine<'_>>
Available on crate feature emit
only.
pub fn source_line(&self, span: Span) -> Option<SourceLine<'_>>
emit
only.Print formatted diagnostics about a source conveniently.
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 pos_to_utf8_linecol(&self, offset: usize) -> (usize, usize)
pub fn pos_to_utf8_linecol(&self, offset: usize) -> (usize, usize)
Convert the given offset to a utf-16 line and character.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Source
impl RefUnwindSafe for Source
impl Send for Source
impl Sync for Source
impl Unpin for Source
impl UnwindSafe for Source
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more