1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use nu_protocol::{ast::Expression, Span, Spanned};
use crate::{into_expression::IntoExpression, NewEmpty};
pub enum Argument {
Named((String, Option<Expression>)),
Positional(Expression),
}
impl Argument {
#[inline]
pub fn named<S: ToString, E: IntoExpression>(name: S, value: Option<E>) -> Self {
Self::Named((name.to_string(), value.map(|v| v.into_expression())))
}
#[inline]
pub fn positional<E: IntoExpression>(value: E) -> Self {
Self::Positional(value.into_expression())
}
pub(crate) fn into_nu_argument(self) -> nu_protocol::ast::Argument {
match self {
Argument::Named((name, value)) => nu_protocol::ast::Argument::Named((
Spanned {
item: name,
span: Span::empty(),
},
None,
value,
)),
Argument::Positional(value) => nu_protocol::ast::Argument::Positional(value),
}
}
}
pub trait IntoArgument {
fn into_argument(self) -> Argument;
}
impl<E: IntoExpression> IntoArgument for E {
#[inline]
fn into_argument(self) -> Argument {
Argument::positional(self)
}
}
impl IntoArgument for Argument {
#[inline]
fn into_argument(self) -> Argument {
self
}
}