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")]
31#[non_exhaustive]
32pub enum AgentKind {
33 Local,
35 Node,
37 External,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
43pub struct AgentIdentity {
44 pub id: AgentId,
45 pub name: String,
46 pub kind: AgentKind,
47 #[serde(default, skip_serializing_if = "Option::is_none")]
49 pub node: Option<String>,
50}
51
52impl AgentIdentity {
53 pub fn new(id: impl Into<String>, name: impl Into<String>, kind: AgentKind) -> Self {
54 Self { id: AgentId::new(id), name: name.into(), kind, node: None }
55 }
56
57 pub fn with_node(mut self, node: impl Into<String>) -> Self {
58 self.node = Some(node.into());
59 self
60 }
61}