#data #type #cell

no-std ladata

A simple & modular data model

2 releases

Uses new Rust 2021

0.0.19 Jul 6, 2022
0.0.18 Jul 4, 2022

#554 in Data structures

MIT/Apache

115KB
1.5K SLoC

ladata

Crate API Lines Of Code

A simple & modular mixed data model.

See the documentation for more information.

Status

  • This is still experimental work in progress. The API can and will keep changing.
  • Currently waiting for GAT stabilization to keep improving the traits.

lib.rs:

A simple & modular mixed data model.

Overview

Units

See the [units] module for more information.

The fundamental unitary abstractions are:

  • DataCell… enums that contains both the data and the type information.
  • DataType… enums that only contains type information, not the data itself.
  • DataBare… unions that only contains the data, not the type of the data.

They implement the [DataCells], [DataTypes] and [DataBares] traits.

Each one has many concrete implementations differentiated by:

  • the maximum size of the represented data.
  • whether all the included types of data are Copy.
  • the possibility of embedding a custom type in the With variant.

For example, these are concrete parallel implementations:

  • [DataType2ByteCopy][all::DataType2ByteCopy] represents a 2-byte sized Copy type (== 1 byte).
  • [DataCell2ByteCopy][all::DataCell2ByteWith] represents the corresponding 2-Byte sized type + data (== 4 bytes).
  • [DataBare2ByteCopy][all::DataBare2ByteCopy] represents the corresponding 2-Byte sized data without the type (== 2 bytes).
  • [DataType2ByteCopyWith][all::DataCell2ByteCopyWith] represents the corresponding 2-Byte sized type, with a custom type embedded (>= 2 bytes).
  • [DataCell2ByteCopyWith][all::DataCell2ByteCopyWith] represents the corresponding 2-Byte sized type + data, with a custom type embedded (>= 4 bytes).

Note that DataBare…s are more space-efficient than DataCell…s but not as convenient to use and also unsafe to read, because they're unions. They are mostly intended to be used from collections that can store their corresponding DataType…s separately. At the moment they only support Copy types, and they can't host any custom types (lacking a With field).

Lines

See the [lines] module for more information.

The fundamental linear abstractions are:

  • DataLine… structs, based on an array [DataCell*; const usize].
  • DataLineGrow… structs, growable, based on a vector Vec<DataCell*>.
  • DataLineCompact* structs, uses DataBare* plus DataType*.

External dependencies

The standard library is enabled by default. You can remove it independently of other features, by not including the "std" feature.

The default features provide a curated selection of external types than can complement the standard Rust types.

Customizing features

  • Only no_std, without any dependencies:

    $ cargo build --no-default-features
    
  • only the standard library:

    $ cargo build --no-default-features --features=std
    
  • all the dependencies (See the full list in Cargo.toml):

    $ cargo build --features=deps_all
    

Basic usage

# use ladata::all::*;
let arr = [
    DataCell32bit::F32(3.14),
    DataCell32bit::Char('π'),
];
for c in arr {
   match c {
        DataCell32bit::F32(f) => println!("a float {f}"),
        DataCell32bit::Char(c) => println!("a char {c:?}"),
        _ => (),
    }
}

See the customize.rs example on how to use custom data types.

Status

  • This is still experimental work in progress. The API can and will keep changing.
  • Currently waiting for GAT stabilization to keep improving the traits.

Dependencies

~0–0.8MB
~18K SLoC