JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

L + Ratio

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨1f5f028

⁨src/model/user.rs⁩ - ⁨703⁩ bytes
Raw
1 use std::str::FromStr;
2
3 use serde::{Deserialize, Serialize};
4
5 use super::instance::Instance;
6
7 #[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
8 pub struct User {
9 pub username: String,
10 pub instance: Instance,
11 }
12
13 impl ToString for User {
14 fn to_string(&self) -> String {
15 format!("{}:{}", self.username, self.instance.url)
16 }
17 }
18
19 impl FromStr for User {
20 type Err = ();
21
22 fn from_str(s: &str) -> Result<Self, Self::Err> {
23 let mut colon_split = s.split(':');
24 let username = colon_split.next().unwrap().to_string();
25 let instance = Instance::from_str(colon_split.next().unwrap()).unwrap();
26
27 Ok(Self { username, instance })
28 }
29 }
30