Refinement types.
You can add refining as a dependency with the following command:
$ cargo add refiningOr 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"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%)
You can find the documentation here.
If you need support with the library, you can send an email.
You can find the changelog here.
You can find the Security Policy of refining here.
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.
refining is licensed under the MIT License terms. See License for details.