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

ambee/giterated

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

Update GitBackend to use new models

Type: Fix

emilia - ⁨2⁩ years ago

parent: tbd commit: ⁨f657cbe

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