gitlab_client/common/
namespace.rs

1use compact_str::CompactString;
2use url::Url;
3
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub struct NamespaceId(u64);
7
8impl NamespaceId {
9  pub const fn new(id: u64) -> Self {
10    Self(id)
11  }
12
13  pub const fn into_u64(self) -> u64 {
14    self.0
15  }
16
17  /// Calls `f` with the string representation of this id as an argument.
18  #[inline]
19  pub fn with_str<R, F>(self, f: F) -> R
20    where
21      F: for<'a> FnOnce(&'a str) -> R,
22  {
23    let mut buf = ::itoa::Buffer::new();
24    f(buf.format(self.0))
25  }
26}
27
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
30pub struct Namespace {
31  pub id: NamespaceId,
32  pub name: CompactString,
33  pub path: CompactString,
34  pub kind: NamespaceKind,
35  pub full_path: CompactString,
36  pub parent_id: Option<NamespaceId>,
37  pub web_url: Url,
38  pub avatar_url: Option<CompactString>,
39}
40
41#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
42#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
43pub enum NamespaceKind {
44  #[cfg_attr(feature = "serde", serde(rename = "group"))]
45  Group,
46  #[cfg_attr(feature = "serde", serde(rename = "user"))]
47  User,
48}