Skip to main content

rl_lang/utils/
source.rs

1use std::sync::Arc;
2
3/// A named source file (or `<repl>` snippet) carried through each pipeline
4/// stage so error reports can quote the original source text.
5#[derive(Clone)]
6pub struct SourceFile {
7    /// The file name shown in error report headers (e.g. `"main.rl"`, `"<repl>"`).
8    pub name: Arc<str>,
9    /// The full source text, reference-counted to avoid cloning across pipeline stages.
10    pub text: Arc<String>,
11}
12
13impl SourceFile {
14    /// Creates a new [`SourceFile`] from a name and source text.
15    pub fn new(name: impl Into<Arc<str>>, text: impl Into<Arc<String>>) -> Self {
16        Self {
17            name: name.into(),
18            text: text.into(),
19        }
20    }
21}