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

ambee/giterated

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

Add docs

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨51aad53

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