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
impl BuilderOptions
Sourcepub fn new_with_files<P: AsRef<Path>, I: IntoIterator<Item = P>>(
files: I,
) -> Self
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.
Sourcepub fn set_compiler<S: AsRef<str>>(self, compiler: S) -> Self
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 standardPATH
resolution.
Sourcepub fn set_output_path<P: AsRef<Path>>(self, output_path: P) -> Self
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.
Sourcepub fn set_symlink_directory<P: AsRef<Path>>(self, symlink_path: P) -> Self
pub fn set_symlink_directory<P: AsRef<Path>>(self, symlink_path: P) -> Self
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.
Sourcepub fn supress_buildrs_directives(self) -> Self
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.
Sourcepub fn compile(self) -> Result
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
impl Clone for BuilderOptions
Source§fn clone(&self) -> BuilderOptions
fn clone(&self) -> BuilderOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more