errors.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use errno::{ Errno };
use std::error::{ self };
use std::fmt::{ self };
pub type Result<T> = ::std::result::Result<T, Error>;
/// Errors that can be returned from the file locking API.
#[derive(Debug, Eq, PartialEq)]
pub enum Error {
/// An exclusive lock is already held on the file. Returned only for the
/// nonblocking API
/// ([`try_lock_shared()`](crate::file_ext::FileExt::try_lock_shared()) and
/// [`try_lock_exclusive`](crate::file_ext::FileExt::try_lock_exclusive())).
AlreadyLocked,
/// The underlying locking primitive returned an error.
LockFailed(Errno),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Error::*;
match *self {
AlreadyLocked => write!(f, "Already locked"),
LockFailed(e) => write!(f, "Locking failed: {}", e),
}
}
}
impl error::Error for Error {}