coap-zero 0.3.0

CoAP protocol implementation for no_std without alloc
Documentation
// Copyright Open Logistics Foundation
//
// Licensed under the Open Logistics Foundation License 1.3.
// For details on the licensing terms, see the LICENSE file.
// SPDX-License-Identifier: OLFL-1.3

//! Error used by the CoAP-Zero [Endpoint](super::CoapEndpoint)
//!
//! Wraps underlying errors and defines own error cases that can occur in the Endpoint

use crate::message;

/// Endpoint Error
///
/// This error type only covers things that went wrong on our side and that the endpoint could not
/// possibly handle in any meaningful way. For example, ill-formatted messages, messages arriving at
/// the wrong time, messages which lack context or CoAP protocol timeouts are expected, handled
/// automatically by the endpoint and only generate an "event" instead.
#[derive(Debug)]
pub enum Error<NetworkError> {
    /// Could not get random number from given PRNG
    Rng,
    /// Endpoint is not connected
    NotConnected,
    /// Endpoint is already connected
    AlreadyConnected,
    /// Error while parsing the URI
    Uri,
    /// There is already an operation ongoing
    Busy,
    /// Something really weird went wrong
    Impossible,
    /// The method that was called is not available in the current state
    Forbidden,
    /// No data received
    NoData,
    /// Reset received
    Reset,
    /// Timeout during operation
    Timeout,
    /// Out of Memory
    OutOfMemory,
    /// Wrong message type was given
    MessageType,
    /// Network error from underlying UDP Stack
    // TODO Depending on the perspective this may be an expected event, too
    Network(NetworkError),
    /// Error from [message] module
    // TODO As far as I can tell, this can only happen when encoding a message which could be
    // covered by OutOfMemory. For the decoding path, we map everything into events. We could
    // change Message::encode to return a Result<..., ()> instead because OOM is the only error
    // case that can happen there. But currently, it felt wrong to throw the message::Error from
    // Message::encode away.
    MessageError(message::Error),
}

impl<E> From<message::Error> for Error<E> {
    fn from(e: message::Error) -> Self {
        Error::MessageError(e)
    }
}