Module frunk_core::labelled [] [src]

This module holds the machinery behind LabelledGeneric.

A LabelledGeneric instance is pretty much exactly the same as a Generic instance, except that the generic representation should contain information about field names.

Having a separate trait for LabelledGenerics gives us the freedom to derive both lablled and non-labelled generic type class instances for our types.

Asides from the main LabelledGeneric trait, this module holds helper methods that allow users to use LabelledGeneric without using universal function call syntax.

In addition, this module holds macro-generated enums that map to letters in field names (identifiers).

Examples

// Optionally alias our tuple that represents our type-level string
type name = (n,a,m,e);
let labelled = field![name, "Lloyd"];
assert_eq!(labelled.name, "name");
assert_eq!(labelled.value, "Lloyd")Run

A more common usage is to use LabelledGeneric to transform strucst that have mis-matched fields !

#[derive(LabelledGeneric)]
struct NewUser<'a> {
    first_name: &'a str,
    last_name: &'a str,
    age: usize,
}

// Notice that the fields are mismatched in terms of ordering
// *and* also in terms of the number of fields.
#[derive(LabelledGeneric)]
struct ShortUser<'a> {
    last_name: &'a str,
    first_name: &'a str,
}

let n_user = NewUser {
    first_name: "Joe",
    last_name: "Blow",
    age: 30,
};

// transform_from automagically sculpts the labelled generic
// representation of the source object to that of the target type
let s_user: ShortUser = transform_from(n_user); // doneRun

Structs

Field

A Label contains a type-level Name, a runtime value, and a reference to a &'static str name.

Enums

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
_0
_1
_2
_3
_4
_5
_6
_7
_8
_9
__
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z

Traits

IntoUnlabelled

Trait for turning a Field HList into an un-labelled HList

LabelledGeneric

A trait that converts from a type to a labelled generic representation

Functions

field_with_name

Returns a new Field for a given value and custom name.

from_labelled_generic

Given a labelled generic Representation of an A, returns A

into_labelled_generic

Given an A, returns its labelled generic Representation

labelled_convert_from

Converts one type into another assuming they have the same labelled generic Representation

sculpted_convert_from [
Deprecated
]

Converts from one type into another assuming that their labelled generic representations can be sculpted into each other.

transform_from

Converts from one type into another assuming that their labelled generic representations can be sculpted into each other.