use ecow::EcoString;
use typst_syntax::Spanned;
use crate::diag::{LoadedWithin, SourceResult};
use crate::engine::Engine;
use crate::foundations::{Cast, func};
use crate::loading::{DataSource, Load, Readable};
#[func]
pub fn read(
engine: &mut Engine,
path: Spanned<EcoString>,
#[named]
#[default(Some(Encoding::Utf8))]
encoding: Option<Encoding>,
) -> SourceResult<Readable> {
let loaded = path.map(DataSource::Path).load(engine.world)?;
Ok(match encoding {
None => Readable::Bytes(loaded.data),
Some(Encoding::Utf8) => Readable::Str(loaded.data.to_str().within(&loaded)?),
})
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
pub enum Encoding {
Utf8,
}