mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +01:00
impl Value::Record from HashMap<String, Value>
This commit is contained in:
parent
1ea124a65b
commit
8fee0b32e7
@ -11,10 +11,11 @@ use serde::{Deserialize, Serialize};
|
||||
pub use stream::*;
|
||||
pub use unit::*;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::{cmp::Ordering, fmt::Debug};
|
||||
|
||||
use crate::ast::{CellPath, PathMember};
|
||||
use crate::{span, BlockId, Span, Type};
|
||||
use crate::{span, BlockId, Span, Spanned, Type};
|
||||
|
||||
use crate::ShellError;
|
||||
|
||||
@ -1032,6 +1033,23 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a Value::Record from a spanned hashmap
|
||||
impl From<Spanned<HashMap<String, Value>>> for Value {
|
||||
fn from(input: Spanned<HashMap<String, Value>>) -> Self {
|
||||
let span = input.span;
|
||||
let (cols, vals) = input
|
||||
.item
|
||||
.into_iter()
|
||||
.fold((vec![], vec![]), |mut acc, (k, v)| {
|
||||
acc.0.push(k);
|
||||
acc.1.push(v);
|
||||
acc
|
||||
});
|
||||
|
||||
Value::Record { cols, vals, span }
|
||||
}
|
||||
}
|
||||
|
||||
/// Format a duration in nanoseconds into a string
|
||||
pub fn format_duration(duration: i64) -> String {
|
||||
let (sign, duration) = if duration >= 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user