Skip to content

Commit

Permalink
[Build] Update to 2021 edition (#200)
Browse files Browse the repository at this point in the history
Co-authored-by: andrzej.gluszak <[email protected]>
  • Loading branch information
agluszak and andrzej.gluszak authored Sep 18, 2022
1 parent 09a3d4f commit 58a399d
Show file tree
Hide file tree
Showing 30 changed files with 242 additions and 241 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ benches-variable

# VSCode:

.vscode/
.vscode/

# IntelliJ:
.idea
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frunk"
edition = "2018"
edition = "2021"
version = "0.4.0"
authors = ["Lloyd <[email protected]>"]
description = "Frunk provides developers with a number of functional programming tools like HList, Coproduct, Generic, LabelledGeneric, Validated, Monoid, Semigroup and friends."
Expand Down
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ Statically typed heterogeneous lists.

First, let's enable `hlist`:
```rust
#[macro_use] extern crate frunk; // allows us to use the handy hlist! macro
use frunk::{HNil, HCons};
use frunk::{HNil, HCons, hlist};
```

Some basics:
Expand Down Expand Up @@ -170,10 +169,6 @@ Here are some examples:
#### HList ⇄ Struct

```rust
#[macro_use] // for the hlist macro
extern crate frunk;
extern crate frunk_core;

#[derive(Generic, Debug, PartialEq)]
struct Person<'a> {
first_name: &'a str,
Expand Down Expand Up @@ -308,9 +303,6 @@ As usual, the goal with Frunk is to do this:
Here is an example:

```rust
#[macro_use]
extern crate frunk_core;

use frunk::labelled::Transmogrifier;

#[derive(LabelledGeneric)]
Expand Down Expand Up @@ -505,7 +497,6 @@ to take a look at `Coproduct`. In Rust, thanks to `enum`, you could potentially
want a sum type to do this, but there is a light-weight way of doing it through Frunk:

```rust
#[macro_use] extern crate frunk; // for the Coprod! type macro
use frunk::prelude::*; // for the fold method

// Declare the types we want in our Coproduct
Expand Down Expand Up @@ -548,7 +539,6 @@ best by [the Cats project](http://typelevel.org/cats/datatypes/validated.html)).

To use `Validated`, first:
```rust
#[macro_use] extern crate frunk; // allows us to use the handy hlist! macro
use frunk::prelude::*; // for Result::into_validated
```

Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frunk_core"
edition = "2018"
edition = "2021"
version = "0.4.0"
authors = ["Lloyd <[email protected]>"]
description = "Frunk core provides developers with HList, Coproduct, LabelledGeneric and Generic"
Expand Down
57 changes: 33 additions & 24 deletions core/src/coproduct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
//! Think of "Coproduct" as ad-hoc enums; allowing you to do something like this
//!
//! ```
//! #[macro_use]
//! extern crate frunk;
//!
//! # fn main() {
//! # use frunk_core::Coprod;
//! // For simplicity, assign our Coproduct type to a type alias
//! // This is purely optional.
//! type I32Bool = Coprod!(i32, bool);
Expand Down Expand Up @@ -40,7 +38,7 @@
//! Or, if you want to "fold" over all possible values of a coproduct
//!
//! ```
//! # #[macro_use] extern crate frunk;
//! # use frunk_core::{hlist, poly_fn, Coprod};
//! # fn main() {
//! # type I32Bool = Coprod!(i32, bool);
//! # let co1 = I32Bool::inject(3);
Expand Down Expand Up @@ -74,6 +72,8 @@
use crate::hlist::{HCons, HNil};
use crate::indices::{Here, There};
use crate::traits::{Func, Poly, ToMut, ToRef};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Enum type representing a Coproduct. Think of this as a Result, but capable
/// of supporting any arbitrary number of types instead of just 2.
Expand All @@ -84,8 +84,9 @@ use crate::traits::{Func, Poly, ToMut, ToRef};
/// # Examples
///
/// ```
/// # #[macro_use] extern crate frunk;
/// # fn main() {
/// use frunk_core::Coprod;
///
/// type I32Bool = Coprod!(i32, bool);
/// let co1 = I32Bool::inject(3);
/// let get_from_1a: Option<&i32> = co1.get();
Expand Down Expand Up @@ -130,9 +131,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// # Example
///
/// ```
/// # #[macro_use] extern crate frunk;
/// # fn main() {
/// use frunk::Coproduct;
/// use frunk_core::Coprod;
///
/// type I32F32 = Coprod!(i32, f32);
///
Expand Down Expand Up @@ -172,8 +173,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// # Example
///
/// ```
/// # #[macro_use] extern crate frunk;
/// # fn main() {
/// use frunk_core::Coprod;
///
/// type I32F32 = Coprod!(i32, f32);
///
/// // You can let type inference find the desired type:
Expand Down Expand Up @@ -203,8 +205,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// # Example
///
/// ```
/// # #[macro_use] extern crate frunk;
/// # fn main() {
/// use frunk_core::Coprod;
///
/// type I32F32 = Coprod!(i32, f32);
///
/// // You can let type inference find the desired type:
Expand Down Expand Up @@ -238,8 +241,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// Basic usage:
///
/// ```
/// # #[macro_use] extern crate frunk;
/// # fn main() {
/// use frunk_core::Coprod;
///
/// type I32F32 = Coprod!(i32, f32);
/// type I32 = Coprod!(i32); // remainder after uninjecting f32
/// type F32 = Coprod!(f32); // remainder after uninjecting i32
Expand Down Expand Up @@ -268,8 +272,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// Chaining calls for an exhaustive match:
///
/// ```rust
/// # #[macro_use] extern crate frunk;
/// # fn main() {
/// use frunk_core::Coprod;
///
/// type I32F32 = Coprod!(i32, f32);
///
/// // Be aware that this particular example could be
Expand Down Expand Up @@ -318,10 +323,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// Basic usage:
///
/// ```
/// # #[macro_use] extern crate frunk;
/// use ::frunk::Coproduct;
///
/// # fn main() {
/// use frunk_core::Coprod;
///
/// type I32BoolF32 = Coprod!(i32, bool, f32);
/// type I32F32 = Coprod!(i32, f32);
///
Expand All @@ -347,10 +351,10 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// with the advantage that it can remove more than one type at a time:
///
/// ```
/// # #[macro_use] extern crate frunk;
/// use frunk::Coproduct;
///
/// # fn main() {
/// use frunk_core::{Coprod, hlist};
/// use frunk_core::coproduct::Coproduct;
///
/// fn handle_stringly_things(co: Coprod!(&'static str, String)) -> String {
/// co.fold(hlist![
/// |s| format!("&str {}", s),
Expand Down Expand Up @@ -429,8 +433,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// # Example
///
/// ```
/// # #[macro_use] extern crate frunk;
/// # fn main() {
/// use frunk_core::Coprod;
///
/// type I32BoolF32 = Coprod!(i32, bool, f32);
/// type BoolI32 = Coprod!(bool, i32);
///
Expand Down Expand Up @@ -460,8 +465,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// consuming the coproduct:
///
/// ```
/// # #[macro_use] extern crate frunk; fn main() {
/// # fn main() {
/// use frunk::Coproduct;
/// use frunk_core::Coprod;
///
/// let co: Coprod!(i32, bool, String) = Coproduct::inject(true);
///
Expand All @@ -484,8 +490,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// consuming the coproduct:
///
/// ```
/// # #[macro_use] extern crate frunk; fn main() {
/// # fn main() {
/// use frunk::Coproduct;
/// use frunk_core::Coprod;
///
/// let mut co: Coprod!(i32, bool, String) = Coproduct::inject(true);
///
Expand Down Expand Up @@ -513,8 +520,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// # Example
///
/// ```
/// # #[macro_use] extern crate frunk;
/// # fn main() {
/// use frunk_core::{Coprod, hlist};
///
/// type I32F32StrBool = Coprod!(i32, f32, bool);
///
/// let co1 = I32F32StrBool::inject(3);
Expand All @@ -534,9 +542,9 @@ impl<Head, Tail> Coproduct<Head, Tail> {
/// handlers for the types in your Coproduct.
///
/// ```
/// # #[macro_use] extern crate frunk;
/// # fn main() {
/// use frunk::{Poly, Func};
/// use frunk_core::Coprod;
///
/// type I32F32StrBool = Coprod!(i32, f32, bool);
///
Expand Down Expand Up @@ -1040,7 +1048,7 @@ mod tests {
let co1 = I32F32StrBool::inject(3);
let folded = co1.fold(Poly(P));

assert_eq!(folded, false);
assert!(!folded);
}

#[test]
Expand Down Expand Up @@ -1117,7 +1125,7 @@ mod tests {
assert!(res.is_err());

if false {
#[allow(unreachable_code)]
#[allow(unreachable_code, clippy::diverging_sub_expression)]
{
// ...including CNil.
#[allow(unused)]
Expand All @@ -1143,7 +1151,7 @@ mod tests {
fn test_coproduct_embed() {
// CNil can be embedded into any coproduct.
if false {
#[allow(unreachable_code)]
#[allow(unreachable_code, clippy::diverging_sub_expression)]
{
#[allow(unused)]
let cnil: CNil = panic!();
Expand Down Expand Up @@ -1175,6 +1183,7 @@ mod tests {
assert_eq!(out_c, Coproduct::Inr(Coproduct::Inr(Coproduct::Inl(C))));
}

#[allow(clippy::upper_case_acronyms)]
{
// Multiple variants can resolve to the same output w/o type annotations
type ABC = Coprod!(A, B, C);
Expand Down
6 changes: 2 additions & 4 deletions core/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
//! # Examples
//!
//! ```rust
//! #[macro_use] extern crate frunk;
//! #[macro_use] extern crate frunk_core;
//! use frunk::Generic;
//!
//! # fn main() {
//! #[derive(Generic)]
Expand Down Expand Up @@ -50,8 +49,7 @@
/// # Examples
///
/// ```rust
/// #[macro_use] extern crate frunk;
/// #[macro_use] extern crate frunk_core;
/// use frunk::Generic;
///
/// # fn main() {
/// #[derive(Generic)]
Expand Down
Loading

2 comments on commit 58a399d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Frunk Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 58a399d Previous: 09a3d4f Ratio
big_transform_from_24fields 1782 ns/iter (± 41) 68 ns/iter (± 0) 26.21
big_transform_from_25fields 1800 ns/iter (± 31) 75 ns/iter (± 1) 24

This comment was automatically generated by workflow using github-action-benchmark.

CC: @lloydmeta

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Frunk Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 58a399d Previous: 09a3d4f Ratio
big_transform_from_24fields 1489 ns/iter (± 5) 68 ns/iter (± 0) 21.90
big_transform_from_25fields 1499 ns/iter (± 6) 75 ns/iter (± 1) 19.99

This comment was automatically generated by workflow using github-action-benchmark.

CC: @lloydmeta

Please sign in to comment.