Skip to main content

Module window

Module window 

Source
Expand description

Windows of rows for rich_ext’s virtualised tables (#260).

VirtualTable fetches rows by index through VirtualRows. Rows implements it directly. A RowSource reads forward only, so RowWindow reads one pass of it and keeps just the window, the first rows (to sample column widths from) and the count: a file of any length costs one window of memory.

use rich::Console;
use rich_data::window::RowWindow;
use rich_data::{Rows, Value};

let mut rows = Rows::new(["n", "square"]);
for n in 0..100_000i64 {
    rows.push([Value::Int(n), Value::Int(n * n)]);
}
let window = RowWindow::reader()
    .offset(50_000)
    .len(2)
    .read(rows.into_source())
    .unwrap();
assert_eq!((window.start(), window.rows().len(), window.total()), (50_000, 2, Some(100_000)));

let out = Console::builder().width(40).build().render_export(&window.to_virtual_table());
assert!(out.contains("│ 50001 │ 2500100001 │"), "{out}");
assert!(out.ends_with("rows 50,001–50,002 of 100,000\n"), "{out}");

Structs§

RowWindow
One window of a RowSource, with its first rows and its count; see the module docs.
WindowReader
How RowWindow reads a source; from RowWindow::reader.