Skip to main content

TableLogic

Trait TableLogic 

Source
pub trait TableLogic:
    Send
    + Sync
    + 'static {
    type Row: Serialize + DeserializeOwned + Send + Sync;

    // Required methods
    fn name(&self) -> &'static str;
    fn file(&self) -> &'static str;
    fn title(&self) -> &'static str;
    fn schema(&self, ctx: &Context) -> Result<Schema, ApiError>;
    fn validate(
        &self,
        rows: &[Self::Row],
        ctx: &Context,
    ) -> Result<Vec<ValidationError>, ApiError>;

    // Provided methods
    fn parse(&self, text: &str) -> Result<Vec<Self::Row>, ParseError> { ... }
    fn serialize(&self, rows: &[Self::Row]) -> Result<String, Error> { ... }
    fn derive(
        &self,
        _rows: &[Self::Row],
        _ctx: &Context,
    ) -> Result<Vec<Value>, ApiError> { ... }
    fn siblings(&self, _ctx: &Context) -> Result<Value, ApiError> { ... }
}
Expand description

One table’s per-repository logic.

parse and serialize default to plain JSONL, so a table whose row type serializes the way it is stored implements neither. derive and siblings default to nothing, so a table with no derived values and no cross-table data implements neither.

Required Associated Types§

Required Methods§

Source

fn name(&self) -> &'static str

The route segment and ?table= value, such as books. The names app, health, shutdown, and stop are reserved: the first three are control endpoints and the fourth is the stop subcommand, which clap takes before the positional table name.

Source

fn file(&self) -> &'static str

The file under Data/, such as Books.jsonl.

It is a bare file name: no directory separators, nothing absolute, and not . or ... Building a crate::Server over a table that names anything else panics. It must exist before the editor can open the table; the editor edits a table, it does not create one.

Source

fn title(&self) -> &'static str

The heading the shell shows, such as Books.

Source

fn schema(&self, ctx: &Context) -> Result<Schema, ApiError>

Rebuilt on every read, so sibling-derived options and widths are current.

Source

fn validate( &self, rows: &[Self::Row], ctx: &Context, ) -> Result<Vec<ValidationError>, ApiError>

Problems with the rows, each reported against the row’s one-based position in the set. A write is not refused because of them: the editor persists what it is given and shows the errors beside the cells.

Provided Methods§

Source

fn parse(&self, text: &str) -> Result<Vec<Self::Row>, ParseError>

Source

fn serialize(&self, rows: &[Self::Row]) -> Result<String, Error>

Source

fn derive( &self, _rows: &[Self::Row], _ctx: &Context, ) -> Result<Vec<Value>, ApiError>

Values the editor displays but does not store, parallelling rows index for index. A computed column reads one of the keys of each row’s object through its from.

Source

fn siblings(&self, _ctx: &Context) -> Result<Value, ApiError>

Cross-table data a bespoke editor needs. The schema-driven editor ignores it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§