put hashbrown behind alloc feature
This commit is contained in:
parent
e85e953c93
commit
1fcc8d3f57
@ -7,11 +7,14 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
delegate = "0.8"
|
delegate = "0.8"
|
||||||
hashbrown = "0.13"
|
|
||||||
paste = "1.0"
|
paste = "1.0"
|
||||||
dyn-clone = "1.0"
|
dyn-clone = "1.0"
|
||||||
embed-doc-image = "0.1"
|
embed-doc-image = "0.1"
|
||||||
|
|
||||||
|
[dependencies.hashbrown]
|
||||||
|
version = "0.13"
|
||||||
|
optional = true
|
||||||
|
|
||||||
[dependencies.heapless]
|
[dependencies.heapless]
|
||||||
version = "0.7"
|
version = "0.7"
|
||||||
optional = true
|
optional = true
|
||||||
@ -55,7 +58,7 @@ version = "1.0"
|
|||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std", "serde/std", "spacepackets/std"]
|
std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std", "serde/std", "spacepackets/std"]
|
||||||
alloc = ["serde/alloc", "spacepackets/alloc"]
|
alloc = ["serde/alloc", "spacepackets/alloc", "hashbrown"]
|
||||||
serde = ["dep:serde", "spacepackets/serde"]
|
serde = ["dep:serde", "spacepackets/serde"]
|
||||||
crossbeam = ["crossbeam-channel"]
|
crossbeam = ["crossbeam-channel"]
|
||||||
heapless = ["dep:heapless"]
|
heapless = ["dep:heapless"]
|
||||||
|
@ -63,6 +63,7 @@ use alloc::vec;
|
|||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use core::slice::Iter;
|
use core::slice::Iter;
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
@ -3,7 +3,9 @@ use crate::events::{EventU32, GenericEvent, Severity};
|
|||||||
use crate::events::{EventU32TypedSev, HasSeverity};
|
use crate::events::{EventU32TypedSev, HasSeverity};
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
use core::hash::Hash;
|
use core::hash::Hash;
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
use hashbrown::HashSet;
|
use hashbrown::HashSet;
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
@ -38,43 +40,6 @@ pub trait PusEventMgmtBackendProvider<Provider: GenericEvent> {
|
|||||||
fn disable_event_reporting(&mut self, event: &Provider) -> Result<bool, Self::Error>;
|
fn disable_event_reporting(&mut self, event: &Provider) -> Result<bool, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default backend provider which uses a hash set as the event reporting status container
|
|
||||||
/// like mentioned in the example of the [PusEventMgmtBackendProvider] documentation.
|
|
||||||
///
|
|
||||||
/// This provider is a good option for host systems or larger embedded systems where
|
|
||||||
/// the expected occasional memory allocation performed by the [HashSet] is not an issue.
|
|
||||||
pub struct DefaultPusMgmtBackendProvider<Event: GenericEvent = EventU32> {
|
|
||||||
disabled: HashSet<Event>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Safety: All contained field are [Send] as well
|
|
||||||
unsafe impl<Event: GenericEvent + Send> Send for DefaultPusMgmtBackendProvider<Event> {}
|
|
||||||
|
|
||||||
impl<Event: GenericEvent> Default for DefaultPusMgmtBackendProvider<Event> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
disabled: HashSet::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Provider: GenericEvent + PartialEq + Eq + Hash + Copy + Clone>
|
|
||||||
PusEventMgmtBackendProvider<Provider> for DefaultPusMgmtBackendProvider<Provider>
|
|
||||||
{
|
|
||||||
type Error = ();
|
|
||||||
fn event_enabled(&self, event: &Provider) -> bool {
|
|
||||||
!self.disabled.contains(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn enable_event_reporting(&mut self, event: &Provider) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.disabled.remove(event))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn disable_event_reporting(&mut self, event: &Provider) -> Result<bool, Self::Error> {
|
|
||||||
Ok(self.disabled.insert(*event))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "heapless")]
|
#[cfg(feature = "heapless")]
|
||||||
pub mod heapless_mod {
|
pub mod heapless_mod {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -145,6 +110,43 @@ impl<SenderE> From<EcssTmError<SenderE>> for EventManError<SenderE> {
|
|||||||
pub mod alloc_mod {
|
pub mod alloc_mod {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
/// Default backend provider which uses a hash set as the event reporting status container
|
||||||
|
/// like mentioned in the example of the [PusEventMgmtBackendProvider] documentation.
|
||||||
|
///
|
||||||
|
/// This provider is a good option for host systems or larger embedded systems where
|
||||||
|
/// the expected occasional memory allocation performed by the [HashSet] is not an issue.
|
||||||
|
pub struct DefaultPusMgmtBackendProvider<Event: GenericEvent = EventU32> {
|
||||||
|
disabled: HashSet<Event>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Safety: All contained field are [Send] as well
|
||||||
|
unsafe impl<Event: GenericEvent + Send> Send for DefaultPusMgmtBackendProvider<Event> {}
|
||||||
|
|
||||||
|
impl<Event: GenericEvent> Default for DefaultPusMgmtBackendProvider<Event> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
disabled: HashSet::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Provider: GenericEvent + PartialEq + Eq + Hash + Copy + Clone>
|
||||||
|
PusEventMgmtBackendProvider<Provider> for DefaultPusMgmtBackendProvider<Provider>
|
||||||
|
{
|
||||||
|
type Error = ();
|
||||||
|
fn event_enabled(&self, event: &Provider) -> bool {
|
||||||
|
!self.disabled.contains(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enable_event_reporting(&mut self, event: &Provider) -> Result<bool, Self::Error> {
|
||||||
|
Ok(self.disabled.remove(event))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn disable_event_reporting(&mut self, event: &Provider) -> Result<bool, Self::Error> {
|
||||||
|
Ok(self.disabled.insert(*event))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PusEventDispatcher<BackendError, Provider: GenericEvent> {
|
pub struct PusEventDispatcher<BackendError, Provider: GenericEvent> {
|
||||||
reporter: EventReporter,
|
reporter: EventReporter,
|
||||||
backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>,
|
backend: Box<dyn PusEventMgmtBackendProvider<Provider, Error = BackendError>>,
|
||||||
|
@ -95,7 +95,7 @@ pub use alloc_mod::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::seq_count::SequenceCountProvider;
|
use crate::seq_count::SequenceCountProvider;
|
||||||
#[cfg(feature = "crossbeam")]
|
#[cfg(all(feature = "crossbeam", feature = "std"))]
|
||||||
pub use stdmod::CrossbeamVerifSender;
|
pub use stdmod::CrossbeamVerifSender;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use stdmod::{
|
pub use stdmod::{
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// TODO: Refactor this to also test the STD impl using mpsc
|
||||||
#[cfg(feature = "crossbeam")]
|
#[cfg(feature = "crossbeam")]
|
||||||
pub mod crossbeam_test {
|
pub mod crossbeam_test {
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
Loading…
Reference in New Issue
Block a user