devalang_wasm/language/syntax/source/
mod.rs1use std::path::{Path, PathBuf};
2
3#[derive(Debug, Clone)]
4pub struct SourceFile {
5 pub path: PathBuf,
6 pub content: String,
7}
8
9impl SourceFile {
10 pub fn from_str(content: impl Into<String>) -> Self {
11 Self {
12 path: PathBuf::new(),
13 content: content.into(),
14 }
15 }
16
17 pub fn from_path(path: impl AsRef<Path>) -> anyhow::Result<Self> {
18 let path = path.as_ref();
19 let content = std::fs::read_to_string(path)?;
20 Ok(Self {
21 path: path.to_path_buf(),
22 content,
23 })
24 }
25
26 pub fn iter_lines(&self) -> impl Iterator<Item = &str> {
27 self.content.lines()
28 }
29}