Struct safer_ffi::headers::Builder

source ·
pub struct Builder<'__, W> { /* private fields */ }
Available on crate feature headers only.

Implementations§

source§

impl<'__, W> Builder<'__, W>

source

pub fn with_guard(self, guard: &'__ str) -> Self

Sets up the name of the ifndef guard of the header file.

It defaults to:

format!("__RUST_{}__", env::var("CARGO_CRATE_NAME")?.replace("-", "_").to_ascii_uppercase())
source

pub fn with_text_after_guard(self, text_after_guard: &'__ str) -> Self

Text included after the include guard of the header file

It defaults to an empty string

source

pub fn with_banner(self, banner: &'__ str) -> Self

Sets up the banner of the generated C header file.

It defaults to:

concat!(
    "/*! \\file */\n",
    "/*******************************************\n",
    " *                                         *\n",
    " *  File auto-generated by `::safer_ffi`.  *\n",
    " *                                         *\n",
    " *  Do not manually edit this file.        *\n",
    " *                                         *\n",
    " *******************************************/\n",
)
/*! \file */
/*******************************************
 *                                         *
 *  File auto-generated by `::safer_ffi`.  *
 *                                         *
 *  Do not manually edit this file.        *
 *                                         *
 *******************************************/
source

pub fn with_language(self, language: Language) -> Self

Sets the Language of the generated headers.

It defaults to Language::C.

source

pub fn with_naming_convention(self, naming_convention: NamingConvention) -> Self

Sets prefix for generated functions, structs & enums

source

pub fn with_stable_header(self, stable_header: bool) -> Self

Whether to yield a stable header or not (order of defined items guaranteed not to change provided the source code doesn’t change either).

It defaults to true.

source§

impl<'__> Builder<'__, WhereTo>

source

pub fn to_file(self, filename: impl AsRef<Path>) -> Result<Builder<'__, File>>

Specify the path to the file to be generated.

⚠️ If it already exists, its contents will be overwritten ⚠️

There is no default value here, either .to_file() or .to_writer() need to be called to be able to .generate() the headers.

For more fine-grained control over the “output stream” where the headers will be written to, use .to_writer().

§Example
::safer_ffi::headers::builder()
    .to_file("my_header.h")?
    .generate()?
source

pub fn to_writer<W>(self, out: W) -> Builder<'__, W>
where W: Write,

Specify the Write “stream” where the headers will be written to.

§Example
// Display the headers to the standard output
// (may need the `--nocapture` flag when running the tests)
::safer_ffi::headers::builder()
    .to_writer(::std::io::stdout())
    .generate()?
source§

impl<'__, W: Write> Builder<'__, W>

source

pub fn generate(self) -> Result<()>

Generate the C header file.

source§

impl Builder<'_, WhereTo>

source

pub fn generate_with_definer(self, definer: &mut impl Definer) -> Result<()>

More customizable version of .generate().

With this call, one can provide a custom implementation of a Definer, which can be useful for mock tests, mainly.

Trait Implementations§

source§

impl<'__, W: Default> Default for Builder<'__, W>

source§

fn default() -> Builder<'__, W>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'__, W> Freeze for Builder<'__, W>
where W: Freeze,

§

impl<'__, W> RefUnwindSafe for Builder<'__, W>
where W: RefUnwindSafe,

§

impl<'__, W> Send for Builder<'__, W>
where W: Send,

§

impl<'__, W> Sync for Builder<'__, W>
where W: Sync,

§

impl<'__, W> Unpin for Builder<'__, W>
where W: Unpin,

§

impl<'__, W> UnwindSafe for Builder<'__, W>
where W: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CompatExt for T

source§

fn compat(self) -> Compat<T>

Applies the Compat adapter by value. Read more
source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
source§

impl<T> FitForCBox for T

§

type CBoxWrapped = Box_<T>

Available on crate feature alloc only.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ManuallyDropMut for T

§

type Ret = ManuallyDrop<T>

source§

fn manually_drop_mut<'__>(&'__ mut self) -> &'__ mut ManuallyDrop<T>

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UpcastAny for T
where T: 'static,

source§

fn upcast_any(&self) -> &(dyn Any + 'static)

Available on crate feature headers only.