azure_iot_operations_services/
leased_lock.rsuse core::fmt::Debug;
use azure_iot_operations_protocol::common::aio_protocol_error::AIOProtocolError;
use thiserror::Error;
use crate::state_store::{self, KeyObservation, ServiceError as StateStoreServiceError};
pub use crate::state_store::{Response, SetCondition, SetOptions};
pub type LockObservation = KeyObservation;
pub type ServiceError = StateStoreServiceError;
mod client;
pub use client::Client;
#[derive(Debug, Error)]
#[error(transparent)]
pub struct Error(#[from] ErrorKind);
impl Error {
#[must_use]
pub fn kind(&self) -> &ErrorKind {
&self.0
}
}
impl From<state_store::Error> for Error {
fn from(error: state_store::Error) -> Self {
let kind: ErrorKind = (error.consuming_kind()).into();
kind.into()
}
}
#[derive(Error, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum ErrorKind {
#[error("lock is already held by another holder")]
LockAlreadyHeld,
#[error(transparent)]
AIOProtocolError(#[from] AIOProtocolError),
#[error(transparent)]
ServiceError(#[from] ServiceError),
#[error("key length must not be zero")]
KeyLengthZero,
#[error("lock name length must not be zero")]
LockNameLengthZero,
#[error("lock holder name length must not be zero")]
LockHolderNameLengthZero,
#[error("{0}")]
SerializationError(String),
#[error("{0}")]
InvalidArgument(String),
#[error("Unexpected response payload for the request type: {0}")]
UnexpectedPayload(String),
#[error("lock may only be observed once at a time")]
DuplicateObserve,
}
impl From<state_store::ErrorKind> for ErrorKind {
fn from(kind: state_store::ErrorKind) -> Self {
match kind {
state_store::ErrorKind::AIOProtocolError(protocol_error) => {
ErrorKind::AIOProtocolError(protocol_error)
}
state_store::ErrorKind::ServiceError(service_error) => {
ErrorKind::ServiceError(service_error)
}
state_store::ErrorKind::KeyLengthZero => ErrorKind::KeyLengthZero,
state_store::ErrorKind::SerializationError(error_string) => {
ErrorKind::SerializationError(error_string)
}
state_store::ErrorKind::InvalidArgument(argument) => {
ErrorKind::InvalidArgument(argument)
}
state_store::ErrorKind::UnexpectedPayload(payload) => {
ErrorKind::UnexpectedPayload(payload)
}
state_store::ErrorKind::DuplicateObserve => ErrorKind::DuplicateObserve,
}
}
}
pub enum AcquireAndUpdateKeyOption {
Update(Vec<u8>, SetOptions),
DoNotUpdate,
Delete,
}