Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Overview
rovv
is a crate to provide a "poor-man's" row-polymorphism for rust base on lens-rs
.
What is row poly?
In programming language type theory, row polymorphism is a kind of polymorphism that allows one to write programs that are polymorphic on record field types (also known as rows, hence row polymorphism).
-- wikipedia
Considering a function in PureScript:
\r -> r.x
you can pass a record into the function above
{ x: 1 }
or even
{ x: 1, y: 2, z: 3 }
That is what "row-poly" means: a record can be passed into the function above as long as it contains a field .x
.
The type of the function is:
{ x: a | l } -> a
-- The label `l` represents the rest fields of a record.
Now you can do the same(not exactly) in rust.
Usage
restrict the parameter r
contains a field .x
// &row! { x: T, .. } is ok
// &mut row! { x: T, .. } is ok
let foo = Foo
let bar = Bar
assert_eq!;
assert_eq!;
You can also describe a type may have a field:
assert_eq!;
assert_eq!;
Desugar
The function take_x
is equivalent to
In fact the row! { .. }
will be desugared to the impl trait, the placeholder of a type satisfied the lens trait.
And the dyn_row! { .. }
will be desugared to the dyn trait, the dynamic version of row!
.
>
Limitations
- Cannot pass the genreric arguments explicitly into the function when
row!
is used in argument position now, because therow!
is the impl trait. dyn_row!
will lose some polymorphism e.g.dyn_row! { x: i32, .. }
does not satisfydyn_row! { ref x: i32, .. }
, because the trait object cannot convert to the others, thought Trait1: Trait2.- Cannot move out of a field from a
dyn_row!
.
Cargo.toml
Please add the following in your Cargo.toml
[]
= "0.3"
= "0.2"
[]
= true
= true
Enjoy it!