Skip to content

Commit

Permalink
Replace Option with Result georust#1: added errors based using error-…
Browse files Browse the repository at this point in the history
…chain
  • Loading branch information
jdroenner committed Dec 28, 2016
1 parent 184091a commit 5be2864
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ repository = "https://github.com/georust/rust-gdal"
documentation = "https://georust.github.io/rust-gdal/"

[dependencies]
libc = "0.2.13"
error-chain = "0.7.2"
libc = "0.2.18"
geo = "0.0.5"
gdal-sys = { path = "gdal-sys", version = "0.1.0"}

Expand Down
20 changes: 20 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use libc::{c_int};

// Create the Error, ErrorKind, ResultExt, and Result types
error_chain! {
foreign_links {
FfiNulError(::std::ffi::NulError);
StrUtf8Error(::std::str::Utf8Error);
}

errors {
CplError(class: c_int, number: c_int, msg: String) {
description("GDAL internal error")
display("CPL error class: '{}', error number: '{}', error msg: '{}'", class, number, msg)
}
NullPointer(method_name: &'static str) {
description("GDAL method returned a NULL pointer.")
display("GDAL method {} returned a NULL pointer.", method_name)
}
}
}
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
#![crate_name="gdal"]
#![crate_type="lib"]


extern crate libc;
extern crate geo;
extern crate gdal_sys;

#[macro_use]
extern crate error_chain;

pub use version::version_info;

mod utils;
Expand All @@ -33,8 +35,4 @@ pub mod metadata;
pub mod version;
pub mod raster;
pub mod vector;

#[derive(Clone, Copy, PartialEq, Debug)]
pub struct GdalError {
pub desc: &'static str,
}
pub mod errors;

0 comments on commit 5be2864

Please sign in to comment.