pub trait AstrsMessage: Sized {
const URN: &'static str;
// Required methods
fn data_type() -> DataType;
fn to_record_batch(&self) -> Result<RecordBatch, DataError>;
fn from_record_batch(batch: &RecordBatch) -> Result<Self, DataError>;
// Provided methods
fn schema() -> Schema { ... }
fn type_urn() -> Result<TypeUrn, TypeUrnError> { ... }
}Expand description
A Rust type that maps onto a single-column AstRS payload (blueprint §6.1, §9.2).
See the module documentation for why this trait lives in
astrs-data and what it deliberately leaves to callers.
Required Associated Constants§
Required Methods§
Sourcefn data_type() -> DataType
fn data_type() -> DataType
The columnar layout AstrsMessage::to_record_batch produces and
AstrsMessage::from_record_batch expects.
Sourcefn to_record_batch(&self) -> Result<RecordBatch, DataError>
fn to_record_batch(&self) -> Result<RecordBatch, DataError>
Encodes one message into a one-row RecordBatch (blueprint §6.1’s
“one record batch per message”).
§Errors
A crate::DataError from whichever columnar constructor rejects
the value. Practically unreachable for a #[derive(AstrsMessage)]
impl, since the derive only emits calls that cannot disagree with
its own AstrsMessage::data_type, but the trait stays fallible for
hand-written implementors.
Sourcefn from_record_batch(batch: &RecordBatch) -> Result<Self, DataError>
fn from_record_batch(batch: &RecordBatch) -> Result<Self, DataError>
Decodes one message from a one-row RecordBatch.
§Errors
crate::DataError::MessageRowCount when batch does not hold
exactly one row, or another crate::DataError when a column’s
shape or nullability disagrees with AstrsMessage::data_type.
Provided Methods§
Sourcefn schema() -> Schema
fn schema() -> Schema
The single-column Schema wrapping AstrsMessage::data_type
under crate::DATA_COLUMN (blueprint §6.1).
Sourcefn type_urn() -> Result<TypeUrn, TypeUrnError>
fn type_urn() -> Result<TypeUrn, TypeUrnError>
Parses AstrsMessage::URN.
§Errors
Whatever TypeUrn::parse reports, wrapped through
crate::DataError::TypeUrn. A malformed constant is a programmer
error rather than a data error, but the parse is still fallible at
the type level — a #[derive(AstrsMessage)] impl’s constant has
already passed the macro’s own syntax check (see
astrs-operator-macros), so this should only ever fail for a
hand-written implementation.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".