Crate v9[][src]

v9 is a clean, easy to use, and flexible data engine.

It provides a means to implement applications using Data Oriented Design.

#[v9::table]
struct engines {
    pub cylinder_count: u8,
    pub lines_of_code: u64,
}

use v9::prelude::Universe;
let mut universe = Universe::new();

use v9::prelude::Register;
engines::Marker::register(&mut universe);

let (v9, v11) = universe.eval(|mut engines: engines::Write| {
    (
        engines.push(engines::Row {
            cylinder_count: 9,
            lines_of_code: 5000,
        }),
        engines.push(engines::Row {
            cylinder_count: 11,
            lines_of_code: std::u64::MAX,
        }),
    )
});

#[v9::table]
struct projects {
    pub name: &'static str,
    pub engine: crate::engines::Id,
}

projects::Marker::register(&mut universe);
universe.eval(|mut projects: projects::Write| {
    projects.push(projects::Row {
        name: "TOP SECRET!",
        engine: v9,
    });
    projects.push(projects::Row {
        name: "Stinky Cheese Inc!",
        engine: v11,
    });
});

universe.eval(|projects: projects::Read| {
    assert_eq!(projects.iter().count(), 2);
});

universe.eval(|mut engines: engines::Write| {
    engines.remove(v11);
});

universe.eval(|projects: projects::Read| {
    // No dangling pointers!
    assert_eq!(projects.iter().count(), 1);
});

(Another example.)

Design

A Universe works like a HashMap<TypeId, Any>. A single instance of any type can be inserted into the universe. Changes can then be made by running a Kernel. A Kernel is any closure whose arguments all implement Extract, a trait that works like fn extract(&Universe) -> Self.

Encapsulation

This crate makes an unreasonable amount of things public. It’s very intentional! It’s hard to foresee all needs; hopefully you can do something useful with them, and this is more honest than making things pub to satisfy my whims.

A serious application should provide its own interfaces to hide v9 behind.

Safety

┐(ツ)┌

My priorities are:

  1. A beautiful API.
  2. Gotta go fast:
    • Compile-times must be fast.
    • Bulk operations (via kernels) must be h*ckin’ fast.
  3. Safety.

Monkey-proofing is not a high priority. That said, you’ll probably only have trouble if you go looking for it.

If you’ve tripped over something, that we’d maybe wish didn’t compile, and it doesn’t blow up at runtime in an obvious way, then I’ll be concerned.

Modules

column

Columns and their extractions.

event

Mechanisms for responding to events.

extract

Extracting values from the Universe.

id

Ids, lists of Ids, and various iterators.

kernel

Running functions over the Universe.

linkage

Connecting tables.

lock

Low-level locking.

object

The Universe, and interacting with it as a data structure.

prelude

A tasteful set of items.

prelude_lib

An indiscriminant selection of most things.

prelude_macro

Provides a single import statement for decl_table!.

property

Singleton values.

table
util

Macros

decl_context

Extract many things at once.

decl_property

Declares a singleton property.

decl_table

Defines a table. This is the most important item in the crate!