Frunk Versions Save

Funktional generic type-level programming in Rust: HList, Coproduct, Generic, LabelledGeneric, Validated, Monoid and friends.

laws0.5.0

3 months ago

Bumped due to new quickcheck (1.x-based now!)

0.4.2

11 months ago

See changelog for details.

Much thanks to the efforts of @CobaltCause.

0.4.1

1 year ago

Lots of good stuff thanks to team work from a number of contributors (incl steffahn, kpp, agluszak, rosefromthedead, and BGR360)

From the Changelog

0.4.0

2 years ago

Lots of good stuff thanks to team work from a number of contributors (incl @mbrobbel, @ImmemorConsultrixContrarie , @ExpHP)

From the Changelog

0.3.2

3 years ago

v0.3.1

4 years ago

v0.3.0

5 years ago

v0.2.4

5 years ago

Added

  • Added ToMut trait, which allows borrowing mutably from a Coproduct or HList.
  • Added support for #[derive(LabelledGeneric)] on tuple structs
  • Added Path model and PathTraverser trait, which allows for composable lens-like-usage

Changed

  • Make macros call themselves recursively with $crate::

v0.2.2

5 years ago

Adds support for transmogrifying data of different types

#[macro_use]
extern crate frunk_core;

use frunk::labelled::Transmogrifier;

#[derive(LabelledGeneric)]
struct InternalPhoneNumber {
    emergency: Option<usize>,
    main: usize,
    secondary: Option<usize>,
}

#[derive(LabelledGeneric)]
struct InternalAddress<'a> {
    is_whitelisted: bool,
    name: &'a str,
    phone: InternalPhoneNumber,
}

#[derive(LabelledGeneric)]
struct InternalUser<'a> {
    name: &'a str,
    age: usize,
    address: InternalAddress<'a>,
    is_banned: bool,
}

#[derive(LabelledGeneric, PartialEq, Debug)]
struct ExternalPhoneNumber {
    main: usize,
}

#[derive(LabelledGeneric, PartialEq, Debug)]
struct ExternalAddress<'a> {
    name: &'a str,
    phone: ExternalPhoneNumber,
}

#[derive(LabelledGeneric, PartialEq, Debug)]
struct ExternalUser<'a> {
    age: usize,
    address: ExternalAddress<'a>,
    name: &'a str,
}

let internal_user = InternalUser {
    name: "John",
    age: 10,
    address: InternalAddress {
        is_whitelisted: true,
        name: "somewhere out there",
        phone: InternalPhoneNumber {
            main: 1234,
            secondary: None,
            emergency: Some(5678),
        },
    },
    is_banned: true,
};

/// Boilerplate-free conversion of a top-level InternalUser into an
/// ExternalUser, taking care of subfield conversions as well.
let external_user: ExternalUser = internal_user.transmogrify();

let expected_external_user = ExternalUser {
    name: "John",
    age: 10,
    address: ExternalAddress {
        name: "somewhere out there",
        phone: ExternalPhoneNumber {
            main: 1234,
        },
    }
};

assert_eq!(external_user, expected_external_user);

v0.2.1

5 years ago

Upgraded syn and quote versions in frunk_derives.

Lock-step bump in versions for all libs to keep things straightforward.