Skip to content

nekitdev/refining

refining

License Version Downloads Test

Refinement types.

Installation

cargo

You can add refining as a dependency with the following command:

$ cargo add refining

Or by directly specifying it in the configuration like so:

[dependencies]
refining = "0.1.0"

Alternatively, you can add it directly from the source:

[dependencies.refining]
git = "https://github.com/nekitdev/refining.git"

Examples

use core::fmt;

use anyhow::Result;

use refining::prelude::*;

type_str!(DeviceName = "device name");
type_str!(DeviceCharge = "device charge");

type Name = Refinement<str, And<Ascii, LengthClosed<1, 32>>, DeviceName>;
type Charge = Refinement<u8, u8::Closed<1, 100>, DeviceCharge>;

struct Device<'a> {
    name: &'a Name,
    charge: Charge,
}

impl fmt::Display for Device<'_> {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            formatter,
            "{name} ({charge}%)",
            name = self.name,
            charge = self.charge
        )
    }
}

fn main() -> Result<()> {
    let name = "nekit".refine_ref()?;
    let charge = 42.refine()?;

    let device = Device { name, charge };

    println!("{device}");

    Ok(())
}

Running the example will print the following output:

nekit (42%)

Features

std

empty

length

int

char

str

regex

Documentation

You can find the documentation here.

Support

If you need support with the library, you can send an email.

Changelog

You can find the changelog here.

Security Policy

You can find the Security Policy of refining here.

Contributing

If you are interested in contributing to refining, make sure to take a look at the Contributing Guide, as well as the Code of Conduct.

License

refining is licensed under the MIT License terms. See License for details.

About

Refinement types.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors

Languages