#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![deny(unsafe_code)]
#![cfg_attr(
all(
any(feature = "proto-ipv4", feature = "proto-ipv6"),
feature = "medium-ethernet"
),
deny(unused)
)]
#![allow(clippy::match_like_matches_macro)]
#![allow(clippy::redundant_field_names)]
#![allow(clippy::identity_op)]
#![allow(clippy::option_map_unit_fn)]
#![allow(clippy::unit_arg)]
#[cfg(any(feature = "std", feature = "alloc"))]
extern crate alloc;
#[cfg(not(any(
feature = "proto-ipv4",
feature = "proto-ipv6",
feature = "proto-sixlowpan"
)))]
compile_error!("You must enable at least one of the following features: proto-ipv4, proto-ipv6, proto-sixlowpan");
#[cfg(all(
feature = "socket",
not(any(
feature = "socket-raw",
feature = "socket-udp",
feature = "socket-tcp",
feature = "socket-icmp",
feature = "socket-dhcp",
))
))]
compile_error!("If you enable the socket feature, you must enable at least one of the following features: socket-raw, socket-udp, socket-tcp, socket-icmp, socket-dhcp");
#[cfg(all(
feature = "socket",
not(any(
feature = "medium-ethernet",
feature = "medium-ip",
feature = "medium-ieee802154",
))
))]
compile_error!("If you enable the socket feature, you must enable at least one of the following features: medium-ip, medium-ethernet, medium-ieee802154");
#[cfg(all(feature = "defmt", feature = "log"))]
compile_error!("You must enable at most one of the following features: defmt, log");
use core::fmt;
#[macro_use]
mod macros;
mod parsers;
mod rand;
#[cfg(any(
feature = "medium-ethernet",
feature = "medium-ip",
feature = "medium-ieee802154"
))]
pub mod iface;
pub mod phy;
#[cfg(feature = "socket")]
pub mod socket;
pub mod storage;
pub mod time;
pub mod wire;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
Exhausted,
Illegal,
Unaddressable,
Finished,
Truncated,
Checksum,
Unrecognized,
Fragmented,
Malformed,
Dropped,
NotSupported,
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
pub type Result<T> = core::result::Result<T, Error>;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Exhausted => write!(f, "buffer space exhausted"),
Error::Illegal => write!(f, "illegal operation"),
Error::Unaddressable => write!(f, "unaddressable destination"),
Error::Finished => write!(f, "operation finished"),
Error::Truncated => write!(f, "truncated packet"),
Error::Checksum => write!(f, "checksum error"),
Error::Unrecognized => write!(f, "unrecognized packet"),
Error::Fragmented => write!(f, "fragmented packet"),
Error::Malformed => write!(f, "malformed packet"),
Error::Dropped => write!(f, "dropped by socket"),
Error::NotSupported => write!(f, "not supported by smoltcp"),
}
}
}