Add environment variable and variable functions to builder
parent
830e90761e
commit
7c2545d593
@ -1,3 +1,10 @@
|
||||
use nu_protocol::ShellError;
|
||||
use thiserror::Error;
|
||||
|
||||
pub type CrateResult<T> = std::result::Result<T, CrateError>;
|
||||
|
||||
pub enum CrateError {}
|
||||
#[derive(Clone, Debug, Error)]
|
||||
pub enum CrateError {
|
||||
#[error("Shell Error {0}")]
|
||||
NuShellError(#[from] ShellError),
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
use state_builder::StateBuilder;
|
||||
|
||||
pub(crate) mod error;
|
||||
pub mod state_builder;
|
||||
pub(crate) mod utils;
|
||||
|
||||
pub type Error = error::CrateError;
|
||||
|
@ -0,0 +1,95 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use nu_protocol::{Span, Value};
|
||||
|
||||
pub trait SpanEmpty {
|
||||
fn empty() -> Self;
|
||||
}
|
||||
|
||||
impl SpanEmpty for Span {
|
||||
fn empty() -> Self {
|
||||
Span::new(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IntoValue {
|
||||
fn into_value(self) -> Value;
|
||||
}
|
||||
|
||||
impl IntoValue for Value {
|
||||
fn into_value(self) -> Value {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoValue for String {
|
||||
fn into_value(self) -> Value {
|
||||
Value::String {
|
||||
val: self,
|
||||
span: Span::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoValue for i64 {
|
||||
fn into_value(self) -> Value {
|
||||
Value::Int {
|
||||
val: self,
|
||||
span: Span::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoValue for bool {
|
||||
fn into_value(self) -> Value {
|
||||
Value::Bool {
|
||||
val: self,
|
||||
span: Span::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoValue for f64 {
|
||||
fn into_value(self) -> Value {
|
||||
Value::Float {
|
||||
val: self,
|
||||
span: Span::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoValue for char {
|
||||
fn into_value(self) -> Value {
|
||||
Value::String {
|
||||
val: self.to_string(),
|
||||
span: Span::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoValue for &'a str {
|
||||
fn into_value(self) -> Value {
|
||||
self.to_string().into_value()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoValue for HashMap<String, Value> {
|
||||
fn into_value(self) -> Value {
|
||||
let (cols, vals) = self.into_iter().unzip();
|
||||
|
||||
Value::Record {
|
||||
cols,
|
||||
vals,
|
||||
span: Span::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoValue for Vec<Value> {
|
||||
fn into_value(self) -> Value {
|
||||
Value::List {
|
||||
vals: self,
|
||||
span: Span::empty(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue