mirror of
https://github.com/nushell/nushell.git
synced 2025-06-02 16:16:01 +02:00
Remove Record::drain
This commit is contained in:
parent
ec43f449fb
commit
a01097b11b
@ -144,7 +144,9 @@ fn drop_cols(
|
|||||||
fn drop_cols_set(val: &mut Value, head: Span, drop: usize) -> Result<HashSet<String>, ShellError> {
|
fn drop_cols_set(val: &mut Value, head: Span, drop: usize) -> Result<HashSet<String>, ShellError> {
|
||||||
if let Value::Record { val: record, .. } = val {
|
if let Value::Record { val: record, .. } = val {
|
||||||
let len = record.len().saturating_sub(drop);
|
let len = record.len().saturating_sub(drop);
|
||||||
Ok(record.drain(len..).map(|(col, _)| col).collect())
|
let set = record.columns().skip(len).cloned().collect();
|
||||||
|
record.truncate(len);
|
||||||
|
Ok(set)
|
||||||
} else {
|
} else {
|
||||||
Err(unsupported_value_error(val, head))
|
Err(unsupported_value_error(val, head))
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{ShellError, Span, Value};
|
use crate::{ShellError, Span, Value};
|
||||||
use ecow::EcoVec;
|
use ecow::EcoVec;
|
||||||
use serde::{de::Visitor, ser::SerializeMap, Deserialize, Serialize};
|
use serde::{de::Visitor, ser::SerializeMap, Deserialize, Serialize};
|
||||||
use std::{iter::FusedIterator, ops::RangeBounds};
|
use std::iter::FusedIterator;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Record {
|
pub struct Record {
|
||||||
@ -258,14 +258,14 @@ impl Record {
|
|||||||
/// assert_eq!(rec_iter.next(), Some(("a".into(), Value::test_nothing())));
|
/// assert_eq!(rec_iter.next(), Some(("a".into(), Value::test_nothing())));
|
||||||
/// assert_eq!(rec_iter.next(), None);
|
/// assert_eq!(rec_iter.next(), None);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn drain<R>(&mut self, range: R) -> Drain
|
// pub fn drain<R>(&mut self, range: R) -> Drain
|
||||||
where
|
// where
|
||||||
R: RangeBounds<usize> + Clone,
|
// R: RangeBounds<usize> + Clone,
|
||||||
{
|
// {
|
||||||
Drain {
|
// Drain {
|
||||||
iter: self.inner[(range.start_bound().cloned(), range.end_bound().cloned())].iter(),
|
// iter: self.inner.drain(range)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// Sort the record by its columns.
|
/// Sort the record by its columns.
|
||||||
///
|
///
|
||||||
@ -630,39 +630,39 @@ impl ExactSizeIterator for IntoValues {
|
|||||||
|
|
||||||
impl FusedIterator for IntoValues {}
|
impl FusedIterator for IntoValues {}
|
||||||
|
|
||||||
pub struct Drain<'a> {
|
// pub struct Drain<'a> {
|
||||||
iter: std::slice::Iter<'a, (String, Value)>,
|
// iter: std::slice::Iter<'a, (String, Value)>,
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl Iterator for Drain<'_> {
|
// impl Iterator for Drain<'_> {
|
||||||
type Item = (String, Value);
|
// type Item = (String, Value);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
// fn next(&mut self) -> Option<Self::Item> {
|
||||||
self.iter
|
// self.iter
|
||||||
.next()
|
// .next()
|
||||||
.map(|(col, val)| (col.clone(), val.clone()))
|
// .map(|(col, val)| (col.clone(), val.clone()))
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
// fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
self.iter.size_hint()
|
// self.iter.size_hint()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl DoubleEndedIterator for Drain<'_> {
|
// impl DoubleEndedIterator for Drain<'_> {
|
||||||
fn next_back(&mut self) -> Option<Self::Item> {
|
// fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
self.iter
|
// self.iter
|
||||||
.next_back()
|
// .next_back()
|
||||||
.map(|(col, val)| (col.clone(), val.clone()))
|
// .map(|(col, val)| (col.clone(), val.clone()))
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl ExactSizeIterator for Drain<'_> {
|
// impl ExactSizeIterator for Drain<'_> {
|
||||||
fn len(&self) -> usize {
|
// fn len(&self) -> usize {
|
||||||
self.iter.len()
|
// self.iter.len()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl FusedIterator for Drain<'_> {}
|
// impl FusedIterator for Drain<'_> {}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! record {
|
macro_rules! record {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user