1use std::fmt;
2use std::io;
3
4pub type Result<T> = std::result::Result<T, Error>;
6
7#[derive(Debug)]
9pub enum Error {
10 InvalidName,
14
15 WouldBlock,
18
19 Io(io::Error),
21}
22
23impl fmt::Display for Error {
24 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25 match self {
26 Error::InvalidName => f.write_str(
27 "invalid lock name: must be non-empty and contain no '\\0', '/', or '\\'",
28 ),
29 Error::WouldBlock => f.write_str("lock is currently held by another thread or process"),
30 Error::Io(e) => write!(f, "I/O error: {e}"),
31 }
32 }
33}
34
35impl std::error::Error for Error {
36 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
37 match self {
38 Error::Io(e) => Some(e),
39 _ => None,
40 }
41 }
42}
43
44impl From<io::Error> for Error {
45 fn from(e: io::Error) -> Self {
46 Error::Io(e)
47 }
48}