Crates.io | std-embedded-nal |
lib.rs | std-embedded-nal |
version | 0.3.0 |
source | src |
created_at | 2020-09-02 07:10:07.807454 |
updated_at | 2024-06-05 14:11:45.4509 |
description | Implementation of the `embedded-nal` traits for large devices that support the standard library |
homepage | |
repository | https://gitlab.com/chrysn/std-embedded-nal |
max_upload_size | |
id | 283794 |
size | 58,114 |
std-embedded-nal
This crate implements the embedded-nal network traits for operating systems that support the standard library's network. .
In that, it is to embedded-nal what linux-embedded-hal is to embedded-hal: A way to use libraries written for the bare-metal embedded world on Linux. (Just that network interfaces are better standardized than hardware access, so it should work on any system).
As the operating system's network stack is always available, it can be instanciated and used at any time without need for synchronization, roughly like this:
use embedded_nal::nb::block;
use std_embedded_nal::Stack;
use embedded_nal::UdpClient;
let message = [0x50, 0x01, 0x00, 0x00];
let mut stack = Stack::default();
let mut socket = stack.socket()?;
block!(stack.connect(&mut socket, "127.0.0.1:5683".parse()?)?);
block!(stack.send(&mut socket, &message)?);
See the CoAP and HTTP examples for full and working versions.
When using the regular embedded-nal
APIs,
the client main examples run use nb::block!
,
which means that there is busy looping until an event arrives
(which is bad in clients and terrible in servers).
The general expectation with these APIs based on nb
is that
users would know when to try again;
the UNIX version of the coapclient
example illustrates how that would probably be done.
(The setup around mio
and this library is relatively complex;
embedded implementations might get away with less code there.)
On nightly, and gated by the async
feature,
the asynchronous implementations of the embedded-nal-async crate are available.
This crate contains minimal working implementations the traits currently in embedded-nal.
This crate is build-tested on stable Rust 1.60.0. That is largely following the embedded-nal MSRV. It might compile with older versions but that may change at any time.