Skip to main content

Data

Struct Data 

Source
pub struct Data(/* private fields */);
Expand description

A named collection of tables, changed in place by patches.

Cloning is O(1) and a clone is a snapshot: apply changes only self, and every page it does not write stays shared with earlier snapshots.

let mut grid = Data::new("grid");
grid.apply(
    Patch::new()
        .axis("time", "s")
        .replace(Table::new("Bus", vec![1_u64, 2]).field("kv", vec![230.0, 115.0]))
        .replace(Table::new("Branch", Ids::count(1)).reference("from", "Bus", vec![1_u64]).reference("to", "Bus", vec![2_u64])),
)?;
grid.apply(Patch::new().append([0.0], "Bus", [("vm", vec![1.01, 0.99])]))?;

Implementations§

Source§

impl Data

Source

pub fn new(name: impl Into<Name>) -> Data

An empty dataset named name.

Source

pub fn name(&self) -> &Name

The dataset’s name.

Source

pub fn axis(&self) -> Option<(&str, &str)>

The name and unit of the axis sampled fields are recorded over.

Source

pub fn tables(&self) -> impl Iterator<Item = &Table> + '_

Every table, by name.

Source

pub fn table(&self, name: &str) -> Option<&Table>

The table named name.

Source

pub fn span(&self) -> Option<[f64; 2]>

The axis coordinates the sampled fields span.

Source

pub fn get(&self, row: &Row, field: &str) -> Option<Value>

The value of field for row; a sampled field reads its last frame.

Source

pub fn get_at(&self, row: &Row, field: &str, at: f64) -> Option<Value>

The value of field for row at axis coordinate at: the last frame at or before it.

Source

pub fn apply(&mut self, patch: impl Into<Patch>) -> Result<()>

Applies every change in patch, or none of them when one is invalid. A patch to another dataset is an error.

The error’s path names the change and part, such as patch[1].Bus.kv.

Source

pub fn to_patch(&self) -> Patch

The patch to this dataset that builds it from an empty one.

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

The dataset as bytes: the patch to it that builds it.

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Data>

A dataset from to_bytes, or any bytes of a patch to a dataset.

Source

pub fn read(bytes: &[u8], name: Option<&str>) -> Result<Data>

A dataset from bytes: latkit’s own, as to_bytes writes them, or GeoJSON, gzip-compressed or not. GeoJSON’s features become rows of tables points, lines, and polygons by their geometry, each with its geometry as field geometry and its properties as fields. name names the dataset, as GeoJSON needs; latkit’s bytes name their own unless given one.

let city = latkit::Data::read(br#"{"type": "Feature", "properties": {"name": "Hall"},
    "geometry": {"type": "Point", "coordinates": [-97.74, 30.27]}}"#, Some("city"))?;
assert_eq!(city.table("points").map(latkit::Table::len), Some(1));
Source

pub fn renamed(&self, name: impl Into<Name>) -> Data

The same tables as dataset name: another dataset, which views draw apart from this one.

Source§

impl Data

Source

pub fn describe(&self) -> Description

What the dataset holds: tables, rows, fields and their kinds, the axis and its span.

Source§

impl Data

Source

pub fn to_tiles( &self, chunk: u32, write: impl FnMut(&str, &[u8]) -> Result<()>, ) -> Result<()>

The dataset as time tiles, each file’s path and bytes handed to write: frames.json, the manifest a view’s tiles open; base.latk, the dataset with its sampled fields reading their frames but holding none; and a patch for each span of chunk entries of each level of each sampled field that holds any, at {field}/{level}/{index}.latk. A view given the manifest as Tiles fetches the spans its lines draw, at the level of detail its plot window asks, and those about the coordinate it shows; until a span lands, the span above it draws.

The manifest is written last, so a reader finding it finds every file it names.

Source§

impl Data

Source

pub async fn load( json: &str, base: &str, host: &(impl Fetch + ?Sized), ) -> Result<Data>

A dataset from its JSON, {"name": ..., "patch": [...]}: its name and the patch that builds it, as its bytes are. The patch loads as Patch::load loads one.

Source§

impl Data

Source

pub fn query(&self, query: &Query) -> Result<(Table, usize)>

The rows of a table query asks for, as a table of their own: their ids, and their fields or what the query computes, sampled fields read at its coordinate; and how many rows its filter kept, before the page. A limit picks its rows in linear time before sorting only them.

Trait Implementations§

Source§

impl Clone for Data

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Data

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl JsonSchema for Data

A dataset’s JSON document.

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

impl PartialEq for Data

Source§

fn eq(&self, other: &Data) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Freeze for Data

§

impl RefUnwindSafe for Data

§

impl Send for Data

§

impl Sync for Data

§

impl Unpin for Data

§

impl UnsafeUnpin for Data

§

impl UnwindSafe for Data

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,