use alloc::vec::Vec;
use core::fmt;
use super::SyncFlags;
use crate::error::Error;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum SyncError {
Failed(Vec<u8>),
UnexpectedId([u8; 4]),
RemoteErrno(u32),
InvalidFlags(SyncFlags),
InvalidPath,
}
impl fmt::Display for SyncError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Failed(msg) => {
let s = core::str::from_utf8(msg).unwrap_or("<non-utf8>");
write!(f, "sync: device error: {s}")
}
Self::UnexpectedId(id) => {
let s = core::str::from_utf8(id).unwrap_or("????");
write!(f, "sync: unexpected response: {s}")
}
Self::RemoteErrno(e) => write!(f, "sync: remote errno {e}"),
Self::InvalidFlags(flags) => write!(f, "sync: invalid flags {:#x}", flags.bits()),
Self::InvalidPath => f.write_str("sync: path contains a NUL byte"),
}
}
}
impl core::error::Error for SyncError {}
impl<E> From<SyncError> for Error<E> {
fn from(e: SyncError) -> Self {
Self::Sync(e)
}
}