Struct flatbuffers_build::BuilderOptions

source ·
pub struct BuilderOptions { /* private fields */ }
Expand description

Builder for options to the flatc compiler options. When consumed using BuilderOptions::compile, this generates rust code from the flatbuffer definition files provided. The basic usage for this struct looks something like this:

use flatbuffers_build::BuilderOptions;

BuilderOptions::new_with_files(["some_file.fbs", "some_other_file.fbs"])
    .compile()
    .expect("flatbuffer compilation failed");

This struct operates as a builder pattern, so you can do things like set the flatc path:

BuilderOptions::new_with_files(["some_file.fbs", "some_other_file.fbs"])
    .set_compiler("/some/path/to/flatc")
    .compile()
    .expect("flatbuffer compilation failed");

Consult the functions bellow for more details.

Implementations§

source§

impl BuilderOptions

source

pub fn new_with_files<P: AsRef<Path>, I: IntoIterator<Item = P>>( files: I ) -> Self

Create a new builder for the compiler options. We purely initialise with an iterable of files to compile. To actually build, refer to the Self::compile function. Note that the order of the files is actually important, as incorrect ordering will result in incorrect generated code with missing components. You should always put dependencies of other files earlier in the list. In other words, if schema_a.fbs imports schema_b.fbs, then you’d want to call this with:

BuilderOptions::new_with_files(["schema_b.fbs", "schema_a.fbs"]);
§Arguments
  • files - An iterable of files that should be compiled into rust code. No glob resolution happens here, and all paths MUST match to real files, either as absolute paths or relative to the current working directory.
source

pub fn set_compiler<S: AsRef<str>>(self, compiler: S) -> Self

Set the path of the flatc binary to use as a compiler. If no such path is provided, we will default to first using whatever’s set in the FLATC_PATH environment variable, or if that’s not set, we will let the system resolve using standard PATH resolution.

§Arguments
  • compiler - Path to the compiler to run. This can also be a name that we should resolve using standard PATH resolution.
source

pub fn set_output_path<P: AsRef<Path>>(self, output_path: P) -> Self

Call this to set the output directory of the protobufs. If you don’t set this, we will default to writing to ${OUT_DIR}/flatbuffers.

§Arguments
  • output_path - The directory to write the files to.

Set a path to create a symlink that points to the output files. This is commonly used to symlink to a folder under src so you can normally pull in the generated code as a module. We recommend always calling this and setting it to src/generated or something similar.

§Arguments
  • symlink_path - Path to generate the symlink to.
source

pub fn supress_buildrs_directives(self) -> Self

Set this if you’re not running from a build.rs script and don’t want us to print the build.rs instructions/directives that we would otherwise print in stdout.

source

pub fn compile(self) -> Result

Call this function to trigger compilation. Will write the compiled protobufs to the specified directory, or to ${OUT_DIR}/flatbuffers by default.

§Errors

Will fail if any error happens during compilation, including:

  • Invalid protoc files
  • Unsupported flatc version
  • flatc exiting with a non-zero error code For more details, see Error.

Trait Implementations§

source§

impl Clone for BuilderOptions

source§

fn clone(&self) -> BuilderOptions

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BuilderOptions

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for BuilderOptions

source§

fn eq(&self, other: &BuilderOptions) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for BuilderOptions

source§

impl StructuralPartialEq for BuilderOptions

Auto Trait Implementations§

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> 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.