File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515 - run : rustup update ${{ matrix.toolchain }}
1616 - run : cargo check --all-features --all
1717
18+ nostd :
19+ name : Check no_std
20+ runs-on : ubuntu-latest
21+ strategy :
22+ matrix :
23+ toolchain : [stable, beta, nightly]
24+ steps :
25+ - name : Checkout sources
26+ uses : actions/checkout@v4
27+ - run : rustup update ${{ matrix.toolchain }}
28+ - run : cargo check --no-default-features --features=serde --all
29+
1830 test :
1931 name : Test Suite
2032 runs-on : ubuntu-latest
Original file line number Diff line number Diff line change @@ -6,21 +6,26 @@ description = "Memory-efficient data structures based on patricia tree"
66homepage = " https://github.com/sile/patricia_tree"
77repository = " https://github.com/sile/patricia_tree"
88readme = " README.md"
9- keywords = [" patricia" , " radix" , " trie" ]
9+ keywords = [" patricia" , " radix" , " trie" , " no_std " ]
1010categories = [" data-structures" ]
1111license = " MIT"
1212edition = " 2021"
1313rust-version = " 1.82.0"
1414
1515[dependencies ]
16- bitflags = " 2"
16+ bitflags = { version = " 2" , default-features = false }
1717serde = { version = " 1" , optional = true }
1818
1919[dev-dependencies ]
2020clap = { version = " 4" , features = [" derive" ] }
2121rand = " 0.8"
2222serde_json = { version = " 1" }
2323
24+ [features ]
25+ default = [" std" ]
26+ std = []
27+ serde = [" dep:serde" ]
28+
2429[package .metadata .docs .rs ]
2530all-features = true
2631
Original file line number Diff line number Diff line change 2424//! ```
2525#![ warn( missing_docs) ]
2626#![ allow( clippy:: cast_ptr_alignment) ]
27+ #![ cfg_attr( not( feature = "std" ) , no_std) ]
2728
2829#[ macro_use]
2930extern crate bitflags;
3031#[ cfg( test) ]
3132extern crate rand;
3233
33- use std:: cmp:: Ordering ;
34+ #[ macro_use]
35+ extern crate alloc;
36+
37+ use alloc:: borrow:: ToOwned ;
38+ use alloc:: string:: String ;
39+ use alloc:: vec:: Vec ;
40+ use core:: cmp:: Ordering ;
3441
3542pub use map:: { GenericPatriciaMap , PatriciaMap , StringPatriciaMap } ;
3643pub use set:: { GenericPatriciaSet , PatriciaSet , StringPatriciaSet } ;
@@ -129,11 +136,11 @@ impl BorrowedBytes for str {
129136 }
130137
131138 fn is_valid_bytes ( bytes : & [ u8 ] ) -> bool {
132- std :: str:: from_utf8 ( bytes) . is_ok ( )
139+ core :: str:: from_utf8 ( bytes) . is_ok ( )
133140 }
134141
135142 fn from_bytes ( bytes : & [ u8 ] ) -> & Self {
136- std :: str:: from_utf8 ( bytes) . expect ( "unreachable" )
143+ core :: str:: from_utf8 ( bytes) . expect ( "unreachable" )
137144 }
138145
139146 fn strip_common_prefix ( & self , bytes : & [ u8 ] ) -> & Self {
Original file line number Diff line number Diff line change @@ -4,9 +4,12 @@ use crate::node;
44use crate :: node:: Node ;
55use crate :: tree:: { self , PatriciaTree } ;
66use crate :: { BorrowedBytes , Bytes } ;
7- use std:: fmt;
8- use std:: iter:: FromIterator ;
9- use std:: marker:: PhantomData ;
7+ use alloc:: borrow:: ToOwned ;
8+ use alloc:: string:: String ;
9+ use alloc:: vec:: Vec ;
10+ use core:: fmt;
11+ use core:: iter:: FromIterator ;
12+ use core:: marker:: PhantomData ;
1013
1114/// Patricia tree based map with [`Vec<u8>`] as key.
1215pub type PatriciaMap < V > = GenericPatriciaMap < Vec < u8 > , V > ;
Original file line number Diff line number Diff line change 11//! A node which represents a subtree of a patricia tree.
22use crate :: BorrowedBytes ;
3- use std:: alloc:: { alloc, dealloc, handle_alloc_error, Layout } ;
4- use std:: marker:: PhantomData ;
5- use std:: mem;
6- use std:: ptr;
7- use std:: slice;
3+ use alloc:: alloc:: { alloc, dealloc, handle_alloc_error, Layout } ;
4+ use alloc:: vec:: Vec ;
5+ use core:: marker:: PhantomData ;
6+ use core:: { mem, ptr, slice} ;
87
98macro_rules! assert_some {
109 ( $expr: expr) => {
Original file line number Diff line number Diff line change 11use crate :: node:: { Flags , Node } ;
22use crate :: { BorrowedBytes , GenericPatriciaMap , GenericPatriciaSet } ;
3+ use alloc:: borrow:: { Cow , ToOwned } ;
4+ use alloc:: vec:: Vec ;
5+ use core:: borrow:: Borrow ;
6+ use core:: marker:: PhantomData ;
37use serde:: de:: { Error , Visitor } ;
48use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
5- use std:: borrow:: { Borrow , Cow } ;
6- use std:: marker:: PhantomData ;
79
810impl < T > Serialize for GenericPatriciaSet < T > {
911 /// In order to serialize a [PatriciaSet], make sure you installed the crate
@@ -217,7 +219,7 @@ struct BytesVisitor;
217219impl < ' de > Visitor < ' de > for BytesVisitor {
218220 type Value = Bytes < ' de > ;
219221
220- fn expecting ( & self , formatter : & mut std :: fmt:: Formatter ) -> std :: fmt:: Result {
222+ fn expecting ( & self , formatter : & mut core :: fmt:: Formatter ) -> core :: fmt:: Result {
221223 write ! ( formatter, "a byte string" )
222224 }
223225
Original file line number Diff line number Diff line change @@ -3,8 +3,10 @@ use crate::map::{self, GenericPatriciaMap};
33#[ cfg( any( feature = "serde" , test) ) ]
44use crate :: node:: Node ;
55use crate :: Bytes ;
6- use std:: fmt;
7- use std:: iter:: FromIterator ;
6+ use alloc:: string:: String ;
7+ use alloc:: vec:: Vec ;
8+ use core:: fmt;
9+ use core:: iter:: FromIterator ;
810
911/// Patricia tree based set with [`Vec<u8>`] as key.
1012pub type PatriciaSet = GenericPatriciaSet < Vec < u8 > > ;
Original file line number Diff line number Diff line change 1+ use alloc:: vec:: Vec ;
2+
13use crate :: {
24 node:: { self , Node , NodeMut } ,
35 BorrowedBytes ,
You can’t perform that action at this time.
0 commit comments