Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bindings up to Augeas 1.11.0 (current) #10

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

name = "augeas"
version = "0.1.0"
authors = ["panicbit <[email protected]>"]
description = "High level bindings for augeas"
authors = ["panicbit <[email protected]>", "David Lutterkort <[email protected]>"]
description = "Augeas bindings for Rust"
license = "MIT"
keywords = ["augeas", "bindings"]
repository = "https://github.com/panicbit/rust-augeas"
Expand Down
54 changes: 44 additions & 10 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@ use augeas_sys::*;
#[derive(Clone,PartialEq,Debug)]
pub enum Error {
Augeas(AugeasError),
Parse(ParseError),
Nul(NulError)
}

impl ::std::error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::Augeas(ref err) => err.description(),
Error::Nul(ref err) => err.description()
}
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Augeas(ref err) => err.fmt(f),
Error::Nul(ref err) => err.fmt(f)
Error::Nul(ref err) => err.fmt(f),
Error::Parse(ref err) => err.fmt(f)
}
}
}
Expand Down Expand Up @@ -75,6 +68,15 @@ impl fmt::Display for AugeasError {
}
}

impl Error {
pub fn is_code(&self, code : ErrorCode) -> bool {
match self {
Error::Augeas(err) => err.code == code,
_ => false
}
}
}

impl From<NulError> for Error {
fn from(err: NulError) -> Error {
Error::Nul(err)
Expand Down Expand Up @@ -145,3 +147,35 @@ impl ErrorCode {
impl Default for ErrorCode {
fn default() -> ErrorCode { ErrorCode::NoError }
}

impl From<ErrorCode> for Error {
fn from(code : ErrorCode) -> Error {
Error::Augeas(AugeasError {
code : code,
message : None,
minor_message : None,
details : None
})
}
}

impl From<String> for Error {
fn from(kind: String) -> Error {
Error::Parse(ParseError {
kind: kind
})
}
}

impl fmt::Display for ParseError {
fn fmt(&self, f : &mut fmt::Formatter) -> fmt::Result {
write!(f, "parse error of kind {}", self.kind)
}
}

#[derive(Clone, PartialEq, Debug)]
pub struct ParseError {
// There's a lot more information we can/should pull out of the
// tree when parsing goes wrong
pub kind : String
}
Loading