{"id":18044591,"url":"https://github.com/pedromfedricci/constrained_int","last_synced_at":"2025-04-05T03:26:38.966Z","repository":{"id":43018055,"uuid":"510520928","full_name":"pedromfedricci/constrained_int","owner":"pedromfedricci","description":"Integers that are constrained within inclusive ranges.","archived":false,"fork":false,"pushed_at":"2023-07-28T05:34:09.000Z","size":118,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T03:06:34.704Z","etag":null,"topics":["experimental","intergers","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pedromfedricci.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-04T22:42:58.000Z","updated_at":"2024-11-21T17:07:18.000Z","dependencies_parsed_at":"2024-12-18T08:52:00.495Z","dependency_job_id":null,"html_url":"https://github.com/pedromfedricci/constrained_int","commit_stats":{"total_commits":65,"total_committers":2,"mean_commits":32.5,"dds":0.01538461538461533,"last_synced_commit":"35be496d1610609564b80ae590d4e8efcddf6a39"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedromfedricci%2Fconstrained_int","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedromfedricci%2Fconstrained_int/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedromfedricci%2Fconstrained_int/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedromfedricci%2Fconstrained_int/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pedromfedricci","download_url":"https://codeload.github.com/pedromfedricci/constrained_int/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284355,"owners_count":20913686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["experimental","intergers","rust"],"created_at":"2024-10-30T18:09:31.070Z","updated_at":"2025-04-05T03:26:38.938Z","avatar_url":"https://github.com/pedromfedricci.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Integers that are constrained within inclusive ranges\n\n[![License][license-image]][license-mit]\n[![Documentation][doc-image]][doc-link]\n[![Crate][crate-image]][crate-link]\n[![CI][ci-image]][ci-link]\n[![codecov][codecov-image]][codecov-link]\n![Safety][safety-image]\n![No std][no_std-image]\n![Maintenance][experimental-image]\n\n`Constrained` types are represented simply as primitive integers, but their\nvalues will **always** be contained by inclusive range bounds. The range is\ndefined at compile time, by assigning values to appropriate const generic\nparameters. Constrained types provide fallible APIs for construction and\nvalue assignment, they also implement wrapping, saturating, overflowing\nand checked arithmetic operations for the range boundaries. See each desired\ntype documentation for more information.\n\nThe `constrained_int` crate relies on the incomplete [generic_const_exprs]\nfeature to define compile time constraints for const generic parameters.\nTherefore, this crate can only be compiled with nightly and, more importantly,\nmust be considered as an **experimental** crate only.\n\nThis crate is `no_std` by default. See features section for more information.\n\n## Install\n\n```toml\n# Cargo.toml\n\n[dependencies]\nconstrained_int = \"0.2\"\n```\n\n## Example\n\n```rust\nuse constrained_int::i8::{ConstrainedI8, ConstrainedI8Error};\n\n// Lower bound = -5, upper bound = 10, default = -1.\ntype Constrained = ConstrainedI8\u003c-5, 10, -1\u003e;\ntype ConstrainedError = ConstrainedI8Error\u003c-5, 10\u003e;\n\nfn main() -\u003e Result\u003c(), ConstrainedError\u003e {\n    // Gets the default value.\n    let mut constrained = Constrained::default();\n    assert_eq!(constrained.get(), -1);\n\n    // Sets within inclusive range, succeeds.\n    constrained.set(-5)?;\n    assert_eq!(constrained.get(), -5);\n\n    // Below lower bound, fails.\n    assert_eq!(constrained.checked_sub(1), None);\n    assert_eq!(constrained.get(), -5);\n\n    // Saturates at the upper bound.\n    constrained = constrained.saturating_add(100);\n    assert_eq!(constrained.get(), 10);\n\n    // Sets out of boundary, fails.\n    assert!(constrained.set(11).is_err());\n\n    // Wraps around the upper bound.\n    constrained = constrained.wrapping_add(1);\n    assert_eq!(constrained.get(), -5);\n\n    Ok(())\n}\n```\n\n## Documentation\n\nThis project documentation is hosted at [docs.rs][doc-link].\n\n## Safety\n\nThis crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in\n100% safe Rust.\n\n## Feature flags\n\nThis crate does not provide any default features. The features that can be\nenabled are: `std` and `serde`.\n\n### std\n\nThis crate does not link against the standard library by default, so it is\nsuitable for `no_std` environments. It does provide a `std` feature though,\nthat enables the standard library as a dependency. By enabling this crate's\n`std` feature, these additional features are provided:\n\n- All crate's error types will implement the `std::error::Error` trait.\n\nIf users already are importing the standard library on their crate, enabling\n`std` feature comes at no additional cost.\n\n### serde\n\nThe `serde` feature implements [serde]'s `Serialize` and `Deserialize` traits\nfor `Wrapping`, `Saturating` and all `Constrained` types. Note that `Constrained`\ntype's construction constraints are also evaluated for the `Deserialize`\nimplementation. See each desired type documentation for more information about\nthese constraints.\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0 ([LICENSE-APACHE] or \u003chttp://apache.org/licenses/LICENSE-2.0\u003e)\n- MIT license ([LICENSE-MIT] or \u003chttp://opensource.org/licenses/MIT\u003e)\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n\n## Code review\n\nIt is recommended to always use [cargo-crev] to verify the trustworthiness of\neach of your dependencies, including this one.\n\n[//]: # \"general links\"\n[generic_const_exprs]: https://github.com/rust-lang/rust/issues/76560\n[serde]: https://serde.rs/\n[cargo-crev]: https://github.com/crev-dev/cargo-crev\n[doc-link]: https://docs.rs/constrained_int\n[crate-link]: https://crates.io/crates/constrained_int\n[codecov-link]: https://codecov.io/gh/pedromfedricci/constrained_int\n[ci-link]: https://github.com/pedromfedricci/constrained_int/actions/workflows/ci.yaml\n[license-apache]: ./LICENSE-APACHE\n[license-mit]: ./LICENSE-MIT\n[//]: # \"badges\"\n[safety-image]: https://img.shields.io/badge/unsafe-forbidden-success.svg\n[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg\n[ci-image]: https://github.com/pedromfedricci/constrained_int/actions/workflows/ci.yaml/badge.svg\n[doc-image]: https://docs.rs/constrained_int/badge.svg\n[crate-image]: https://img.shields.io/crates/v/constrained_int.svg\n[codecov-image]: https://codecov.io/gh/pedromfedricci/constrained_int/branch/main/graph/badge.svg?token=5ZBKPBGE4P\n[experimental-image]: https://img.shields.io/badge/maintenance-experimental-blue.svg\n[no_std-image]: https://img.shields.io/badge/no__std-compatible-success.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedromfedricci%2Fconstrained_int","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpedromfedricci%2Fconstrained_int","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedromfedricci%2Fconstrained_int/lists"}