Skip to content

Commit

Permalink
Add feature flags for sync and async
Browse files Browse the repository at this point in the history
  • Loading branch information
ollipa committed Sep 12, 2023
1 parent 657e571 commit 7e6baf1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build --locked
run: cargo build --all-features --locked

- name: Run unit tests
run: cargo test
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ nix = "0.26"
[dev-dependencies]
simple_logger = "4.2"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

[features]
default = ["sync"]
sync = ["neli/sync"]
async = ["neli/async"]
20 changes: 20 additions & 0 deletions examples/print_interfaces.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use log::LevelFilter;
#[cfg(feature = "async")]
use netlink_wi::AsyncNlSocket;
#[cfg(not(feature = "async"))]
use netlink_wi::NlSocket;
use simple_logger::SimpleLogger;

#[cfg(not(feature = "async"))]
fn main() {
SimpleLogger::new()
.with_level(LevelFilter::Debug)
Expand All @@ -15,3 +19,19 @@ fn main() {
println!("{interface:#?}");
}
}

#[cfg(feature = "async")]
#[tokio::main]
async fn main() {
SimpleLogger::new()
.with_level(LevelFilter::Debug)
.with_module_level("neli", LevelFilter::Info)
.init()
.unwrap();

let mut socket = AsyncNlSocket::connect().await.unwrap();
let interfaces = socket.list_interfaces().await.unwrap();
for interface in interfaces {
println!("{interface:#?}");
}
}
18 changes: 0 additions & 18 deletions examples/print_interfaces_async.rs

This file was deleted.

8 changes: 5 additions & 3 deletions examples/print_reg_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ fn main() {
.unwrap();

let mut socket = NlSocket::connect().unwrap();
let domains = socket.get_regulatory_domain().unwrap();
for domain in domains {
println!("{domain:#?}");
loop {
let domains = socket.get_regulatory_domain().unwrap();
for domain in domains {
println!("{domain:#?}");
}
}
}
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@
pub(crate) mod attributes;
pub(crate) mod commands;

#[cfg(feature = "async")]
mod asynchronous;
mod error;
pub mod interface;
mod netlink;
pub mod reg_domain;
pub mod station;
#[cfg(feature = "sync")]
mod synchronous;
pub mod wiphy;

pub use crate::attributes::MonitorFlags;
#[cfg(feature = "async")]
pub use asynchronous::AsyncNlSocket;
pub use error::NlError;
#[cfg(feature = "sync")]
pub use synchronous::NlSocket;

0 comments on commit 7e6baf1

Please sign in to comment.