59 lines
1.4 KiB
Rust
59 lines
1.4 KiB
Rust
use derive_more::{Deref, DerefMut};
|
|
use iris::core::util::HashMap;
|
|
use openworm::rsc::DataRsc;
|
|
|
|
#[derive(Default, serde::Serialize, serde::Deserialize, Deref, DerefMut)]
|
|
pub struct AccountListV0(Vec<AccountInfoV0>);
|
|
#[derive(Clone, serde::Serialize, serde::Deserialize)]
|
|
pub struct AccountInfoV0 {
|
|
pub url: String,
|
|
pub username: String,
|
|
}
|
|
|
|
impl AccountInfoV0 {
|
|
pub fn path(&self) -> String {
|
|
self.username.clone() + "@" + &self.url
|
|
}
|
|
}
|
|
|
|
impl DataRsc for AccountListV0 {
|
|
fn name() -> &'static str {
|
|
"account_list"
|
|
}
|
|
|
|
fn parse_version(text: &str, version: u32) -> Result<Self, String> {
|
|
match version {
|
|
0 => ron::from_str(text).map_err(|e| e.to_string()),
|
|
_ => Err(format!("unknown version {version}")),
|
|
}
|
|
}
|
|
|
|
fn version() -> u32 {
|
|
0
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Default, serde::Serialize, serde::Deserialize, Deref, DerefMut)]
|
|
pub struct ServerListV0(HashMap<String, ServerInfoV0>);
|
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
|
pub struct ServerInfoV0 {
|
|
pub cert_hex: String,
|
|
}
|
|
|
|
impl DataRsc for ServerListV0 {
|
|
fn name() -> &'static str {
|
|
"server_list"
|
|
}
|
|
|
|
fn parse_version(text: &str, version: u32) -> Result<Self, String> {
|
|
match version {
|
|
0 => ron::from_str(text).map_err(|e| e.to_string()),
|
|
_ => Err(format!("unknown version {version}")),
|
|
}
|
|
}
|
|
|
|
fn version() -> u32 {
|
|
0
|
|
}
|
|
}
|