gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 229Rust 8TOML 3CSS 1310 Definiciones

⎇ a40abe4bd9bd4a3eb0e6d80afa84924e4076f52a src/sys.rs Rust · 69 líneas · 2.0 KB Historia Quién tocó qué crudo

Break out a sys module that encapsulates target-specific APIs 6e9ad8ea3 · David Flemström ·

1#[cfg(feature = "std")]
2mod std {
3    pub type Map<K, V> = ::std::collections::HashMap<K, V>;
4    pub type Vec<A> = ::std::vec::Vec<A>;
5    pub type ChildrenVec<A> = ::std::vec::Vec<A>;
6    pub type ParentsVec<A> = ::std::vec::Vec<A>;
7
8    pub fn new_map_with_capacity<K, V>(capacity: usize) -> Map<K, V>
9    where
10        K: Eq + ::std::hash::Hash,
11    {
12        Map::with_capacity(capacity)
13    }
14
15    pub fn new_vec_with_capacity<A>(capacity: usize) -> Vec<A> {
16        Vec::with_capacity(capacity)
17    }
18}
19
20#[cfg(feature = "alloc")]
21mod alloc {
22    pub type Map<K, V> = ::hashbrown::HashMap<K, V>;
23    pub type Vec<A> = ::alloc::vec::Vec<A>;
24    pub type ChildrenVec<A> = ::alloc::vec::Vec<A>;
25    pub type ParentsVec<A> = ::alloc::vec::Vec<A>;
26
27    pub fn new_map_with_capacity<K, V>(capacity: usize) -> Map<K, V> {
28        Map::with_capacity(capacity)
29    }
30
31    pub fn new_vec_with_capacity<A>(capacity: usize) -> Vec<A> {
32        Vec::with_capacity(capacity)
33    }
34}
35
36#[cfg(all(not(feature = "alloc"), not(feature = "std")))]
37mod core {
38    use typenum::marker_traits::Unsigned;
39
40    type MaxNodeCount = heapless::consts::U256;
41    type MaxChildCount = heapless::consts::U16;
42    type MaxParentsCount = heapless::consts::U1;
43
44    pub type Map<K, V> = ::heapless::FnvIndexMap<K, V, MaxNodeCount>;
45    pub type Vec<A> = ::arrayvec::ArrayVec<[A; MaxNodeCount::USIZE]>;
46    pub type ChildrenVec<A> = ::arrayvec::ArrayVec<[A; MaxChildCount::USIZE]>;
47    pub type ParentsVec<A> = ::arrayvec::ArrayVec<[A; MaxParentsCount::USIZE]>;
48
49    pub fn new_map_with_capacity<K, V>(_capacity: usize) -> Map<K, V>
50    where
51        K: Eq + ::hash32::Hash,
52    {
53        Map::new()
54    }
55
56    pub fn new_vec_with_capacity<T, A>(_capacity: usize) -> ::arrayvec::ArrayVec<A>
57    where
58        A: ::arrayvec::Array<Item = T>,
59    {
60        ::arrayvec::ArrayVec::new()
61    }
62}
63
64#[cfg(feature = "alloc")]
65pub use self::alloc::*;
66#[cfg(all(not(feature = "alloc"), not(feature = "std")))]
67pub use self::core::*;
68#[cfg(feature = "std")]
69pub use self::std::*;