Struct cranelift_isle::error::Errors
source · Expand description
A collection of errors from attempting to compile some ISLE source files.
Fields§
§errors: Vec<Error>
The individual errors.
Implementations§
source§impl Errors
impl Errors
sourcepub fn from_io(error: Error, context: impl Into<String>) -> Self
pub fn from_io(error: Error, context: impl Into<String>) -> Self
Create isle::Errors
from the given I/O error and context.
Examples found in repository?
src/lexer.rs (line 103)
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
pub fn from_files<P>(file_paths: impl IntoIterator<Item = P>) -> Result<Lexer<'a>>
where
P: AsRef<Path>,
{
let mut filenames = Vec::<Arc<str>>::new();
let mut file_texts = Vec::<Arc<str>>::new();
for f in file_paths {
let f = f.as_ref();
filenames.push(f.display().to_string().into());
let s = std::fs::read_to_string(f)
.map_err(|e| Errors::from_io(e, format!("failed to read file: {}", f.display())))?;
file_texts.push(s.into());
}
assert!(!filenames.is_empty());
let mut file_starts = vec![];
let mut buf = String::new();
for text in &file_texts {
file_starts.push(buf.len());
buf += &text;
buf += "\n";
}
let mut l = Lexer {
filenames,
file_texts,
buf: Cow::Owned(buf.into_bytes()),
file_starts,
pos: Pos {
file: 0,
offset: 0,
line: 1,
col: 0,
},
lookahead: None,
};
l.reload()?;
Ok(l)
}