flag_rs/
completion_item.rs1use std::borrow::Cow;
7
8#[derive(Clone, Debug)]
10pub struct CompletionItem {
11 pub value: Cow<'static, str>,
13 pub description: Option<Cow<'static, str>>,
15}
16
17impl CompletionItem {
18 #[must_use]
20 pub fn new(value: impl Into<Cow<'static, str>>) -> Self {
21 Self {
22 value: value.into(),
23 description: None,
24 }
25 }
26
27 #[must_use]
29 pub fn with_description(
30 value: impl Into<Cow<'static, str>>,
31 desc: impl Into<Cow<'static, str>>,
32 ) -> Self {
33 Self {
34 value: value.into(),
35 description: Some(desc.into()),
36 }
37 }
38
39 #[must_use]
41 pub fn description_or_empty(&self) -> &str {
42 self.description.as_deref().unwrap_or("")
43 }
44}
45
46impl From<&'static str> for CompletionItem {
47 fn from(value: &'static str) -> Self {
48 Self::new(value)
49 }
50}
51
52impl From<String> for CompletionItem {
53 fn from(value: String) -> Self {
54 Self::new(value)
55 }
56}
57
58impl From<(&'static str, &'static str)> for CompletionItem {
59 fn from((value, desc): (&'static str, &'static str)) -> Self {
60 Self::with_description(value, desc)
61 }
62}