Skip to content

Commit

Permalink
Use alloc::collections in no_std builds
Browse files Browse the repository at this point in the history
In no_std builds, replace std::collections types with alloc::collections counterparts
  • Loading branch information
GeneFerneau committed Mar 13, 2021
1 parent 2ec3efa commit b441165
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions lightning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern crate bitcoin;
#[cfg(any(test, feature = "_test_utils"))] extern crate hex;
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] extern crate regex;

#[cfg(feature = "no_std")] extern crate alloc;
#[cfg(feature = "no_std")] extern crate core;
#[cfg(feature = "no_std")] extern crate hashbrown;

Expand Down
5 changes: 3 additions & 2 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ use bitcoin::secp256k1::key::{PublicKey,SecretKey};

use regex;

use std::collections::BTreeSet;
#[cfg(not(feature = "no_std"))]
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeSet, HashMap, HashSet};
#[cfg(feature = "no_std")]
use hashbrown::{HashMap, HashSet};
#[cfg(feature = "no_std")]
use alloc::collections::BTreeSet;
use std::default::Default;
use std::sync::Mutex;
#[cfg(not(feature = "no_std"))]
Expand Down
3 changes: 3 additions & 0 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ use util::events::{MessageSendEvent, MessageSendEventsProvider};
use util::logger::Logger;
use routing::network_graph::NetGraphMsgHandler;

#[cfg(not(feature = "no_std"))]
use std::collections::LinkedList;
#[cfg(feature = "no_std")]
use alloc::collections::LinkedList;
#[cfg(not(feature = "no_std"))]
use std::collections::{HashMap, HashSet, hash_map};
#[cfg(feature = "no_std")]
Expand Down
6 changes: 4 additions & 2 deletions lightning/src/routing/network_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ use std::sync::atomic::{AtomicUsize, Ordering};
#[cfg(feature = "no_std")]
use core::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
use std::collections::BTreeMap;
use std::collections::btree_map::Entry as BtreeEntry;
#[cfg(not(feature = "no_std"))]
use std::collections::{BTreeMap, btree_map::Entry as BtreeEntry};
#[cfg(feature = "no_std")]
use alloc::collections::{BTreeMap, btree_map::Entry as BtreeEntry};
use bitcoin::hashes::hex::ToHex;

/// The maximum number of extra bytes which we do not understand in a gossip message before we will
Expand Down
3 changes: 3 additions & 0 deletions lightning/src/routing/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use util::logger::Logger;
use std::{cmp, ops::Deref};
#[cfg(feature = "no_std")]
use core::{cmp, ops::Deref};
#[cfg(not(feature = "no_std"))]
use std::collections::BinaryHeap;
#[cfg(feature = "no_std")]
use alloc::collections::BinaryHeap;
#[cfg(not(feature = "no_std"))]
use std::collections::HashMap;
#[cfg(feature = "no_std")]
Expand Down

0 comments on commit b441165

Please sign in to comment.