Skip to content

Commit dff1e57

Browse files
committed
Give release its own error type
1 parent 70a793a commit dff1e57

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

alpm/src/alpm.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::utils::*;
22
use crate::{Callbacks, Error, Result};
33

44
use std::ffi::{c_void, CString};
5+
use std::fmt;
56
use std::os::raw::c_int;
67
use std::ptr::NonNull;
78

@@ -33,6 +34,17 @@ impl Drop for Alpm {
3334
}
3435
}
3536

37+
#[derive(Debug, Eq, PartialEq, Copy, Clone, Ord, PartialOrd, Hash)]
38+
pub struct ReleaseError;
39+
40+
impl fmt::Display for ReleaseError {
41+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42+
f.write_str("Failed to release alpm")
43+
}
44+
}
45+
46+
impl std::error::Error for ReleaseError {}
47+
3648
impl Alpm {
3749
#[doc(alias("alpm_initialize", "initialize"))]
3850
pub fn new<S: Into<Vec<u8>>>(root: S, db_path: S) -> Result<Alpm> {
@@ -55,13 +67,13 @@ impl Alpm {
5567
Alpm::new(root, db_path)
5668
}
5769

58-
pub fn release(self) -> std::result::Result<(), ()> {
70+
pub fn release(self) -> std::result::Result<(), ReleaseError> {
5971
if unsafe { alpm_release(self.as_ptr()) } == 0 {
6072
std::mem::forget(self);
6173
Ok(())
6274
} else {
6375
std::mem::forget(self);
64-
Err(())
76+
Err(ReleaseError)
6577
}
6678
}
6779

0 commit comments

Comments
 (0)