Skip to main content

Record

Enum Record 

Source
#[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 parsed Value tree. 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 enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

#[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
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§bytes: Bytes

The raw bytes.

§format: Format

Hint about the format (JSON, protobuf, etc.)

§

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

Source

pub fn raw(bytes: impl Into<Bytes>, format: Format) -> Record

Create a record from raw bytes.

Source

pub fn parsed(value: Value) -> Record

Create a record from a parsed value.

Source

pub fn is_raw(&self) -> bool

Check if this record is in raw (unparsed) form.

Source

pub fn is_parsed(&self) -> bool

Check if this record is parsed.

Source

pub fn format(&self) -> Format

Get the format hint.

For Parsed records, returns Format::VALUE.

Source

pub fn as_bytes(&self) -> Option<&Bytes>

Get raw bytes if available without serialization.

Returns None for Parsed records (would require serialization).

Source

pub fn as_value(&self) -> Option<&Value>

Get parsed value if available without parsing.

Returns None for Raw records (would require parsing).

Source

pub fn into_value(self, codec: &dyn Codec) -> Result<Value, Error>

Parse into a Value.

  • For Parsed records: returns the value (no cost).
  • For Raw records: parses the bytes using the codec.

This is where you pay the parsing cost.

Source

pub fn into_bytes( self, codec: &dyn Codec, target_format: &Format, ) -> Result<Bytes, Error>

Serialize into bytes.

  • For Raw records with matching format: returns the bytes (no cost).
  • For Raw records with different format: transcodes via Value.
  • For Parsed records: serializes using the codec.

This is where you pay the serialization cost.

Source

pub fn try_into_bytes(self, target_format: &Format) -> Result<Bytes, Record>

Try to get bytes without serialization, returning the record if not possible.

Useful when you want bytes if available, but don’t want to pay serialization cost.

Trait Implementations§

Source§

impl Clone for Record

Source§

fn clone(&self) -> Record

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Record

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Record

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Record, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Bytes> for Record

Source§

fn from(bytes: Bytes) -> Record

Converts to this type from the input type.
Source§

impl From<Value> for Record

Source§

fn from(v: Value) -> Record

Converts to this type from the input type.
Source§

impl Serialize for Record

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.