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

ambee/giterated

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

woo

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨2d48bc0

⁨src/model/instance.rs⁩ - ⁨1096⁩ bytes
Raw
1 use std::str::FromStr;
2
3 use serde::{Deserialize, Serialize};
4 use thiserror::Error;
5
6 pub struct InstanceMeta {
7 pub url: String,
8 pub public_key: String,
9 }
10
11 /// An instance, defined by the URL it can be reached at.
12 ///
13 /// # Textual Format
14 /// An instance's textual format is its URL.
15 ///
16 /// ## Examples
17 /// For the instance `giterated.dev`, the following [`Instance`] initialization
18 /// would be valid:
19 ///
20 /// ```
21 /// let instance = Instance {
22 /// url: String::from("giterated.dev")
23 /// };
24 ///
25 /// // This is correct
26 /// assert_eq!(Instance::from_str("giterated.dev").unwrap(), instance);
27 /// ```
28 #[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
29 pub struct Instance {
30 pub url: String,
31 }
32
33 impl ToString for Instance {
34 fn to_string(&self) -> String {
35 self.url.clone()
36 }
37 }
38
39 impl FromStr for Instance {
40 type Err = InstanceParseError;
41
42 fn from_str(s: &str) -> Result<Self, Self::Err> {
43 Ok(Self { url: s.to_string() })
44 }
45 }
46
47 #[derive(Debug, Error)]
48 pub enum InstanceParseError {
49 #[error("invalid format")]
50 InvalidFormat,
51 }
52