1#![deny(missing_docs)]
15#![cfg_attr(test, feature(downcast_unchecked))]
18#![cfg_attr(not(feature = "std"), no_std)]
19#[cfg(feature = "alloc")]
20extern crate alloc;
21
22#[cfg(feature = "std")]
23pub mod simple_executor;
24#[cfg(feature = "std")]
25pub use simple_executor::SimpleExecutor;
26
27#[cfg(feature = "std")]
28pub mod threadpool_executor;
29#[cfg(feature = "std")]
30pub use threadpool_executor::ThreadPoolExecutor;
31
32#[cfg(feature = "std")]
33pub mod threaded_executor;
34#[cfg(feature = "std")]
35pub use threaded_executor::ThreadedExecutor;
36
37use core::cmp::{Ord, Ordering};
38use ncomm_core::node::Node;
39
40#[cfg(feature = "alloc")]
41use alloc::{boxed::Box, vec::Vec};
42#[cfg(feature = "std")]
43use std::{boxed::Box, vec::Vec};
44
45#[cfg(any(feature = "alloc", feature = "std"))]
46pub(crate) struct NodeWrapper<ID: PartialEq> {
51 pub priority: u128,
53 pub node: Box<dyn Node<ID>>,
55}
56
57#[cfg(any(feature = "alloc", feature = "std"))]
58impl<ID: PartialEq> NodeWrapper<ID> {
59 pub fn destroy(self) -> Box<dyn Node<ID>> {
61 self.node
62 }
63}
64
65#[cfg(any(feature = "alloc", feature = "std"))]
66impl<ID: PartialEq> Ord for NodeWrapper<ID> {
67 fn cmp(&self, other: &Self) -> Ordering {
68 self.priority.cmp(&other.priority).reverse()
69 }
70}
71
72#[cfg(any(feature = "alloc", feature = "std"))]
73impl<ID: PartialEq> PartialOrd for NodeWrapper<ID> {
74 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
75 Some(self.cmp(other))
76 }
77}
78
79#[cfg(any(feature = "alloc", feature = "std"))]
80impl<ID: PartialEq> PartialEq for NodeWrapper<ID> {
81 fn eq(&self, other: &Self) -> bool {
82 self.priority == other.priority
83 }
84}
85
86#[cfg(any(feature = "alloc", feature = "std"))]
87impl<ID: PartialEq> Eq for NodeWrapper<ID> {}
88
89#[cfg(any(feature = "alloc", feature = "std"))]
90#[inline(always)]
96pub(crate) fn insert_into<ID: PartialEq>(vec: &mut Vec<NodeWrapper<ID>>, node: NodeWrapper<ID>) {
97 match vec.binary_search(&node) {
101 Ok(idx) => vec.insert(idx + 1, node),
102 Err(idx) => vec.insert(idx, node),
103 }
104}