1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::fs;
use std::path::Path;
use anyhow::{bail, Result};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct SubInfo {
top: u32,
bottom: u32,
left: u32,
right: u32
}
impl SubInfo {
pub fn from_path(path: &Path) -> Result<Self> {
let contents = fs::read_to_string(path).expect("Failed to load file");
let extension = path.extension().unwrap().to_str().unwrap();
let sub = match extension {
"json5" => { from_json5(contents) }
"sub" => { from_sub(contents) }
_ => { bail!("No extension found for {}", extension)}
}.expect("TODO: panic message");
Ok(sub)
}
}
pub fn from_json5(contents: String) -> Result<SubInfo> {
let sub = json5::from_str::<SubInfo>(contents.as_str())?;
Ok(sub)
}
pub fn from_sub(_contents: String) -> Result<SubInfo> {
todo!()
}