2023-07-01 05:11:44 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2023-07-01 04:43:18 +00:00
|
|
|
|
2023-07-01 05:11:44 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
2023-07-01 04:43:18 +00:00
|
|
|
pub struct Site {
|
|
|
|
pub url: String,
|
|
|
|
pub name: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum NamesError {
|
|
|
|
FileAccessError,
|
|
|
|
ParseError,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn load_names(names: String) -> Result<Vec<Site>, NamesError> {
|
|
|
|
match serde_json::from_str::<Vec<Site>>(&names) {
|
|
|
|
Ok(content) => Ok(content),
|
2023-07-01 05:11:44 +00:00
|
|
|
Err(_) => Err(NamesError::ParseError),
|
2023-07-01 04:43:18 +00:00
|
|
|
}
|
|
|
|
}
|