Struct linera_witty::hlist::HNil
source · pub struct HNil;
Expand description
Represents the right-most end of a heterogeneous list
§Examples
let h = h_cons(1, HNil);
let h = h.head;
assert_eq!(h, 1);
Implementations§
source§impl HNil
impl HNil
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of a given HList
§Examples
use frunk_core::hlist;
let h = hlist![1, "hi"];
assert_eq!(h.len(), 2);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether a given HList is empty
§Examples
use frunk_core::hlist;
let h = hlist![];
assert!(h.is_empty());
sourcepub fn prepend<H>(self, h: H) -> HCons<H, HNil>
pub fn prepend<H>(self, h: H) -> HCons<H, HNil>
Prepend an item to the current HList
§Examples
use frunk_core::hlist;
let h1 = hlist![1, "hi"];
let h2 = h1.prepend(true);
let (a, (b, c)) = h2.into_tuple2();
assert_eq!(a, true);
assert_eq!(b, 1);
assert_eq!(c, "hi");
sourcepub fn sculpt<Ts, Indices>(
self,
) -> (Ts, <HNil as Sculptor<Ts, Indices>>::Remainder)
pub fn sculpt<Ts, Indices>( self, ) -> (Ts, <HNil as Sculptor<Ts, Indices>>::Remainder)
Consume the current HList and return an HList with the requested shape.
sculpt
allows us to extract/reshape/sculpt the current HList into another shape,
provided that the requested shape’s types are are contained within the current HList.
The Indices
type parameter allows the compiler to figure out that Ts
and Self
can be morphed into each other.
§Examples
use frunk_core::{hlist, HList};
let h = hlist![9000, "joe", 41f32, true];
let (reshaped, remainder): (HList![f32, i32, &str], _) = h.sculpt();
assert_eq!(reshaped, hlist![41f32, 9000, "joe"]);
assert_eq!(remainder, hlist![true]);
sourcepub fn into_reverse(self) -> <HNil as IntoReverse>::Outputwhere
HNil: IntoReverse,
pub fn into_reverse(self) -> <HNil as IntoReverse>::Outputwhere
HNil: IntoReverse,
Reverse the HList.
§Examples
use frunk_core::hlist;
assert_eq!(hlist![].into_reverse(), hlist![]);
assert_eq!(
hlist![1, "hello", true, 42f32].into_reverse(),
hlist![42f32, true, "hello", 1],
)
sourcepub fn to_ref<'a>(&'a self) -> <HNil as ToRef<'a>>::Output
pub fn to_ref<'a>(&'a self) -> <HNil as ToRef<'a>>::Output
Return an HList where the contents are references to the original HList on which this method was called.
§Examples
use frunk_core::hlist;
assert_eq!(hlist![].to_ref(), hlist![]);
assert_eq!(hlist![1, true].to_ref(), hlist![&1, &true]);
sourcepub fn to_mut<'a>(&'a mut self) -> <HNil as ToMut<'a>>::Output
pub fn to_mut<'a>(&'a mut self) -> <HNil as ToMut<'a>>::Output
Return an HList
where the contents are mutable references
to the original HList
on which this method was called.
§Examples
use frunk_core::hlist;
assert_eq!(hlist![].to_mut(), hlist![]);
assert_eq!(hlist![1, true].to_mut(), hlist![&mut 1, &mut true]);
sourcepub fn map<F>(self, mapper: F) -> <HNil as HMappable<F>>::Output
pub fn map<F>(self, mapper: F) -> <HNil as HMappable<F>>::Output
Apply a function to each element of an HList.
This transforms some HList![A, B, C, ..., E]
into some
HList![T, U, V, ..., Z]
. A variety of types are supported
for the folder argument:
- An
hlist![]
of closures (one for each element). - A single closure (for mapping an HList that is homogenous).
- A single
Poly
.
§Examples
use frunk::HNil;
use frunk_core::hlist;
assert_eq!(HNil.map(HNil), HNil);
let h = hlist![1, false, 42f32];
// Sadly we need to help the compiler understand the bool type in our mapper
let mapped = h.to_ref().map(hlist![
|&n| n + 1,
|b: &bool| !b,
|&f| f + 1f32]);
assert_eq!(mapped, hlist![2, true, 43f32]);
// There is also a value-consuming version that passes values to your functions
// instead of just references:
let mapped2 = h.map(hlist![
|n| n + 3,
|b: bool| !b,
|f| f + 8959f32]);
assert_eq!(mapped2, hlist![4, true, 9001f32]);
sourcepub fn zip<Other>(self, other: Other) -> <HNil as HZippable<Other>>::Zipped
pub fn zip<Other>(self, other: Other) -> <HNil as HZippable<Other>>::Zipped
Zip two HLists together.
This zips a HList![A1, B1, ..., C1]
with a HList![A2, B2, ..., C2]
to make a HList![(A1, A2), (B1, B2), ..., (C1, C2)]
§Example
use frunk::HNil;
use frunk_core::hlist;
assert_eq!(HNil.zip(HNil), HNil);
let h1 = hlist![1, false, 42f32];
let h2 = hlist![true, "foo", 2];
let zipped = h1.zip(h2);
assert_eq!(zipped, hlist![
(1, true),
(false, "foo"),
(42f32, 2),
]);
sourcepub fn foldl<Folder, Acc>(
self,
folder: Folder,
acc: Acc,
) -> <HNil as HFoldLeftable<Folder, Acc>>::Outputwhere
HNil: HFoldLeftable<Folder, Acc>,
pub fn foldl<Folder, Acc>(
self,
folder: Folder,
acc: Acc,
) -> <HNil as HFoldLeftable<Folder, Acc>>::Outputwhere
HNil: HFoldLeftable<Folder, Acc>,
Perform a left fold over an HList.
This transforms some HList![A, B, C, ..., E]
into a single
value by visiting all of the elements in left-to-right order.
A variety of types are supported for the mapper argument:
- An
hlist![]
of closures (one for each element). - A single closure (for folding an HList that is homogenous).
- A single
Poly
.
The accumulator can freely change type over the course of the call.
When called with a list of N
functions, an expanded form of the
implementation with type annotations might look something like this:
let acc: Acc0 = init_value;
let acc: Acc1 = f1(acc, x1);
let acc: Acc2 = f2(acc, x2);
let acc: Acc3 = f3(acc, x3);
...
let acc: AccN = fN(acc, xN);
acc
§Examples
use frunk_core::hlist;
let nil = hlist![];
assert_eq!(nil.foldl(hlist![], 0), 0);
let h = hlist![1, false, 42f32];
let folded = h.to_ref().foldl(
hlist![
|acc, &i| i + acc,
|acc, b: &bool| if !b && acc > 42 { 9000f32 } else { 0f32 },
|acc, &f| f + acc
],
1
);
assert_eq!(42f32, folded);
// There is also a value-consuming version that passes values to your folding
// functions instead of just references:
let folded2 = h.foldl(
hlist![
|acc, i| i + acc,
|acc, b: bool| if !b && acc > 42 { 9000f32 } else { 0f32 },
|acc, f| f + acc
],
8918
);
assert_eq!(9042f32, folded2)
sourcepub fn foldr<Folder, Init>(
self,
folder: Folder,
init: Init,
) -> <HNil as HFoldRightable<Folder, Init>>::Outputwhere
HNil: HFoldRightable<Folder, Init>,
pub fn foldr<Folder, Init>(
self,
folder: Folder,
init: Init,
) -> <HNil as HFoldRightable<Folder, Init>>::Outputwhere
HNil: HFoldRightable<Folder, Init>,
Perform a right fold over an HList.
This transforms some HList![A, B, C, ..., E]
into a single
value by visiting all of the elements in reverse order.
A variety of types are supported for the mapper argument:
- An
hlist![]
of closures (one for each element). - A single closure (for folding an HList that is homogenous), taken by reference.
- A single
Poly
.
The accumulator can freely change type over the course of the call.
§Comparison to foldl
While the order of element traversal in foldl
may seem more natural,
foldr
does have its use cases, in particular when it is used to build
something that reflects the structure of the original HList (such as
folding an HList of Option
s into an Option
of an HList).
An implementation of such a function using foldl
will tend to
reverse the list, while foldr
will tend to preserve its order.
The reason for this is because foldr
performs what is known as
“structural induction;” it can be understood as follows:
- Write out the HList in terms of
h_cons
andHNil
. - Substitute each
h_cons
with a function, and substituteHNil
withinit
the list:
h_cons(x1, h_cons(x2, h_cons(x3, ...h_cons(xN, HNil)...)))
becomes:
f1( x1, f2( x2, f3( x3, ... fN( xN, init)...)))
§Examples
use frunk_core::hlist;
let nil = hlist![];
assert_eq!(nil.foldr(hlist![], 0), 0);
let h = hlist![1, false, 42f32];
let folded = h.foldr(
hlist![
|acc, i| i + acc,
|acc, b: bool| if !b && acc > 42f32 { 9000 } else { 0 },
|acc, f| f + acc
],
1f32
);
assert_eq!(9001, folded)
Trait Implementations§
source§impl<F, Acc> HFoldLeftable<F, Acc> for HNil
impl<F, Acc> HFoldLeftable<F, Acc> for HNil
source§impl<F, Init> HFoldRightable<F, Init> for HNil
impl<F, Init> HFoldRightable<F, Init> for HNil
source§impl<F, Init> HFoldRightableOwned<F, Init> for HNil
impl<F, Init> HFoldRightableOwned<F, Init> for HNil
fn real_foldr( self, f: F, i: Init, ) -> (<HNil as HFoldRightable<F, Init>>::Output, F)
source§impl HList for HNil
impl HList for HNil
source§const LEN: usize = 0usize
const LEN: usize = 0usize
source§fn static_len() -> usize
fn static_len() -> usize
source§impl<Results, UserData> InstanceWithFunction<HNil, Results> for EntrypointInstance<UserData>where
Results: FlatLayout + WasmerResults,
UserData: 'static,
impl<Results, UserData> InstanceWithFunction<HNil, Results> for EntrypointInstance<UserData>where
Results: FlatLayout + WasmerResults,
UserData: 'static,
§type Function = TypedFunction<<HNil as WasmerParameters>::ImportParameters, <Results as WasmerResults>::Results>
type Function = TypedFunction<<HNil as WasmerParameters>::ImportParameters, <Results as WasmerResults>::Results>
source§fn function_from_export(
&mut self,
export: <Self::Runtime as Runtime>::Export,
) -> Result<Option<Self::Function>, RuntimeError>
fn function_from_export( &mut self, export: <Self::Runtime as Runtime>::Export, ) -> Result<Option<Self::Function>, RuntimeError>
source§fn call(
&mut self,
function: &Self::Function,
$crate::hlist::HNil: HNil,
) -> Result<Results, RuntimeError>
fn call( &mut self, function: &Self::Function, $crate::hlist::HNil: HNil, ) -> Result<Results, RuntimeError>
function
from this instance using the specified parameters
.source§fn load_function(&mut self, name: &str) -> Result<Self::Function, RuntimeError>
fn load_function(&mut self, name: &str) -> Result<Self::Function, RuntimeError>
source§impl<Results, UserData> InstanceWithFunction<HNil, Results> for ReentrantInstance<'_, UserData>where
Results: FlatLayout + WasmerResults,
UserData: 'static,
impl<Results, UserData> InstanceWithFunction<HNil, Results> for ReentrantInstance<'_, UserData>where
Results: FlatLayout + WasmerResults,
UserData: 'static,
§type Function = TypedFunction<<HNil as WasmerParameters>::ImportParameters, <Results as WasmerResults>::Results>
type Function = TypedFunction<<HNil as WasmerParameters>::ImportParameters, <Results as WasmerResults>::Results>
source§fn function_from_export(
&mut self,
export: <Self::Runtime as Runtime>::Export,
) -> Result<Option<Self::Function>, RuntimeError>
fn function_from_export( &mut self, export: <Self::Runtime as Runtime>::Export, ) -> Result<Option<Self::Function>, RuntimeError>
source§fn call(
&mut self,
function: &Self::Function,
$crate::hlist::HNil: HNil,
) -> Result<Results, RuntimeError>
fn call( &mut self, function: &Self::Function, $crate::hlist::HNil: HNil, ) -> Result<Results, RuntimeError>
function
from this instance using the specified parameters
.source§fn load_function(&mut self, name: &str) -> Result<Self::Function, RuntimeError>
fn load_function(&mut self, name: &str) -> Result<Self::Function, RuntimeError>
source§impl IntoReverse for HNil
impl IntoReverse for HNil
type Output = HNil
source§fn into_reverse(self) -> <HNil as IntoReverse>::Output
fn into_reverse(self) -> <HNil as IntoReverse>::Output
source§impl IntoUnlabelled for HNil
impl IntoUnlabelled for HNil
Implementation for HNil
type Output = HNil
source§fn into_unlabelled(self) -> <HNil as IntoUnlabelled>::Output
fn into_unlabelled(self) -> <HNil as IntoUnlabelled>::Output
source§impl IntoValueLabelled for HNil
impl IntoValueLabelled for HNil
type Output = HNil
source§fn into_value_labelled(self) -> <HNil as IntoValueLabelled>::Output
fn into_value_labelled(self) -> <HNil as IntoValueLabelled>::Output
source§impl<TargetHead, TargetTail> JoinFlatLayouts<HCons<TargetHead, TargetTail>> for HNil
impl<TargetHead, TargetTail> JoinFlatLayouts<HCons<TargetHead, TargetTail>> for HNil
source§fn into_joined(self) -> HCons<TargetHead, TargetTail>
fn into_joined(self) -> HCons<TargetHead, TargetTail>
Target
flat layout.source§fn from_joined(_joined: HCons<TargetHead, TargetTail>) -> Self
fn from_joined(_joined: HCons<TargetHead, TargetTail>) -> Self
Target
flat layout into the current flat layout.source§impl JoinFlatLayouts<HNil> for HNil
impl JoinFlatLayouts<HNil> for HNil
source§fn into_joined(self) -> HNil
fn into_joined(self) -> HNil
Target
flat layout.source§fn from_joined(_joined: HNil) -> Self
fn from_joined(_joined: HNil) -> Self
Target
flat layout into the current flat layout.source§impl Ord for HNil
impl Ord for HNil
source§impl PartialEq for HNil
impl PartialEq for HNil
source§impl PartialOrd for HNil
impl PartialOrd for HNil
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl RegisterWitTypes for HNil
impl RegisterWitTypes for HNil
source§impl<SourceHead, SourceTail> Transmogrifier<HNil, HNil> for HCons<SourceHead, SourceTail>
impl<SourceHead, SourceTail> Transmogrifier<HNil, HNil> for HCons<SourceHead, SourceTail>
Implementation of Transmogrifier
for when the Target
is empty and the Source
is non-empty.
source§fn transmogrify(self) -> HNil
fn transmogrify(self) -> HNil
source§impl Transmogrifier<HNil, HNil> for HNil
impl Transmogrifier<HNil, HNil> for HNil
Implementation of Transmogrifier
for when the Target
is empty and the Source
is empty.
source§fn transmogrify(self) -> HNil
fn transmogrify(self) -> HNil
source§impl WasmerParameters for HNil
impl WasmerParameters for HNil
§type ImportParameters = ()
type ImportParameters = ()
§type ExportParameters = ()
type ExportParameters = ()
source§fn into_wasmer(self) -> Self::ImportParameters
fn into_wasmer(self) -> Self::ImportParameters
source§fn from_wasmer((): Self::ExportParameters) -> Self
fn from_wasmer((): Self::ExportParameters) -> Self
source§impl WasmerResults for HNil
impl WasmerResults for HNil
source§impl WasmtimeParameters for HNil
impl WasmtimeParameters for HNil
§type Parameters = ()
type Parameters = ()
source§fn into_wasmtime(self) -> Self::Parameters
fn into_wasmtime(self) -> Self::Parameters
source§fn from_wasmtime((): Self::Parameters) -> Self
fn from_wasmtime((): Self::Parameters) -> Self
source§impl WasmtimeResults for HNil
impl WasmtimeResults for HNil
source§impl WitLoad for HNil
impl WitLoad for HNil
source§fn load<Instance>(
_memory: &Memory<'_, Instance>,
_location: GuestPointer,
) -> Result<Self, RuntimeError>where
Instance: InstanceWithMemory,
fn load<Instance>(
_memory: &Memory<'_, Instance>,
_location: GuestPointer,
) -> Result<Self, RuntimeError>where
Instance: InstanceWithMemory,
location
in the guest’s memory
.source§impl WitStore for HNil
impl WitStore for HNil
source§fn store<Instance>(
&self,
_memory: &mut Memory<'_, Instance>,
_location: GuestPointer,
) -> Result<(), RuntimeError>where
Instance: InstanceWithMemory,
<Instance::Runtime as Runtime>::Memory: RuntimeMemory<Instance>,
fn store<Instance>(
&self,
_memory: &mut Memory<'_, Instance>,
_location: GuestPointer,
) -> Result<(), RuntimeError>where
Instance: InstanceWithMemory,
<Instance::Runtime as Runtime>::Memory: RuntimeMemory<Instance>,
location
in the guest’s memory
.source§fn lower<Instance>(
&self,
_memory: &mut Memory<'_, Instance>,
) -> Result<<Self::Layout as Layout>::Flat, RuntimeError>where
Instance: InstanceWithMemory,
<Instance::Runtime as Runtime>::Memory: RuntimeMemory<Instance>,
fn lower<Instance>(
&self,
_memory: &mut Memory<'_, Instance>,
) -> Result<<Self::Layout as Layout>::Flat, RuntimeError>where
Instance: InstanceWithMemory,
<Instance::Runtime as Runtime>::Memory: RuntimeMemory<Instance>,
source§impl WitType for HNil
impl WitType for HNil
§type Dependencies = HNil
type Dependencies = HNil
WitType
s that this type depends on.source§fn wit_type_name() -> Cow<'static, str>
fn wit_type_name() -> Cow<'static, str>
source§fn wit_type_declaration() -> Cow<'static, str>
fn wit_type_declaration() -> Cow<'static, str>
impl Copy for HNil
impl Eq for HNil
impl StructuralPartialEq for HNil
Auto Trait Implementations§
impl Freeze for HNil
impl RefUnwindSafe for HNil
impl Send for HNil
impl Sync for HNil
impl Unpin for HNil
impl UnwindSafe for HNil
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> CallHasher for T
impl<T> CallHasher for T
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
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<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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moresource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
source§impl<T> MockResults for T
impl<T> MockResults for T
§type Results = T
type Results = T
MockInstance
.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
impl<M, I> RuntimeMemory<&mut I> for Mwhere
M: RuntimeMemory<I>,
source§fn read<'instance>(
&self,
instance: &'instance &mut I,
location: GuestPointer,
length: u32,
) -> Result<Cow<'instance, [u8]>, RuntimeError>
fn read<'instance>( &self, instance: &'instance &mut I, location: GuestPointer, length: u32, ) -> Result<Cow<'instance, [u8]>, RuntimeError>
Reads length
bytes from memory from the provided location
.
source§fn write(
&mut self,
instance: &mut &mut I,
location: GuestPointer,
bytes: &[u8],
) -> Result<(), RuntimeError>
fn write( &mut self, instance: &mut &mut I, location: GuestPointer, bytes: &[u8], ) -> Result<(), RuntimeError>
Writes the bytes
to memory at the provided location
.