diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-08-25 14:19:13 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-08-25 15:25:25 +0200 |
commit | 549b3b0919f28f843dc2a40b1e71c98a87c8652f (patch) | |
tree | 4a32862a2a76dc537d3323d74392cc5f26061d0f /src/errors.rs |
Initial
Diffstat (limited to 'src/errors.rs')
-rw-r--r-- | src/errors.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..bfb5606 --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,21 @@ +use std::io; + +pub trait ToIOError { + fn to_io_error(self) -> io::Error; +} + +impl ToIOError for git2::Error { + fn to_io_error(self) -> io::Error { + io::Error::new(io::ErrorKind::Other, self) + } +} + +pub trait ToIOResult<T> { + fn to_io_result(self) -> io::Result<T>; +} + +impl<T, E: ToIOError> ToIOResult<T> for std::result::Result<T, E> { + fn to_io_result(self) -> io::Result<T> { + self.map_err(|e| e.to_io_error()) + } +} |