gdal 0.1.1

GDAL bindings for Rust
Documentation
use libc::c_int;
use std::ffi::CString;
use std::sync::{Once, ONCE_INIT};
use utils::_string;
use raster::{gdal, Dataset};


static START: Once = ONCE_INIT;
static mut registered_drivers: bool = false;

pub fn _register_drivers() {
    unsafe {
        START.call_once(|| {
            gdal::GDALAllRegister();
            registered_drivers = true;
        });
    }
}


#[allow(missing_copy_implementations)]
pub struct Driver {
    c_driver: *const (),
}


impl Driver {
    pub fn get(name: &str) -> Option<Driver> {
        _register_drivers();
        let c_name = CString::new(name.as_bytes()).unwrap();
        let c_driver = unsafe { gdal::GDALGetDriverByName(c_name.as_ptr()) };
        return match c_driver.is_null() {
            true  => None,
            false => Some(Driver{c_driver: c_driver}),
        };
    }

    pub unsafe fn _with_c_ptr(c_driver: *const ()) -> Driver {
        return Driver{c_driver: c_driver};
    }

    pub unsafe fn _c_ptr(&self) -> *const () {
        return self.c_driver;
    }

    pub fn short_name(&self) -> String {
        let rv = unsafe { gdal::GDALGetDriverShortName(self.c_driver) };
        return _string(rv);
    }

    pub fn long_name(&self) -> String {
        let rv = unsafe { gdal::GDALGetDriverLongName(self.c_driver) };
        return _string(rv);
    }

    pub fn create(
        &self,
        filename: &str,
        size_x: isize,
        size_y: isize,
        bands: isize
    ) -> Option<Dataset> {
        use std::ptr::null;
        let c_filename = CString::new(filename.as_bytes()).unwrap();
        let c_dataset = unsafe { gdal::GDALCreate(
                self.c_driver,
                c_filename.as_ptr(),
                size_x as c_int,
                size_y as c_int,
                bands as c_int,
                gdal::GDT_BYTE,
                null()
            ) };
        return match c_dataset.is_null() {
            true  => None,
            false => unsafe { Some(Dataset::_with_c_ptr(c_dataset)) },
        };
    }
}