update the version and docs about the no_std support
This commit is contained in:
Generated
+1
-1
@@ -26,7 +26,7 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "discrete_range_map"
|
name = "discrete_range_map"
|
||||||
version = "0.5.2"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"btree_monstrousity",
|
"btree_monstrousity",
|
||||||
"either",
|
"either",
|
||||||
|
|||||||
+2
-7
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "discrete_range_map"
|
name = "discrete_range_map"
|
||||||
version = "0.5.2"
|
version = "0.6.0"
|
||||||
authors = ["James Forster <james.forsterer@gmail.com>"]
|
authors = ["James Forster <james.forsterer@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = """
|
description = """
|
||||||
@@ -26,9 +26,4 @@ either = { version = "1.9.0", default-features = false }
|
|||||||
itertools = { version = "0.12.0", default-features = false }
|
itertools = { version = "0.12.0", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pretty_assertions = "1.3.0"
|
pretty_assertions = "1.4.0"
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["std"]
|
|
||||||
std = ["either/use_std", "itertools/use_std", "serde/std"]
|
|
||||||
alloc = ["itertools/use_alloc"]
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ This crate provides [`DiscreteRangeMap`] and [`DiscreteRangeSet`],
|
|||||||
Data Structures for storing non-overlapping discrete intervals based
|
Data Structures for storing non-overlapping discrete intervals based
|
||||||
off [`BTreeMap`].
|
off [`BTreeMap`].
|
||||||
|
|
||||||
|
`no_std` is supported and should work with the default features.
|
||||||
|
|
||||||
## You must implement `Copy`
|
## You must implement `Copy`
|
||||||
|
|
||||||
Due to implementation complications with non-`Copy` types the
|
Due to implementation complications with non-`Copy` types the
|
||||||
@@ -38,22 +40,24 @@ assert_eq!(map.contains_point(5), true);
|
|||||||
## Example using a custom range type
|
## Example using a custom range type
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
use std::ops::{Bound, RangeBounds};
|
||||||
|
|
||||||
use discrete_range_map::test_ranges::ie;
|
use discrete_range_map::test_ranges::ie;
|
||||||
use discrete_range_map::{
|
use discrete_range_map::{
|
||||||
DiscreteFinite, Interval, DiscreteRangeMap,
|
DiscreteFinite, DiscreteRangeMap, InclusiveInterval,
|
||||||
FiniteRange,
|
InclusiveRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
enum Reservation {
|
enum Reservation {
|
||||||
// Start, End (Inclusive-Exclusive)
|
// Start, End (Inclusive-Inclusive)
|
||||||
Finite(i8, i8),
|
Finite(i8, i8),
|
||||||
// Start (Inclusive-Forever)
|
// Start (Inclusive-Infinity)
|
||||||
Infinite(i8),
|
Infinite(i8),
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, we need to implement FiniteRange
|
// First, we need to implement InclusiveRange
|
||||||
impl FiniteRange<i8> for Reservation {
|
impl InclusiveRange<i8> for Reservation {
|
||||||
fn start(&self) -> i8 {
|
fn start(&self) -> i8 {
|
||||||
match self {
|
match self {
|
||||||
Reservation::Finite(start, _) => *start,
|
Reservation::Finite(start, _) => *start,
|
||||||
@@ -62,23 +66,21 @@ impl FiniteRange<i8> for Reservation {
|
|||||||
}
|
}
|
||||||
fn end(&self) -> i8 {
|
fn end(&self) -> i8 {
|
||||||
match self {
|
match self {
|
||||||
//the end is exclusive so we take off 1 with checking
|
Reservation::Finite(_, end) => *end,
|
||||||
//for compile time error overflow detection
|
|
||||||
Reservation::Finite(_, end) => end.down().unwrap(),
|
|
||||||
Reservation::Infinite(_) => i8::MAX,
|
Reservation::Infinite(_) => i8::MAX,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second, we need to implement From<Interval<i8>>
|
// Second, we need to implement From<InclusiveInterval<i8>>
|
||||||
impl From<Interval<i8>> for Reservation {
|
impl From<InclusiveInterval<i8>> for Reservation {
|
||||||
fn from(bounds: Interval<i8>) -> Self {
|
fn from(value: InclusiveInterval<i8>) -> Self {
|
||||||
if bounds.end == i8::MAX {
|
if value.end == i8::MAX {
|
||||||
Reservation::Infinite(bounds.start)
|
Reservation::Infinite(value.start)
|
||||||
} else {
|
} else {
|
||||||
Reservation::Finite(
|
Reservation::Finite(
|
||||||
bounds.start,
|
value.start,
|
||||||
bounds.end.up().unwrap(),
|
value.end.up().unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,7 +89,7 @@ impl From<Interval<i8>> for Reservation {
|
|||||||
// Next we can create a custom typed DiscreteRangeMap
|
// Next we can create a custom typed DiscreteRangeMap
|
||||||
let reservation_map = DiscreteRangeMap::from_slice_strict([
|
let reservation_map = DiscreteRangeMap::from_slice_strict([
|
||||||
(Reservation::Finite(10, 20), "Ferris".to_string()),
|
(Reservation::Finite(10, 20), "Ferris".to_string()),
|
||||||
(Reservation::Infinite(20), "Corro".to_string()),
|
(Reservation::Infinite(21), "Corro".to_string()),
|
||||||
])
|
])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -178,6 +180,9 @@ When a range "merges" other ranges it absorbs them to become larger.
|
|||||||
See Wikipedia's article on mathematical Intervals:
|
See Wikipedia's article on mathematical Intervals:
|
||||||
<https://en.wikipedia.org/wiki/Interval_(mathematics)>
|
<https://en.wikipedia.org/wiki/Interval_(mathematics)>
|
||||||
|
|
||||||
|
# Features
|
||||||
|
This crate currently has no features.
|
||||||
|
|
||||||
# Credit
|
# Credit
|
||||||
|
|
||||||
I originally came up with the `StartBound`: [`Ord`] bodge on my own,
|
I originally came up with the `StartBound`: [`Ord`] bodge on my own,
|
||||||
|
|||||||
+6
-1
@@ -21,6 +21,8 @@ along with discrete_range_map. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
//! Data Structures for storing non-overlapping discrete intervals based
|
//! Data Structures for storing non-overlapping discrete intervals based
|
||||||
//! off [`BTreeMap`].
|
//! off [`BTreeMap`].
|
||||||
//!
|
//!
|
||||||
|
//! `no_std` is supported and should work with the default features.
|
||||||
|
//!
|
||||||
//! ## You must implement `Copy`
|
//! ## You must implement `Copy`
|
||||||
//!
|
//!
|
||||||
//! Due to implementation complications with non-`Copy` types the
|
//! Due to implementation complications with non-`Copy` types the
|
||||||
@@ -186,6 +188,9 @@ along with discrete_range_map. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
//! See Wikipedia's article on mathematical Intervals:
|
//! See Wikipedia's article on mathematical Intervals:
|
||||||
//! <https://en.wikipedia.org/wiki/Interval_(mathematics)>
|
//! <https://en.wikipedia.org/wiki/Interval_(mathematics)>
|
||||||
//!
|
//!
|
||||||
|
//! # Features
|
||||||
|
//! This crate currently has no features.
|
||||||
|
//!
|
||||||
//! # Credit
|
//! # Credit
|
||||||
//!
|
//!
|
||||||
//! I originally came up with the `StartBound`: [`Ord`] bodge on my own,
|
//! I originally came up with the `StartBound`: [`Ord`] bodge on my own,
|
||||||
@@ -266,7 +271,7 @@ along with discrete_range_map. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
#![feature(step_trait)]
|
#![feature(step_trait)]
|
||||||
#![allow(clippy::tabs_in_doc_comments)]
|
#![allow(clippy::tabs_in_doc_comments)]
|
||||||
#![allow(clippy::needless_return)]
|
#![allow(clippy::needless_return)]
|
||||||
#![cfg_attr(not(any(feature = "std", test)), no_std)]
|
#![cfg_attr(not(feature = "test"), no_std)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user