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§
Sourcefn name(&self) -> &'static str
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.
Sourcefn file(&self) -> &'static str
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.
Sourcefn schema(&self, ctx: &Context) -> Result<Schema, ApiError>
fn schema(&self, ctx: &Context) -> Result<Schema, ApiError>
Rebuilt on every read, so sibling-derived options and widths are current.
Sourcefn validate(
&self,
rows: &[Self::Row],
ctx: &Context,
) -> Result<Vec<ValidationError>, ApiError>
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§
fn parse(&self, text: &str) -> Result<Vec<Self::Row>, ParseError>
fn serialize(&self, rows: &[Self::Row]) -> Result<String, Error>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".