#[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: RawInlineThe 32-byte representation of this value.
Implementations§
Source§impl<S: InlineEncoding> Inline<S>
impl<S: InlineEncoding> Inline<S>
Sourcepub fn new(value: RawInline) -> Self
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);Sourcepub fn validate(self) -> Result<Self, S::ValidationError>
pub fn validate(self) -> Result<Self, S::ValidationError>
Validate this value using its schema.
Sourcepub fn transmute<O>(self) -> Inline<O>where
O: InlineEncoding,
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.
Sourcepub fn as_transmute<O>(&self) -> &Inline<O>where
O: InlineEncoding,
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.
Sourcepub fn as_transmute_raw(value: &RawInline) -> &Self
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);Sourcepub fn from_inline<'a, T>(&'a self) -> Twhere
T: TryFromInline<'a, S, Error = Infallible>,
pub fn from_inline<'a, T>(&'a self) -> Twhere
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();Sourcepub fn try_from_inline<'a, T>(
&'a self,
) -> Result<T, <T as TryFromInline<'a, S>>::Error>where
T: TryFromInline<'a, S>,
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.
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§impl<T: InlineEncoding> Clone for Inline<T>
impl<T: InlineEncoding> Clone for Inline<T>
Source§impl<T: InlineEncoding> Debug for Inline<T>
impl<T: InlineEncoding> Debug for Inline<T>
Source§impl<T: InlineEncoding> Hash for Inline<T>
impl<T: InlineEncoding> Hash for Inline<T>
Source§impl<T: InlineEncoding> IntoBytes for Inline<T>
impl<T: InlineEncoding> IntoBytes for Inline<T>
Source§impl<T: InlineEncoding> KnownLayout for Inline<T>where
Self: Sized,
impl<T: InlineEncoding> KnownLayout for Inline<T>where
Self: Sized,
Source§type PointerMetadata = ()
type PointerMetadata = ()
Self. Read moreSource§fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
fn size_for_metadata(meta: Self::PointerMetadata) -> Option<usize>
Self with the given pointer
metadata. Read moreSource§impl<T: InlineEncoding> Ord for Inline<T>
impl<T: InlineEncoding> Ord for Inline<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: InlineEncoding> PartialEq for Inline<T>
impl<T: InlineEncoding> PartialEq for Inline<T>
Source§impl<T: InlineEncoding> PartialOrd for Inline<T>
impl<T: InlineEncoding> PartialOrd for Inline<T>
Source§impl<V: InlineEncoding> ToEncoded<V> for Inline<V>
impl<V: InlineEncoding> ToEncoded<V> for Inline<V>
Source§fn to_encoded(self) -> Encoded<V>
fn to_encoded(self) -> Encoded<V>
Encoded the macro absorbs.Source§impl<T: InlineEncoding> TryFromBytes for Inline<T>
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,
fn try_ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
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,
fn try_ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
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,
fn try_ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
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,
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,
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,
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,
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,
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,
Source§fn try_read_from_bytes(
source: &[u8],
) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_bytes(
source: &[u8],
) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
Source§fn try_read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
Source§fn try_read_from_suffix(
source: &[u8],
) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_suffix(
source: &[u8],
) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
Source§impl<'a, S: InlineEncoding> TryFromInline<'a, S> for Inline<S>
impl<'a, S: InlineEncoding> TryFromInline<'a, S> for Inline<S>
Source§type Error = Infallible
type Error = Infallible
Source§fn try_from_inline(v: &'a Inline<S>) -> Result<Self, Infallible>
fn try_from_inline(v: &'a Inline<S>) -> Result<Self, Infallible>
impl<T: InlineEncoding> Copy for Inline<T>
impl<T: InlineEncoding> Eq for Inline<T>
impl<T: InlineEncoding> Immutable for Inline<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> Encodes<&Inline<Handle<T>>> for T
impl<T> Encodes<&Inline<Handle<T>>> for T
Source§impl<S> Encodes<&Inline<S>> for Swhere
S: InlineEncoding,
impl<S> Encodes<&Inline<S>> for Swhere
S: InlineEncoding,
Source§impl<T> Encodes<Inline<Handle<T>>> for T
impl<T> Encodes<Inline<Handle<T>>> for T
Source§impl<S> Encodes<Inline<S>> for Swhere
S: InlineEncoding,
impl<S> Encodes<Inline<S>> for Swhere
S: InlineEncoding,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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