diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 8eb7dd566f..e792e253fc 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -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>> for Value { + fn from(input: Spanned>) -> 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 {