diff --git a/Cargo.toml b/Cargo.toml index 21100f1b..416e0bcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "superstruct" -version = "0.5.0" +version = "0.6.0" edition = "2021" description = "Versioned data types with minimal boilerplate" license = "Apache-2.0" diff --git a/book/src/codegen/enum.md b/book/src/codegen/enum.md index 9d7e96bf..5f1b4907 100644 --- a/book/src/codegen/enum.md +++ b/book/src/codegen/enum.md @@ -63,3 +63,8 @@ are described [here](./ref-and-refmut.md). * `to_ref` returning `{BaseName}Ref`. * `to_mut` returning `{BaseName}RefMut`. +## `From` implementations + +The top-level enum has `From` implementations for converting (owned) variant structs, i.e. + +* `impl From<{VariantStruct}> for {BaseName}` for all variants diff --git a/book/src/codegen/ref-and-refmut.md b/book/src/codegen/ref-and-refmut.md index b25e51f7..a655d82b 100644 --- a/book/src/codegen/ref-and-refmut.md +++ b/book/src/codegen/ref-and-refmut.md @@ -39,8 +39,18 @@ reference to a `MyStruct` in order to construct: a reference to a single variant ## Trait Implementations +### `Copy` + Each `Ref` type is `Copy`, just like an ordinary `&T`. +### `From` + +The `Ref` type has `From` implementations that allow converting from references to variants +or references to the top-level enum type, i.e. + +- `impl From<&'a {VariantStruct}> for {BaseName}Ref<'a>` for all variants. +- `impl From<&'a {BaseName}> for {BaseName}Ref<'a>` (same as `to_ref()`). + ## Example Please see [`examples/nested.rs`](../rustdoc/src/nested/nested.rs.html) and its