meowy-webring/shared/src/names.rs

21 lines
413 B
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
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),
Err(_) => Err(NamesError::ParseError),
}
}