[][src]Struct safe_bindgen::Bindgen

pub struct Bindgen { /* fields omitted */ }

Stores configuration for the bindgen.

Examples

Since construction can only fail if there is an error while reading the cargo manifest it is usually safe to call .unwrap() on the result (though .expect() is considered better practice).

This example is not tested
Bindgen::new().expect("unable to read cargo manifest");

If your project is a valid cargo project or follows the same structure, you can simply place the following in your build script.

This example is not tested
Bindgen::new().expect("unable to read cargo manifest")
    .run_build("path/to/output/file");

If you use a different structure you should use .source_file("...") to set the path to the root crate file.

This example is not tested
Bindgen::new().expect("unable to read cargo manifest")
    .source_file("src/root.rs")
    .run_build("include/my_header.h");

Methods

impl Bindgen[src]

pub fn new() -> Result<Self, Error>[src]

Create a new bindgen instance.

This can only fail if there are issues reading the cargo manifest. If there is no cargo manifest available then the source file defaults to src/lib.rs.

pub fn source_file<T>(&mut self, path: T) -> &mut Self where
    PathBuf: From<T>, 
[src]

Set the path to the root source file of the crate.

This should only be used when not using a cargo build system.

pub fn source_code<S>(&mut self, file_name: S, code: S) -> &mut Self where
    S: Into<String>, 
[src]

Use custom code as input.

pub fn compile<L: Lang>(
    &mut self,
    lang: &mut L,
    outputs: &mut HashMap<String, String>,
    finalise: bool
) -> Result<(), Vec<Error>>
[src]

Compile just the code into header declarations.

This does not add any include-guards, includes, or extern declarations. It is mainly intended for internal use, but may be of interest to people who wish to embed moz-cheddar's generated code in another file.

pub fn compile_or_panic<L: Lang>(
    &mut self,
    lang: &mut L,
    outputs: &mut HashMap<String, String>,
    finalise: bool
)
[src]

pub fn write_outputs<P: AsRef<Path>>(
    &self,
    root: P,
    outputs: &HashMap<String, String>
) -> Result<(), IoError>
[src]

Writes virtual files to the file system

pub fn write_outputs_or_panic<P: AsRef<Path>>(
    &self,
    root: P,
    outputs: &HashMap<String, String>
)
[src]

pub fn run_build<P: AsRef<Path>, L: Lang>(
    &mut self,
    lang: &mut L,
    output_dir: P
)
[src]

Write the header to a file, panicking on error.

This is a convenience method for use in build scripts. If errors occur during compilation they will be printed then the function will panic.

Panics

Panics on any compilation error so that the build script exits and prints output.

pub fn print_error(&self, error: &Error)[src]

Print an error

Auto Trait Implementations

impl Send for Bindgen

impl Sync for Bindgen

impl Unpin for Bindgen

impl UnwindSafe for Bindgen

impl RefUnwindSafe for Bindgen

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<'a, T> Desc<'a, T> for T[src]