Use ecow::EcowVec in Record

This commit is contained in:
Ian Manske 2024-04-22 17:35:33 -04:00
parent bed236362a
commit 16c8c6cd7d
4 changed files with 27 additions and 15 deletions

12
Cargo.lock generated
View File

@ -398,7 +398,7 @@ dependencies = [
"bitflags 2.5.0",
"cexpr",
"clang-sys",
"itertools 0.11.0",
"itertools 0.12.1",
"lazy_static",
"lazycell",
"proc-macro2",
@ -1348,6 +1348,15 @@ version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125"
[[package]]
name = "ecow"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54bfbb1708988623190a6c4dbedaeaf0f53c20c6395abd6a01feb327b3146f4b"
dependencies = [
"serde",
]
[[package]]
name = "ego-tree"
version = "0.6.2"
@ -3300,6 +3309,7 @@ dependencies = [
"byte-unit",
"chrono",
"chrono-humanize",
"ecow",
"fancy-regex",
"indexmap",
"lru",

View File

@ -31,6 +31,7 @@ serde = { workspace = true, default-features = false }
serde_json = { workspace = true, optional = true }
thiserror = "1.0"
typetag = "0.2"
ecow = { version = "0.2.2", features = ["serde"] }
[features]
plugin = [

View File

@ -110,7 +110,7 @@ pub enum Value {
internal_span: Span,
},
Record {
val: SharedCow<Record>,
val: Record,
// note: spans are being refactored out of Value
// please use .span() instead of matching this span value
#[serde(rename = "span")]

View File

@ -1,12 +1,11 @@
use std::{iter::FusedIterator, ops::RangeBounds};
use crate::{ShellError, Span, Value};
use ecow::EcoVec;
use serde::{de::Visitor, ser::SerializeMap, Deserialize, Serialize};
use std::{iter::FusedIterator, ops::RangeBounds};
#[derive(Debug, Clone, Default)]
pub struct Record {
inner: Vec<(String, Value)>,
inner: EcoVec<(String, Value)>,
}
impl Record {
@ -16,7 +15,7 @@ impl Record {
pub fn with_capacity(capacity: usize) -> Self {
Self {
inner: Vec::with_capacity(capacity),
inner: EcoVec::with_capacity(capacity),
}
}
@ -139,7 +138,7 @@ impl Record {
where
F: FnMut(&str, &Value) -> bool,
{
self.retain_mut(|k, v| keep(k, v));
self.inner.retain(|(k, v)| keep(k, v))
}
/// Remove elements in-place that do not satisfy `keep` while allowing mutation of the value.
@ -183,7 +182,8 @@ impl Record {
where
F: FnMut(&str, &mut Value) -> bool,
{
self.inner.retain_mut(|(col, val)| keep(col, val));
todo!()
// self.inner.retain_mut(|(col, val)| keep(col, val));
}
/// Truncate record to the first `len` elements.
@ -259,9 +259,10 @@ impl Record {
where
R: RangeBounds<usize> + Clone,
{
Drain {
iter: self.inner.drain(range),
}
todo!()
// Drain {
// iter: self.inner.drain(range),
// }
}
/// Sort the record by its columns.
@ -382,7 +383,7 @@ impl Extend<(String, Value)> for Record {
}
pub struct IntoIter {
iter: std::vec::IntoIter<(String, Value)>,
iter: ecow::vec::IntoIter<(String, Value)>,
}
impl Iterator for IntoIter {
@ -538,7 +539,7 @@ impl<'a> ExactSizeIterator for Columns<'a> {
impl FusedIterator for Columns<'_> {}
pub struct IntoColumns {
iter: std::vec::IntoIter<(String, Value)>,
iter: ecow::vec::IntoIter<(String, Value)>,
}
impl Iterator for IntoColumns {
@ -598,7 +599,7 @@ impl<'a> ExactSizeIterator for Values<'a> {
impl FusedIterator for Values<'_> {}
pub struct IntoValues {
iter: std::vec::IntoIter<(String, Value)>,
iter: ecow::vec::IntoIter<(String, Value)>,
}
impl Iterator for IntoValues {