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

The refining crate comes with the following features:

  • std (enabled by default): depends on the Rust Standard Library (std);
  • empty (enabled by default): provides refining::empty predicates;
  • length (enabled by default): provides refining::length predicates;
  • int (enabled by default): provides refining::int predicates;
  • char (enabled by default): provides refining::char predicates;
  • str (enabled by default): provides refining::str predicates;
  • regex (enabled by default, implies std): provides refining::regex predicates.

These features can be disabled via the following:

[dependencies.refining]
version = "0.1.0"
default-features = false

Then only the refining::core module will be available; additional features can be enabled individually.

Again, note that regex implies std, so it can not be used in no_std environments.

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