Module ruststep::tables[][src]

Expand description

Handling “exchange structure graph” as tables

Since records in an exchange structure has references to other records, then consists a graph.

  • An exchange structure corresponds to a graph, we call it “exchange structure graph” here.
  • A node of graph corresponds to a record.
  • An edge of graph corresponds to a reference in a record.

Creating table from exchange structure AST

Let us consider a simple EXPRESS schema:

ENTITY a;
  x: INTEGER;
  y: INTEGER;
END_ENTITY;

ENTITY b;
  z: INTEGER;
  w: a;
END_ENTITY;

Corresponding data section in STEP file will be something like following (skip HEADER section):

DATA;
  #1 = A(1, 2);
  #2 = A(3, 4);
  #3 = B(5, #1);
  #4 = B(6, #1);
  #5 = B(7, #2);
  #6 = B(8, A((9, 10)));
ENDSEC;

In this example, #3 and #4 has reference to #1. There will exist non-exclusive reference between entity instances generally, and thus the data must be regarded as a graph.

ruststep will parse this data section into following tables:

Table (a)x (i64)y (i64)
#112
#234
Table (b)z (i64)w (a)
#35#1
#46#1
#57#2
#68A((9, 10))

Each columns are defined by EXPRESS schema. x, y, and z are specified as integer in EXPRESS, and will be treated as i64 in Rust code. The simple types in EXPRESS are mapped into Rust primitive types. The ENTITY a will be treated as a Rust struct like

struct A {
  x: i64,
  y: i64,
}

The ENTITY b has to support both reference and inline struct like as #4 and #6. For this purpose, PlaceHolder exists:

enum PlaceHolder<T> {
  /// For reference, e.g. `#1`
  Ref(Name),
  /// For inline typed parameter, e.g. `A((9, 10))`
  Owned(T),
}

Then following two Rust structs will be defined:

struct B {
  z: i64,
  w: A,
}
struct BHolder {
  z: i64,
  w: PlaceHolder<AHolder>,
}

There also a function IntoOwned::into_owned to convert a holder struct BHolder into owned struct B. AHolder will also be introduced to keep consistency. These are automated by ruststep_derive::Holder proc-macro.

Enums

Owned value or reference through entity/value id

Traits

Trait for tables which pulls an entity (T) from an entity id (u64)

Trait for a field of tables

Trait for resolving a reference through entity id

Create Table from DataSection

Functions

Helper function to implement TableInit trait