rig_core/completion/
handle.rs1use std::{fmt, sync::Arc};
11
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
17#[serde(transparent)]
18pub struct ModelRef(Arc<str>);
19
20impl ModelRef {
21 pub fn new(label: impl Into<Arc<str>>) -> Self {
23 Self(label.into())
24 }
25
26 pub fn as_str(&self) -> &str {
28 &self.0
29 }
30}
31
32impl std::ops::Deref for ModelRef {
33 type Target = str;
34
35 fn deref(&self) -> &str {
36 &self.0
37 }
38}
39
40impl AsRef<str> for ModelRef {
41 fn as_ref(&self) -> &str {
42 &self.0
43 }
44}
45
46impl fmt::Display for ModelRef {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 f.write_str(&self.0)
49 }
50}
51
52impl From<&str> for ModelRef {
53 fn from(label: &str) -> Self {
54 Self(Arc::from(label))
55 }
56}
57
58impl From<String> for ModelRef {
59 fn from(label: String) -> Self {
60 Self(Arc::from(label))
61 }
62}
63
64impl From<Arc<str>> for ModelRef {
65 fn from(label: Arc<str>) -> Self {
66 Self(label)
67 }
68}
69
70impl From<ModelRef> for String {
71 fn from(label: ModelRef) -> Self {
72 label.0.to_string()
73 }
74}
75
76impl PartialEq<str> for ModelRef {
77 fn eq(&self, other: &str) -> bool {
78 &*self.0 == other
79 }
80}
81
82impl PartialEq<&str> for ModelRef {
83 fn eq(&self, other: &&str) -> bool {
84 &*self.0 == *other
85 }
86}