//! Allocator-flexible data types // When std is enabled, prefer those types #[cfg(feature = "std")] pub use self::std::*; // When alloc but not std is enabled, use those types #[cfg(all(feature = "alloc", not(feature = "std")))] pub use self::alloc::*; // When neither alloc or std is enabled, use a heapless fallback #[cfg(all(not(feature = "alloc"), not(feature = "std")))] pub use self::core::*; /// For when `std` is enabled #[cfg(feature = "std")] mod std { /// An allocation-backend agnostic [`Box`] type pub type Box = std::boxed::Box; /// An allocation-backend agnostic map type pub type Map = std::collections::HashMap; /// An allocation-backend agnostic vector type pub type Vec = std::vec::Vec; /// A vector of child nodes pub type ChildrenVec = std::vec::Vec; /// A vector of parent nodes pub type ParentsVec = std::vec::Vec; /// Creates a new map with the capacity for the specified number of items before it must be resized #[must_use] pub fn new_map_with_capacity(capacity: usize) -> Map where K: Eq + std::hash::Hash, { Map::with_capacity(capacity) } /// Creates a new vector with the capacity for the specified number of items before it must be resized #[must_use] pub fn new_vec_with_capacity(capacity: usize) -> Vec { Vec::with_capacity(capacity) } /// Rounds to the nearest whole number #[must_use] pub fn round(value: f32) -> f32 { value.round() } /// Computes the absolute value #[must_use] pub fn abs(value: f32) -> f32 { value.abs() } } /// For when `alloc` but not `std` is enabled #[cfg(all(feature = "alloc", not(feature = "std")))] mod alloc { extern crate alloc; /// An allocation-backend agnostic `Box` type pub type Box = alloc::boxed::Box; /// An allocation-backend agnostic map type pub type Map = hashbrown::HashMap; /// An allocation-backend agnostic vector type pub type Vec = alloc::vec::Vec; /// A vector of child nodes pub type ChildrenVec = alloc::vec::Vec; /// A vector of parent nodes pub type ParentsVec = alloc::vec::Vec; /// Creates a new map with the capacity for the specified number of items before it must be resized #[must_use] pub fn new_map_with_capacity(capacity: usize) -> Map { Map::with_capacity(capacity) } /// Creates a new vector with the capacity for the specified number of items before it must be resized #[must_use] pub fn new_vec_with_capacity(capacity: usize) -> Vec { Vec::with_capacity(capacity) } /// Rounds to the nearest whole number #[must_use] pub fn round(value: f32) -> f32 { num_traits::float::FloatCore::round(value) } /// Computes the absolute value #[must_use] pub fn abs(value: f32) -> f32 { num_traits::float::FloatCore::abs(value) } } /// For when neither `alloc` nor `std` is enabled #[cfg(all(not(feature = "alloc"), not(feature = "std")))] mod core { /// The maximum number of nodes in the forest pub const MAX_NODE_COUNT: usize = 256; /// The maximum number of children of any given node pub const MAX_CHILD_COUNT: usize = 16; /// The maximum number of parents for each child pub const MAX_PARENTS_COUNT: usize = 1; /// An allocation-backend agnostic map type pub type Map = crate::indexmap::FnvIndexMap; /// An allocation-backend agnostic vector type pub type Vec = arrayvec::ArrayVec; /// A vector of child nodes, whose length cannot exceed [`MAX_CHILD_COUNT`] pub type ChildrenVec = arrayvec::ArrayVec; /// A vector of parent nodes, whose length cannot exceed [`MAX_PARENTS_COUNT`] pub type ParentsVec = arrayvec::ArrayVec; /// Creates a new map with the capacity for the specified number of items /// /// This map cannot be resized. #[must_use] pub fn new_map_with_capacity(_capacity: usize) -> Map where K: Eq + ::hash32::Hash, { Map::new() } /// Creates a new map with the capacity for the specified number of items before it must be resized /// /// This vector cannot be resized. #[must_use] pub fn new_vec_with_capacity(_capacity: usize) -> arrayvec::ArrayVec { arrayvec::ArrayVec::new() } /// Rounds to the nearest whole number #[inline] #[must_use] pub fn round(value: f32) -> f32 { num_traits::float::FloatCore::round(value) } /// Computes the absolute value #[inline] #[must_use] pub fn abs(value: f32) -> f32 { num_traits::float::FloatCore::abs(value) } }