mango 0.4.0

The Mango programming language (UNDER CONSTRUCTION)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use ::std::fs;
use ::std::path::Path;

use crate::common::error::{MangoResult, MangoErr, ErrMsg, MangoErrType, Severity};
use crate::io::source::SourceFile;

pub fn read(pth: &Path) -> MangoResult<SourceFile> {
    match fs::read_to_string(pth) {
        Ok(content) => Ok(SourceFile::new(pth.to_string_lossy(), content)),
        Err(err) => Err(MangoErr::new_debug(
            format!("Could not read source in '{}'", pth.to_string_lossy()),
            format!("{:?}", err),
            Severity::Error,
            MangoErrType::Read,
        )),
    }
}