bspc_rs/parser/
mod.rs

1use super::errors::ParseError;
2use crate::properties::*;
3
4use std::str::FromStr;
5
6pub mod errors;
7pub mod parse_events;
8pub mod utils;
9
10impl FromStr for Presel {
11    type Err = ParseError;
12
13    fn from_str(input: &str) -> Result<Self, Self::Err> {
14        let split: Vec<_> = input.split(' ').collect();
15
16        match split[0] {
17            "dir" => Ok(Self::Dir(split[1].parse()?)),
18            "ratio" => Ok(Self::Ratio(split[1].parse()?)),
19            "cancel" => Ok(Self::Cancel),
20            _ => Err(ParseError::ConversionFailed),
21        }
22    }
23}
24
25impl FromStr for Rectangle {
26    type Err = ParseError;
27
28    fn from_str(input: &str) -> Result<Self, Self::Err> {
29        let split: Vec<_> = input.split(&['+', 'x'][..]).collect();
30
31        if split.len() < 4 {
32            return Err(ParseError::InsufficientData);
33        }
34
35        Ok(Self {
36            width: split[0].parse()?,
37            height: split[1].parse()?,
38            x: split[2].parse()?,
39            y: split[3].parse()?,
40        })
41    }
42}
43
44// impl FromStr for Presel {
45//     type Err = ParseError;
46
47//     fn from_str(input: &str) -> Result<Self, Self::Err> {
48//         let split: Vec<_> = input.split(' ').collect();
49//     }
50// }