Crates.io | dyn_phy |
lib.rs | dyn_phy |
version | |
source | src |
created_at | 2024-10-13 23:50:33.856143 |
updated_at | 2024-10-14 00:51:06.779598 |
description | object-safe version of smoltcp::phy traits |
homepage | https://pub.npry.dev/interstice/about |
repository | https://pub.npry.dev/interstice |
max_upload_size | |
id | 1407770 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
This crate provides DynPhy
, DynTxToken
, and DynRxToken
, which are object-safe versions
of smoltcp
's phy::Device
, phy::RxToken
, and phy::TxToken
.
These Dyn*
types are fully-compatible with and blanket-impled over the smoltcp
types. They are
unfortunately only optimistically zero-alloc (i.e. they may allocate depending on closure sizes).
The motivating use-case for this functionality is dynamic dispatch over multiple PHY interfaces, e.g. for packet-switching. This crate makes the following possible:
use dyn_phy::DynPhy;
use smoltcp::phy;
let mut loopback = phy::Loopback::new(phy::Medium::Ethernet);
let mut fault_test = phy::FaultInjector::new(phy::Loopback::new(phy::Medium::Ethernet), 0);
// This would not be possible with phy::Device as it is not object-safe:
let mut devs = heapless::Vec::<&mut dyn DynPhy, 8>::new();
devs.push(&mut loopback);
devs.push(&mut fault_test);
for dev in &mut devs {
println!("{:?}", dev.capabilities());
}