pub struct Config { /* private fields */ }
Expand description
The starting point of cpp_to_rust
API.
Create a Config
object, set its properties,
add custom functions if necessary, and start
the processing with Config::exec
.
Implementations
sourceimpl Config
impl Config
sourcepub fn new(crate_properties: CrateProperties) -> Config
pub fn new(crate_properties: CrateProperties) -> Config
Creates a Config
.
crate_properties
are used in Cargo.toml of the generated crate.
sourcepub fn set_crate_template_path<P: Into<PathBuf>>(&mut self, path: P)
pub fn set_crate_template_path<P: Into<PathBuf>>(&mut self, path: P)
Sets the directory containing additional files for the crate.
Any files and directories found in the crate template will be copied
to the generated crate’s directory, although some of them (such as Cargo.toml
)
may be overwritten with the generates files. It’s common to put tests
and
examples
subdirectories in the crate template so that cargo
recognizes them
automatically in the generated crate.
If you want to add some extra code
to the generated modules, put src/module_name.rs
file in the crate template and
add include_generated!();
line in the file. This line will be replaced with
the generated content. You can also add extra modules as separate files,
but you’ll also need to create src/lib.rs
in the crate template and
declare new module in it using [pub] mod module_name;
. Use include_generated!();
in src/lib.rs
to include declaration of automatically generated modules.
If the crate template contains rustfmt.toml
file, it’s used to format the generated
Rust code instead of the default rustfmt.toml
.
Creating crate template is optional. The generator can make a crate without a template.
sourcepub fn set_dependent_cpp_crates(&mut self, paths: Vec<String>)
pub fn set_dependent_cpp_crates(&mut self, paths: Vec<String>)
Sets list of names of crates created with cpp_to_rust
.
The generator will integrate API of the current library with its
dependencies and re-use their types.
sourcepub fn add_cpp_parser_blocked_name(&mut self, path: CppPath)
pub fn add_cpp_parser_blocked_name(&mut self, path: CppPath)
Adds a C++ identifier that should be skipped
by the C++ parser. Identifier can contain namespaces
and nested classes, with ::
separator (like in
C++ identifiers). Identifier may refer to a method,
a class, a enum or a namespace. All entities inside blacklisted
entity (e.g. the methods of a blocked class or
the contents of a blocked namespace)
will also be skipped.
All class methods with names matching the blocked name
will be skipped, regardless of class name.
sourcepub fn add_cpp_parser_blocked_names<Iter>(&mut self, items: Iter)where
Iter: IntoIterator<Item = CppPath>,
pub fn add_cpp_parser_blocked_names<Iter>(&mut self, items: Iter)where
Iter: IntoIterator<Item = CppPath>,
Adds multiple blocked names. See Config::add_cpp_parser_blocked_name
.
sourcepub fn add_cpp_parser_argument<P: Into<String>>(&mut self, lib: P)
pub fn add_cpp_parser_argument<P: Into<String>>(&mut self, lib: P)
Adds a command line argument for clang C++ parser.
Note that this value is not used when building the wrapper library.
Use Config::cpp_build_config_mut
or a similar method to
configure building the wrapper library.
sourcepub fn add_cpp_parser_arguments<Item, Iter>(&mut self, items: Iter)where
Item: Into<String>,
Iter: IntoIterator<Item = Item>,
pub fn add_cpp_parser_arguments<Item, Iter>(&mut self, items: Iter)where
Item: Into<String>,
Iter: IntoIterator<Item = Item>,
Adds multiple command line arguments for clang C++ parser.
See Config::add_cpp_parser_argument
.
sourcepub fn set_cpp_build_paths(&mut self, paths: CppBuildPaths)
pub fn set_cpp_build_paths(&mut self, paths: CppBuildPaths)
Sets CppBuildPaths
value for this config. These paths
are used for testing C++ methods while processing the library,
but they are not used when building the generated crate.
sourcepub fn add_target_include_path<P: Into<PathBuf>>(&mut self, path: P)
pub fn add_target_include_path<P: Into<PathBuf>>(&mut self, path: P)
Adds path to an include directory or an include file of the target library. Any C++ types and methods will be parsed and used only if they are declared within one of files or directories added with this method.
If no target include paths are added, all types and methods will be used. Most libraries include system headers and other libraries’ header files, so this mode is often unwanted.
sourcepub fn add_include_directive<P: Into<PathBuf>>(&mut self, path: P)
pub fn add_include_directive<P: Into<PathBuf>>(&mut self, path: P)
Adds an include directive. Each directive will be added
as #include <path>
to the input file for the C++ parser.
File name only paths or relative paths should be used in this method.
sourcepub fn add_cpp_filtered_namespace(&mut self, namespace: CppPath)
pub fn add_cpp_filtered_namespace(&mut self, namespace: CppPath)
Adds a namespace to filter out before rust code generation.
sourcepub fn add_cpp_filtered_namespaces(
&mut self,
namespaces: impl IntoIterator<Item = CppPath>
)
pub fn add_cpp_filtered_namespaces(
&mut self,
namespaces: impl IntoIterator<Item = CppPath>
)
Adds multiple namespaces to filter out before rust code generation.
sourcepub fn set_movable_types(&mut self, names: Vec<CppPath>)
pub fn set_movable_types(&mut self, names: Vec<CppPath>)
Overrides automatic selection of type allocation place for type_name
and uses place
instead. See CppTypeAllocationPlace
for more information.
sourcepub fn set_cpp_build_config(&mut self, cpp_build_config: CppBuildConfig)
pub fn set_cpp_build_config(&mut self, cpp_build_config: CppBuildConfig)
Sets CppBuildConfig
value that will be passed to the build script
of the generated crate.
sourcepub fn cpp_build_config_mut(&mut self) -> &mut CppBuildConfig
pub fn cpp_build_config_mut(&mut self) -> &mut CppBuildConfig
Allows to change CppBuildConfig
value that will be passed to the build script
of the generated crate.
pub fn set_cpp_lib_version<S: Into<String>>(&mut self, version: S)
pub fn cpp_lib_version(&self) -> Option<&str>
pub fn add_custom_processing_step(&mut self, step: ProcessingStep)
sourcepub fn crate_properties(&self) -> &CrateProperties
pub fn crate_properties(&self) -> &CrateProperties
Returns crate properties passed to Config::new
.
sourcepub fn crate_template_path(&self) -> Option<&PathBuf>
pub fn crate_template_path(&self) -> Option<&PathBuf>
Returns value set by Config::set_crate_template_path
.
sourcepub fn dependent_cpp_crates(&self) -> &[String]
pub fn dependent_cpp_crates(&self) -> &[String]
Returns value set by Config::set_dependent_cpp_crates
.
sourcepub fn cpp_parser_blocked_names(&self) -> &[CppPath]
pub fn cpp_parser_blocked_names(&self) -> &[CppPath]
Returns names added with Config::add_cpp_parser_blocked_name
and similar methods.
sourcepub fn cpp_parser_arguments(&self) -> &[String]
pub fn cpp_parser_arguments(&self) -> &[String]
Returns names added with Config::add_cpp_parser_argument
and similar methods.
sourcepub fn cpp_build_paths(&self) -> &CppBuildPaths
pub fn cpp_build_paths(&self) -> &CppBuildPaths
Returns values added by Config::set_cpp_build_paths
.
sourcepub fn target_include_paths(&self) -> &[PathBuf]
pub fn target_include_paths(&self) -> &[PathBuf]
Returns values added by Config::add_target_include_path
.
sourcepub fn include_directives(&self) -> &[PathBuf]
pub fn include_directives(&self) -> &[PathBuf]
Returns values added by Config::add_include_directive
.
sourcepub fn cpp_filtered_namespaces(&self) -> &[CppPath]
pub fn cpp_filtered_namespaces(&self) -> &[CppPath]
Returns values added by Config::add_cpp_filtered_namespace
.
sourcepub fn cpp_build_config(&self) -> &CppBuildConfig
pub fn cpp_build_config(&self) -> &CppBuildConfig
Returns current CppBuildConfig
value.
sourcepub fn movable_types(&self) -> &[CppPath]
pub fn movable_types(&self) -> &[CppPath]
Returns values added by Config::set_movable_types
.
Keys of the hash map are names of C++ types.