#[non_exhaustive]pub enum Record {
#[non_exhaustive] Raw {
bytes: Bytes,
format: Format,
},
Parsed(Value),
}Expand description
A record that can be forwarded without parsing or parsed for inspection.
This is the core abstraction for zero-copy forwarding. A Record is either:
Raw: Unparsed bytes with a format hint. Can be forwarded without parsing.Parsed: A parsedValuetree. Efficient for inspection and modification.
§Zero-Copy Forwarding
use structfs_core_store::{Record, Format};
use bytes::Bytes;
// Data comes in as raw bytes
let record = Record::raw(Bytes::from_static(b"{\"name\":\"Alice\"}"), Format::JSON);
// Forward without parsing - just pass the Record through
// No JSON parsing happens!§Lazy Parsing
use structfs_core_store::{Record, Format, Value};
use bytes::Bytes;
let record = Record::raw(Bytes::from_static(b"..."), Format::JSON);
// Only parse when you need to inspect
// let value = record.into_value(&codec)?;Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
#[non_exhaustive]Raw
Unparsed bytes with format hint.
The bytes can be forwarded without parsing. Use into_value() to
parse when you need to inspect or modify the data.
Fields
This variant is marked as non-exhaustive
Parsed(Value)
Parsed tree structure.
Efficient for inspection and modification. Use into_bytes() to
serialize when you need to send over the wire.
Implementations§
Source§impl Record
impl Record
Sourcepub fn as_bytes(&self) -> Option<&Bytes>
pub fn as_bytes(&self) -> Option<&Bytes>
Get raw bytes if available without serialization.
Returns None for Parsed records (would require serialization).
Sourcepub fn as_value(&self) -> Option<&Value>
pub fn as_value(&self) -> Option<&Value>
Get parsed value if available without parsing.
Returns None for Raw records (would require parsing).
Sourcepub fn into_value(self, codec: &dyn Codec) -> Result<Value, Error>
pub fn into_value(self, codec: &dyn Codec) -> Result<Value, Error>
Parse into a Value.
- For
Parsedrecords: returns the value (no cost). - For
Rawrecords: parses the bytes using the codec.
This is where you pay the parsing cost.
Sourcepub fn into_bytes(
self,
codec: &dyn Codec,
target_format: &Format,
) -> Result<Bytes, Error>
pub fn into_bytes( self, codec: &dyn Codec, target_format: &Format, ) -> Result<Bytes, Error>
Serialize into bytes.
- For
Rawrecords with matching format: returns the bytes (no cost). - For
Rawrecords with different format: transcodes via Value. - For
Parsedrecords: serializes using the codec.
This is where you pay the serialization cost.