nu_protocol/value/
glob.rs1use serde::Deserialize;
2use std::fmt::Display;
3
4#[derive(Debug, Clone, Deserialize)]
7pub enum NuGlob {
8 DoNotExpand(String),
11 Expand(String),
14}
15
16impl NuGlob {
17 pub fn map(self, f: impl FnOnce(String) -> String) -> Self {
18 match self {
19 NuGlob::DoNotExpand(s) => NuGlob::DoNotExpand(f(s)),
20 NuGlob::Expand(s) => NuGlob::Expand(f(s)),
21 }
22 }
23
24 pub fn strip_ansi_string_unlikely(self) -> Self {
25 self.map(nu_utils::strip_ansi_string_unlikely)
26 }
27
28 pub fn is_expand(&self) -> bool {
29 matches!(self, NuGlob::Expand(..))
30 }
31}
32
33impl AsRef<str> for NuGlob {
34 fn as_ref(&self) -> &str {
35 match self {
36 NuGlob::DoNotExpand(s) | NuGlob::Expand(s) => s,
37 }
38 }
39}
40
41impl Display for NuGlob {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 write!(f, "{}", self.as_ref())
44 }
45}