weirdnet_agent/
identity.rs1use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
9#[serde(transparent)]
10pub struct AgentId(pub String);
11
12impl AgentId {
13 pub fn new(id: impl Into<String>) -> Self {
14 Self(id.into())
15 }
16
17 pub fn as_str(&self) -> &str {
18 &self.0
19 }
20}
21
22impl fmt::Display for AgentId {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 f.write_str(&self.0)
25 }
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
30#[serde(rename_all = "snake_case")]
31pub enum AgentKind {
32 Local,
34 Node,
36 External,
38}
39
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42pub struct AgentIdentity {
43 pub id: AgentId,
44 pub name: String,
45 pub kind: AgentKind,
46 #[serde(default, skip_serializing_if = "Option::is_none")]
48 pub node: Option<String>,
49}
50
51impl AgentIdentity {
52 pub fn new(id: impl Into<String>, name: impl Into<String>, kind: AgentKind) -> Self {
53 Self { id: AgentId::new(id), name: name.into(), kind, node: None }
54 }
55
56 pub fn with_node(mut self, node: impl Into<String>) -> Self {
57 self.node = Some(node.into());
58 self
59 }
60}