automatons_github/resource/
visibility.rs

1use std::fmt::{Display, Formatter};
2
3use serde::{Deserialize, Serialize};
4
5/// Visibility of a resource
6///
7/// Some resources on GitHub can be made available to different groups of people. Most prominently,
8/// the visibility of repositories determines who can access a repository and its nested resources.
9/// On [github.com](https://github.com), resources can either be `public` or `private`. On hosted
10/// GitHub Enterprise servers, `internal` resources can only be access by members of the same
11/// GitHub organization.
12#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Deserialize, Serialize)]
13#[serde(rename_all = "snake_case")]
14pub enum Visibility {
15    /// Internal visibility
16    ///
17    /// This resource is visible only to people in the same organization.
18    Internal,
19
20    /// Private visibility
21    ///
22    /// This resource is hidden from the public.
23    Private,
24
25    /// Public visibility
26    ///
27    /// This resource is public.
28    Public,
29}
30
31impl Display for Visibility {
32    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
33        let string_representation = match self {
34            Visibility::Internal => "internal",
35            Visibility::Private => "private",
36            Visibility::Public => "public",
37        };
38
39        write!(f, "{}", string_representation)
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::Visibility;
46
47    #[test]
48    fn trait_deserialize() {
49        let visibility: Visibility = serde_json::from_str(r#""internal""#).unwrap();
50
51        assert!(matches!(visibility, Visibility::Internal));
52    }
53
54    #[test]
55    fn trait_display() {
56        let visibility = Visibility::Private;
57
58        assert_eq!("private", visibility.to_string());
59    }
60
61    #[test]
62    fn trait_send() {
63        fn assert_send<T: Send>() {}
64        assert_send::<Visibility>();
65    }
66
67    #[test]
68    fn trait_sync() {
69        fn assert_sync<T: Sync>() {}
70        assert_sync::<Visibility>();
71    }
72}