Skip to content

Commit b441165

Browse files
committed
Use alloc::collections in no_std builds
In no_std builds, replace std::collections types with alloc::collections counterparts
1 parent 2ec3efa commit b441165

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

lightning/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern crate bitcoin;
3434
#[cfg(any(test, feature = "_test_utils"))] extern crate hex;
3535
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] extern crate regex;
3636

37+
#[cfg(feature = "no_std")] extern crate alloc;
3738
#[cfg(feature = "no_std")] extern crate core;
3839
#[cfg(feature = "no_std")] extern crate hashbrown;
3940

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ use bitcoin::secp256k1::key::{PublicKey,SecretKey};
4747

4848
use regex;
4949

50-
use std::collections::BTreeSet;
5150
#[cfg(not(feature = "no_std"))]
52-
use std::collections::{HashMap, HashSet};
51+
use std::collections::{BTreeSet, HashMap, HashSet};
5352
#[cfg(feature = "no_std")]
5453
use hashbrown::{HashMap, HashSet};
54+
#[cfg(feature = "no_std")]
55+
use alloc::collections::BTreeSet;
5556
use std::default::Default;
5657
use std::sync::Mutex;
5758
#[cfg(not(feature = "no_std"))]

lightning/src/ln/peer_handler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ use util::events::{MessageSendEvent, MessageSendEventsProvider};
3030
use util::logger::Logger;
3131
use routing::network_graph::NetGraphMsgHandler;
3232

33+
#[cfg(not(feature = "no_std"))]
3334
use std::collections::LinkedList;
35+
#[cfg(feature = "no_std")]
36+
use alloc::collections::LinkedList;
3437
#[cfg(not(feature = "no_std"))]
3538
use std::collections::{HashMap, HashSet, hash_map};
3639
#[cfg(feature = "no_std")]

lightning/src/routing/network_graph.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ use std::sync::atomic::{AtomicUsize, Ordering};
4141
#[cfg(feature = "no_std")]
4242
use core::sync::atomic::{AtomicUsize, Ordering};
4343
use std::sync::Mutex;
44-
use std::collections::BTreeMap;
45-
use std::collections::btree_map::Entry as BtreeEntry;
44+
#[cfg(not(feature = "no_std"))]
45+
use std::collections::{BTreeMap, btree_map::Entry as BtreeEntry};
46+
#[cfg(feature = "no_std")]
47+
use alloc::collections::{BTreeMap, btree_map::Entry as BtreeEntry};
4648
use bitcoin::hashes::hex::ToHex;
4749

4850
/// The maximum number of extra bytes which we do not understand in a gossip message before we will

lightning/src/routing/router.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ use util::logger::Logger;
2525
use std::{cmp, ops::Deref};
2626
#[cfg(feature = "no_std")]
2727
use core::{cmp, ops::Deref};
28+
#[cfg(not(feature = "no_std"))]
2829
use std::collections::BinaryHeap;
30+
#[cfg(feature = "no_std")]
31+
use alloc::collections::BinaryHeap;
2932
#[cfg(not(feature = "no_std"))]
3033
use std::collections::HashMap;
3134
#[cfg(feature = "no_std")]

0 commit comments

Comments
 (0)