4 releases

0.1.3 Mar 8, 2022
0.1.2 Feb 27, 2022
0.1.1 Feb 27, 2022
0.1.0 Feb 27, 2022

#1649 in Data structures

27 downloads per month

MPL-2.0 license

157 lines


More types for your types!


This library is a successor to my records library, designed to make it more modular and comosable. Instead of one record attribute, moretypes provides several attributes that can be commposed to give objects certain properties. This is different from traits, as these properties are often implementations of multiple traits, constructors, behavioural changes, etc.


Records in MoreTypes are structs with all fields public (like records::record, but without most of the methods). They are useful for cases like configuration structs, where placing pub before every field is annoying boilerplate at best and logically erroneous at worst. Private fields preceeded by underscores remain private.

use moretypes::record;

pub struct Config {
    option1: String,
    option2: u32,

pub fn main() {
    let cfg = Config {
        option1: String::from("Foo"),
        option2: 69,

    println!("option1 = {}, option2 = {}", cfg.option1, cfg.option2);

Named Tuples

Named tuples are structs with named fields that are able to be used similar to tuple structs. They provide both the ability to convert to/from tuples and a way to construct them like tuples (both of these can be switched off using flags). They are useful as a replacement for tuple structs, where you want named fields and ordering at the same time. The fields are ordered based on where they are declared.

use moretypes::named_tuple;

pub struct Vec3<T> {
    x: T,
    y: T,
    z: T,

pub fn main() {
    let pos = Vec3::new(1.0, 2.0, 3.0);
    println!("{:?}", pos.as_tuple());


~33K SLoC