Doccomment cell path types
This commit is contained in:
parent
671fa24b40
commit
e228e953be
|
@ -3,16 +3,23 @@ use crate::Span;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{cmp::Ordering, fmt::Display};
|
use std::{cmp::Ordering, fmt::Display};
|
||||||
|
|
||||||
|
/// One level of acces of a [`CellPath`]
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum PathMember {
|
pub enum PathMember {
|
||||||
|
/// Accessing a member by string (i.e. columns of a table or [`Record`](crate::Record))
|
||||||
String {
|
String {
|
||||||
val: String,
|
val: String,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
/// If marked as optional don't throw an error if not found but perform default handling
|
||||||
|
/// (e.g. return `Value::Nothing`)
|
||||||
optional: bool,
|
optional: bool,
|
||||||
},
|
},
|
||||||
|
/// Accessing a member by index (i.e. row of a table or item in a list)
|
||||||
Int {
|
Int {
|
||||||
val: usize,
|
val: usize,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
/// If marked as optional don't throw an error if not found but perform default handling
|
||||||
|
/// (e.g. return `Value::Nothing`)
|
||||||
optional: bool,
|
optional: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -143,6 +150,18 @@ impl PartialOrd for PathMember {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents the potentially nested access to fields/cells of a container type
|
||||||
|
///
|
||||||
|
/// In our current implementation for table access the order of row/column is commutative.
|
||||||
|
/// This limits the number of possible rows to select in one [`CellPath`] to 1 as it could
|
||||||
|
/// otherwise be ambiguous
|
||||||
|
///
|
||||||
|
/// ```nushell
|
||||||
|
/// col1.0
|
||||||
|
/// 0.col1
|
||||||
|
/// col2
|
||||||
|
/// 42
|
||||||
|
/// ```
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
|
||||||
pub struct CellPath {
|
pub struct CellPath {
|
||||||
pub members: Vec<PathMember>,
|
pub members: Vec<PathMember>,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user