Skip to content

Commit

Permalink
Add network and serde feature flags (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Mast authored Jul 8, 2024
1 parent 7c6176b commit 46831b6
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 29 deletions.
24 changes: 1 addition & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ asim-macros = { path="macros" }
log = "0.4"
futures = "0.3"
parking_lot = "0.12"
tokio = { version="1", features=["sync", "time", "macros", "rt"], default-features=false }
instant = "0.1"
serde = { version="1", features=["derive"] }
tokio = { version="1", features=["sync"], default-features=false }
serde = { version="1", features=["derive"], optional=true }
async-trait = "0.1"
rand = "0.8"
rand = { version="0.8", optional=true }

[[test]]
name = "speed-test"
path = "tests/speed_test.rs"
required-features = ["network"]

[dev-dependencies]
env_logger = "0.4"

[features]
default = ["network", "serde"]
network = ["dep:rand"]
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Add asim::spawn() function similar to tokio::spawn()
- Add asim::time::sleep() function similar to tokio::time::sleep()
- Improve documentation and add examples
- Move serde and network module behind feature gates

0.1:
- Initial Release
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ The main goal of this crate is to make simulation code look very similar to that
This is achieved by providing an API similar to that of the standard library or tokio but with an implementation based on discrete events.

This crate provides the simulator itself, a timer that allows an asynchronous task to sleep, and synchronization primitives.
Additionally, it includes basic primitives for processes and links that can be used to jump start your process.
Additionally, it includes basic primitives to simulate networking (guarded behind the "network" feature).

## Features
* `network`: Enable networking primitives
* `serde`: Support serialization of (some) asim objects using serde

## Usage
Take a look at the tests and examples to get an idea how this library is intended to be used.
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::future::Future;

pub mod sync;

#[cfg(feature = "network")]
pub mod network;

pub mod time;
Expand Down
4 changes: 4 additions & 0 deletions src/network/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ impl<Message: NetworkMessage, Data: NodeData> Node<Message, Data> {

/// Returns the connection to another node with the specified identifier (if it exists)
pub fn get_link_to(&self, node_id: &ObjectId) -> Option<Rc<Link<Message, Data>>> {
if *node_id == self.identifier {
panic!("There cannot be a link to the node itself");
}

match self.network_links.borrow().get(node_id) {
Some(link) => Some(link.clone()),
None => {
Expand Down
4 changes: 3 additions & 1 deletion src/time/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Elapsed simulated time in nanoseconds
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Ord, Eq)]
pub struct Time(u64);

/// A period of simulated time
Expand Down

0 comments on commit 46831b6

Please sign in to comment.