ds_decomp/config/
mod.rs

1use std::{fmt::Display, str::SplitWhitespace};
2
3pub mod config;
4pub mod delinks;
5pub mod module;
6pub mod relocations;
7pub mod section;
8pub mod symbol;
9
10#[derive(Debug, Clone)]
11pub struct ParseContext {
12    pub file_path: String,
13    pub row: usize,
14}
15
16impl Display for ParseContext {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        write!(f, "{}:{}", self.file_path, self.row)
19    }
20}
21
22// Shorthand for snafu errors
23impl From<&ParseContext> for ParseContext {
24    fn from(val: &ParseContext) -> Self {
25        val.clone()
26    }
27}
28impl From<&mut ParseContext> for ParseContext {
29    fn from(val: &mut ParseContext) -> Self {
30        val.clone()
31    }
32}
33
34pub(crate) fn iter_attributes(words: SplitWhitespace<'_>) -> ParseAttributesIterator<'_> {
35    ParseAttributesIterator { words }
36}
37
38pub(crate) struct ParseAttributesIterator<'a> {
39    words: SplitWhitespace<'a>,
40}
41
42impl<'a> Iterator for ParseAttributesIterator<'a> {
43    type Item = (&'a str, &'a str);
44
45    fn next(&mut self) -> Option<Self::Item> {
46        let word = self.words.next()?;
47        Some(word.split_once(':').unwrap_or((word, "")))
48    }
49}