actrpc_core/action/
kind.rs1use actrpc_core_macros::DescribeValue;
2use serde::{Deserialize, Serialize};
3use std::borrow::Borrow;
4use std::fmt;
5use std::str::FromStr;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, DescribeValue)]
8#[serde(transparent)]
9pub struct ActionKind {
10 name: String,
11}
12
13impl ActionKind {
14 pub fn new(value: impl Into<String>) -> Self {
15 Self { name: value.into() }
16 }
17
18 pub fn as_str(&self) -> &str {
19 &self.name
20 }
21
22 pub fn into_string(self) -> String {
23 self.name
24 }
25}
26
27impl fmt::Display for ActionKind {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 self.name.fmt(f)
30 }
31}
32
33impl AsRef<str> for ActionKind {
34 fn as_ref(&self) -> &str {
35 self.as_str()
36 }
37}
38
39impl Borrow<str> for ActionKind {
40 fn borrow(&self) -> &str {
41 self.as_str()
42 }
43}
44
45impl From<String> for ActionKind {
46 fn from(value: String) -> Self {
47 Self::new(value)
48 }
49}
50
51impl From<&str> for ActionKind {
52 fn from(value: &str) -> Self {
53 Self::new(value)
54 }
55}
56
57impl From<ActionKind> for String {
58 fn from(value: ActionKind) -> Self {
59 value.name
60 }
61}
62
63impl From<&ActionKind> for String {
64 fn from(value: &ActionKind) -> Self {
65 value.as_str().to_owned()
66 }
67}
68
69impl FromStr for ActionKind {
70 type Err = std::convert::Infallible;
71
72 fn from_str(s: &str) -> Result<Self, Self::Err> {
73 Ok(Self::from(s))
74 }
75}