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
47
48
49
50
51
52
53
54
mod fetch;
mod parse;
use crate::{Error, response::StcpResponse};
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use core::fmt;
#[derive(Deserialize, Serialize, Debug, PartialEq)]
pub struct Code(pub String);
impl From<&str> for Code {
fn from(string: &str) -> Self {
Code(string.to_string())
}
}
impl Display for Code {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}", &self.0)
}
}
#[derive(Deserialize, Serialize, Debug, PartialEq)]
pub struct PubCode(pub String);
#[derive(Deserialize, Serialize, Debug, PartialEq)]
pub struct Line {
pub accessibility: u8,
pub code: Code,
#[serde(rename = "pubcode")]
pub pub_code: PubCode,
pub description: String,
}
type LinesResponse = StcpResponse<Line>;
pub fn fetch_lines() -> Result<Vec<Line>, Error> {
let json = fetch::fetch_lines()?;
let lines = parse::parse_lines(&json)?;
Ok(lines.records)
}