pub struct DxSection {
pub schema: Vec<String>,
pub rows: Vec<Vec<DxLlmValue>>,
}Expand description
A data section with schema-defined columns and rows.
DxSection represents tabular data in the DX LLM format. Each section
has a schema (column names) and rows of DxLlmValue data.
§LLM Format Syntax
#d(id,name,active)[ // Section 'd' with schema: id, name, active
1,Alice,+ // Row 1
2,Bob,- // Row 2
]§Examples
§Creating a Section
use serializer::llm::{DxSection, DxLlmValue};
let mut section = DxSection::new(vec![
"id".to_string(),
"name".to_string(),
"active".to_string(),
]);
// Add rows (must match schema length)
section.add_row(vec![
DxLlmValue::Num(1.0),
DxLlmValue::Str("Alice".to_string()),
DxLlmValue::Bool(true),
]).unwrap();
assert_eq!(section.row_count(), 1);
assert_eq!(section.column_count(), 3);§Error Handling
use serializer::llm::{DxSection, DxLlmValue};
let mut section = DxSection::new(vec!["a".to_string(), "b".to_string()]);
// Wrong number of columns returns an error
let result = section.add_row(vec![DxLlmValue::Num(1.0)]);
assert!(result.is_err());§Thread Safety
DxSection implements Send + Sync and can be safely shared between threads.
§See Also
DxDocument- Parent container for sectionsDxLlmValue- Value type for row data
Fields§
§schema: Vec<String>Column names from the schema.
Defines the structure of each row. All rows must have exactly
schema.len() values.
rows: Vec<Vec<DxLlmValue>>Row data.
Each row is a vector of DxLlmValue with length matching the schema.
Implementations§
Source§impl DxSection
impl DxSection
Sourcepub fn add_row(&mut self, row: Vec<DxLlmValue>) -> Result<(), String>
pub fn add_row(&mut self, row: Vec<DxLlmValue>) -> Result<(), String>
Add a row to the section
§Errors
Returns an error if the row length doesn’t match the schema length.
Sourcepub fn column_index(&self, name: &str) -> Option<usize>
pub fn column_index(&self, name: &str) -> Option<usize>
Get the zero-based column index by schema name.
Sourcepub fn column_values(&self, name: &str) -> Option<Vec<&DxLlmValue>>
pub fn column_values(&self, name: &str) -> Option<Vec<&DxLlmValue>>
Return all values from a named column.
Sourcepub fn value_by_key(
&self,
key_column: &str,
key: &str,
value_column: &str,
) -> Option<&DxLlmValue>
pub fn value_by_key( &self, key_column: &str, key: &str, value_column: &str, ) -> Option<&DxLlmValue>
Find a value by matching one column and returning another.
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Get the number of columns
Trait Implementations§
impl StructuralPartialEq for DxSection
Auto Trait Implementations§
impl Freeze for DxSection
impl RefUnwindSafe for DxSection
impl Send for DxSection
impl Sync for DxSection
impl Unpin for DxSection
impl UnsafeUnpin for DxSection
impl UnwindSafe for DxSection
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.