Skip to main content

Inline

Struct Inline 

Source
#[repr(transparent)]
pub struct Inline<T: InlineEncoding> { pub raw: RawInline, /* private fields */ }
Expand description

A value is a 32-byte array that can be (de)serialized as a Rust type. The schema type parameter is an abstract type that represents the meaning and valid bit patterns of the bytes.

§Example

use triblespace_core::prelude::*;
use inlineencodings::R256;
use num_rational::Ratio;

let ratio = Ratio::new(1, 2);
let value: Inline<R256> = R256::inline_from(ratio);
let ratio2: Ratio<i128> = value.try_from_inline().unwrap();
assert_eq!(ratio, ratio2);

Fields§

§raw: RawInline

The 32-byte representation of this value.

Implementations§

Source§

impl<S: InlineEncoding> Inline<S>

Source

pub fn new(value: RawInline) -> Self

Create a new value from a 32-byte array.

§Example
use triblespace_core::inline::{Inline, InlineEncoding};
use triblespace_core::inline::encodings::UnknownInline;

let bytes = [0; 32];
let value = Inline::<UnknownInline>::new(bytes);
Source

pub fn validate(self) -> Result<Self, S::ValidationError>

Validate this value using its schema.

Source

pub fn is_valid(&self) -> bool

Check if this value conforms to its schema.

Source

pub fn transmute<O>(self) -> Inline<O>
where O: InlineEncoding,

Transmute a value from one schema type to another. This is a safe operation, as the bytes are not changed. The schema type is only changed in the type system. This is a zero-cost operation. This is useful when you have a value with an abstract schema type, but you know the concrete schema type.

Source

pub fn as_transmute<O>(&self) -> &Inline<O>
where O: InlineEncoding,

Transmute a value reference from one schema type to another. This is a safe operation, as the bytes are not changed. The schema type is only changed in the type system. This is a zero-cost operation. This is useful when you have a value reference with an abstract schema type, but you know the concrete schema type.

Source

pub fn as_transmute_raw(value: &RawInline) -> &Self

Transmute a raw value reference to a value reference.

§Example
use triblespace_core::inline::{Inline, InlineEncoding};
use triblespace_core::inline::encodings::UnknownInline;
use std::borrow::Borrow;

let bytes = [0; 32];
let value: Inline<UnknownInline> = Inline::new(bytes);
let value_ref: &Inline<UnknownInline> = &value;
let raw_value_ref: &[u8; 32] = value_ref.borrow();
let value_ref2: &Inline<UnknownInline> = Inline::as_transmute_raw(raw_value_ref);
assert_eq!(&value, value_ref2);
Source

pub fn from_inline<'a, T>(&'a self) -> T
where T: TryFromInline<'a, S, Error = Infallible>,

Deserialize a value with an abstract schema type to a concrete Rust type.

This method only works for infallible conversions (where Error = Infallible). For fallible conversions, use the Inline::try_from_inline method.

§Example
use triblespace_core::prelude::*;
use inlineencodings::F64;

let value: Inline<F64> = (3.14f64).to_inline();
let concrete: f64 = value.from_inline();
Source

pub fn try_from_inline<'a, T>( &'a self, ) -> Result<T, <T as TryFromInline<'a, S>>::Error>
where T: TryFromInline<'a, S>,

Deserialize a value with an abstract schema type to a concrete Rust type.

This method returns an error if the conversion is not possible. This might happen if the bytes are not valid for the schema type or if the rust type can’t represent the specific value of the schema type, e.g. if the schema type is a fractional number and the rust type is an integer.

For infallible conversions, use the Inline::from_inline method.

§Example
use triblespace_core::prelude::*;
use inlineencodings::R256;
use num_rational::Ratio;

let value: Inline<R256> = R256::inline_from(Ratio::new(1, 2));
let concrete: Result<Ratio<i128>, _> = value.try_from_inline();

Trait Implementations§

Source§

impl<S> AsRef<Inline<Handle<S>>> for Blob<S>

Blob<S> borrows as the Inline<Handle<S>> that references it.

Models the heavy/lightweight duality at the type system level: a Blob<S> IS a content-addressed value, and its Handle<S> is the 32-byte reference form. Coercing a &Blob<S> to a &Inline<Handle<S>> is free — the handle is stored as a field — so code that wants to pass the lightweight reference around (e.g. inserting into a trible, sending over the network) can just blob.as_ref() instead of &blob.get_handle().

Source§

fn as_ref(&self) -> &Inline<Handle<S>>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<S: InlineEncoding> Borrow<[u8; 32]> for Inline<S>

Source§

fn borrow(&self) -> &RawInline

Immutably borrows from an owned value. Read more
Source§

impl<T: InlineEncoding> Clone for Inline<T>

Source§

fn clone(&self) -> Self

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<T: InlineEncoding> Debug for Inline<T>

Source§

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

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

impl<T: BlobEncoding> From<Inline<Handle<T>>> for Inline<Hash<Blake3>>

Source§

fn from(value: Inline<Handle<T>>) -> Self

Converts to this type from the input type.
Source§

impl<T: BlobEncoding> From<Inline<Hash<Blake3>>> for Inline<Handle<T>>

Source§

fn from(value: Inline<Hash<Blake3>>) -> Self

Converts to this type from the input type.
Source§

impl<T: InlineEncoding> Hash for Inline<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: InlineEncoding> IntoBytes for Inline<T>

Source§

fn as_bytes(&self) -> &[u8]
where Self: Immutable,

Gets the bytes of this value. Read more
Source§

fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to dst. Read more
Source§

fn write_to_prefix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the prefix of dst. Read more
Source§

fn write_to_suffix( &self, dst: &mut [u8], ) -> Result<(), SizeError<&Self, &mut [u8]>>
where Self: Immutable,

Writes a copy of self to the suffix of dst. Read more
Source§

impl<T: InlineEncoding> KnownLayout for Inline<T>
where Self: Sized,

Source§

type PointerMetadata = ()

The type of metadata stored in a pointer to Self. Read more
Source§

fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>

Computes the size of an object of type Self with the given pointer metadata. Read more
Source§

impl<T: InlineEncoding> Ord for Inline<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: InlineEncoding> PartialEq for Inline<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: InlineEncoding> PartialOrd for Inline<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<V: InlineEncoding> ToEncoded<V> for Inline<V>

Source§

fn to_encoded(self) -> Encoded<V>

Produce the Encoded the macro absorbs.
Source§

impl<T: InlineEncoding> TryFromBytes for Inline<T>

Source§

fn try_ref_from_bytes( source: &[u8], ) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the given source as a &Self. Read more
Source§

fn try_ref_from_prefix( source: &[u8], ) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the prefix of the given source as a &Self. Read more
Source§

fn try_ref_from_suffix( source: &[u8], ) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: KnownLayout + Immutable,

Attempts to interpret the suffix of the given source as a &Self. Read more
Source§

fn try_mut_from_bytes( bytes: &mut [u8], ) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the given source as a &mut Self without copying. Read more
Source§

fn try_mut_from_prefix( source: &mut [u8], ) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the prefix of the given source as a &mut Self. Read more
Source§

fn try_mut_from_suffix( source: &mut [u8], ) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
where Self: KnownLayout + IntoBytes,

Attempts to interpret the suffix of the given source as a &mut Self. Read more
Source§

fn try_read_from_bytes( source: &[u8], ) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read the given source as a Self. Read more
Source§

fn try_read_from_prefix( source: &[u8], ) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read a Self from the prefix of the given source. Read more
Source§

fn try_read_from_suffix( source: &[u8], ) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
where Self: Sized,

Attempts to read a Self from the suffix of the given source. Read more
Source§

impl<'a, S: InlineEncoding> TryFromInline<'a, S> for Inline<S>

Source§

type Error = Infallible

The error type returned when the conversion fails.
Source§

fn try_from_inline(v: &'a Inline<S>) -> Result<Self, Infallible>

Convert the Inline with a specific schema type to the Rust type.
Source§

impl<T: InlineEncoding> Copy for Inline<T>

Source§

impl<T: InlineEncoding> Eq for Inline<T>

Source§

impl<T: InlineEncoding> Immutable for Inline<T>

Source§

impl<T: InlineEncoding> Unaligned for Inline<T>

Auto Trait Implementations§

§

impl<T> Freeze for Inline<T>

§

impl<T> RefUnwindSafe for Inline<T>
where T: RefUnwindSafe,

§

impl<T> Send for Inline<T>
where T: Send,

§

impl<T> Sync for Inline<T>
where T: Sync,

§

impl<T> Unpin for Inline<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Inline<T>

§

impl<T> UnwindSafe for Inline<T>
where T: UnwindSafe,

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> Encodes<&Inline<Handle<T>>> for T

Source§

type Output = Inline<Handle<T>>

The concrete form this source produces when encoded for this schema. Inline<Self> for inline encodings, Blob<Self> for blob encodings, or Inline<Handle<Self>> for the precomputed-handle case where Self: BlobEncoding.
Source§

fn encode(source: &Inline<Handle<T>>) -> Inline<Handle<T>>

Run the encoding.
Source§

impl<S> Encodes<&Inline<S>> for S
where S: InlineEncoding,

Source§

type Output = Inline<S>

The concrete form this source produces when encoded for this schema. Inline<Self> for inline encodings, Blob<Self> for blob encodings, or Inline<Handle<Self>> for the precomputed-handle case where Self: BlobEncoding.
Source§

fn encode(source: &Inline<S>) -> Inline<S>

Run the encoding.
Source§

impl<T> Encodes<Inline<Handle<T>>> for T

Source§

type Output = Inline<Handle<T>>

The concrete form this source produces when encoded for this schema. Inline<Self> for inline encodings, Blob<Self> for blob encodings, or Inline<Handle<Self>> for the precomputed-handle case where Self: BlobEncoding.
Source§

fn encode(source: Inline<Handle<T>>) -> Inline<Handle<T>>

Run the encoding.
Source§

impl<S> Encodes<Inline<S>> for S
where S: InlineEncoding,

Source§

type Output = Inline<S>

The concrete form this source produces when encoded for this schema. Inline<Self> for inline encodings, Blob<Self> for blob encodings, or Inline<Handle<Self>> for the precomputed-handle case where Self: BlobEncoding.
Source§

fn encode(source: Inline<S>) -> Inline<S>

Run the encoding.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<S, T> IntoBlob<S> for T
where S: BlobEncoding, T: IntoEncoded<S, Output = Blob<S>>,

Source§

fn to_blob(self) -> Blob<S>
where Self: Sized,

Convert directly to Blob<S>.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<S, T> IntoEncoded<S> for T
where S: Encodes<T>,

Source§

type Output = <S as Encodes<T>>::Output

The concrete form this source produces.
Source§

fn into_encoded(self) -> <T as IntoEncoded<S>>::Output

Run the conversion.
Source§

impl<S, T> IntoInline<S> for T
where S: InlineEncoding, T: IntoEncoded<S, Output = Inline<S>>,

Source§

fn to_inline(self) -> Inline<S>
where Self: Sized,

Convert directly to Inline<S>.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V