Expand description
§Autocxx
This project is a tool for calling C++ from Rust in a heavily automated, but safe, fashion.
The intention is that it has all the fluent safety from cxx whilst generating interfaces automatically from existing C++ headers using a variant of bindgen. Think of autocxx as glue which plugs bindgen into cxx.
For full documentation, see the manual.
§Overview
ⓘ
autocxx::include_cpp! {
    #include "url/origin.h"
    generate!("url::Origin")
    safety!(unsafe_ffi)
}
fn main() {
    let o = ffi::url::Origin::CreateFromNormalizedTuple("https",
        "google.com", 443);
    let uri = o.Serialize();
    println!("URI is {}", uri.to_str().unwrap());
}§License and usage notes
This is not an officially supported Google product.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Re-exports§
Modules§
- extern_
rust  - Tools to export Rust code to C++.
 - prelude
 - Imports which you’re likely to want to use.
 - subclass
 - Module to make Rust subclasses of C++ classes. See 
CppSubclassfor details. 
Macros§
- block
 - Entirely block some type from appearing in the generated code. This can be useful if there is a type which is not understood by bindgen or autocxx, and incorrect code is otherwise generated. This is ‘greedy’ in the sense that any functions/methods which take or return such a type will also be blocked.
 - block_
constructors  - Avoid generating implicit constructors for this type. The rules for when to generate C++ implicit constructors are complex, and if autocxx gets it wrong, you can block such constructors using this.
 - concrete
 - A concrete type to make, for example
concrete!("Container<Contents>"). All types must already be on the allowlist by having usedgenerate!or similar. - exclude_
impls  - Whether to avoid generating 
cxx::UniquePtrandcxx::Vectorimplementations. This is primarily useful for reducing test cases and shouldn’t be used in normal operation. - exclude_
utilities  - Skip the normal generation of a 
make_stringfunction and other utilities which we might generate normally. A directive to be included inside include_cpp - see include_cpp for general information. - extern_
cpp_ opaque_ type  - Indicates that a C++ type is not to be generated by autocxx in this case,
but instead should refer to some pre-existing Rust type. Unlike
extern_cpp_type!, there’s no need for the size and alignment of this type to be correct. - extern_
cpp_ type  - Indicates that a C++ type is not to be generated by autocxx in this case, but instead should refer to some pre-existing Rust type.
 - extern_
rust_ type  - See 
extern_rust::extern_rust_type. - generate
 - Generate Rust bindings for the given C++ type or function. A directive to be included inside include_cpp - see include_cpp for general information. See also generate_pod.
 - generate_
all  - Generate Rust bindings for all C++ types and functions found. Highly experimental and not recommended. A directive to be included inside include_cpp - see include_cpp for general information. See also generate.
 - generate_
ns  - Generate Rust bindings for all C++ types and functions in a given namespace. A directive to be included inside include_cpp - see include_cpp for general information. See also generate.
 - generate_
pod  - Generate as “plain old data” and add to allowlist. Generate Rust bindings for the given C++ type such that it can be passed and owned by value in Rust. This only works for C++ types which have trivial move constructors and no destructor - you’ll encounter a compile error otherwise. If your type doesn’t match that description, use generate instead, and own the type using UniquePtr. A directive to be included inside include_cpp - see include_cpp for general information.
 - include
 - Include a C++ header. A directive to be included inside include_cpp - see include_cpp for details
 - include_
cpp  - Include some C++ headers in your Rust project.
 - instantiable
 - Indicates that a C++ type can definitely be instantiated. This has effect only in a very specific case:
 - name
 - The name of the mod to be generated with the FFI code.
The default is 
ffi. - pod
 - Generate as “plain old data”. For use with generate_all and similarly experimental.
 - rust_
type Deprecated  - Deprecated - use 
extern_rust_typeinstead. - safety
 - Specifies a global safety policy for functions generated
from these headers. By default (without such a 
safety!directive) all such functions are marked asunsafeand therefore can only be called within anunsafe {}block or someunsafefunction which you create. - subclass
 - See 
subclass::subclass. 
Structs§
- Binding
Generation Failure  - autocxx couldn’t generate these bindings. If you come across a method, type or function which refers to this type, it indicates that autocxx couldn’t generate that binding. A documentation comment should be attached indicating the reason.
 - CppMut
Ref  - A C++ non-const reference. These are different from Rust’s 
&mut Tin that several C++ references can exist to the same underlying data (“aliasing”) and that’s not permitted for regular Rust references. - CppPin
 - A newtype wrapper which causes the contained object to obey C++ reference semantics rather than Rust reference semantics. That is, multiple aliasing mutable C++ references may exist to the contents.
 - CppRef
 - A C++ const reference. These are different from Rust’s 
&Tin that these may exist even while the object is mutated elsewhere. See alsoCppMutReffor the mutable equivalent. - CppUnique
PtrPin  - Any newtype wrapper which causes the contained 
UniquePtrtarget to obey C++ reference semantics rather than Rust reference semantics. That is, multiple aliasing mutable C++ references may exist to the contents. - c_
char16_ t  - A C++ 
char16_t - c_int
 - Newtype wrapper for an int
 - c_long
 - Newtype wrapper for a long
 - c_
longlong  - Newtype wrapper for a long long
 - c_short
 - Newtype wrapper for an short
 - c_uchar
 - Newtype wrapper for an unsigned char
 - c_uint
 - Newtype wrapper for an unsigned int
 - c_ulong
 - Newtype wrapper for an unsigned long
 - c_
ulonglong  - Newtype wrapper for an unsigned long long
 - c_
ushort  - Newtype wrapper for an unsigned short
 - c_void
 - Newtype wrapper for a C void. Only useful as a 
*c_void 
Traits§
- AsCpp
MutRef  - Any type which can return a C++ reference to its contents.
 - AsCpp
Ref  - Any type which can return a C++ reference to its contents.
 - PinMut
 - Equivalent to 
std::convert::AsMut, but returns a pinned mutable reference such that cxx methods can be called on it. - RValue
Param  - A trait representing a parameter to a C++ function which is received by rvalue (i.e. by move).
 - Value
Param  - A trait representing a parameter to a C++ function which is received by value.
 - Within
Box  - Provides utility functions to emplace any 
moveit::Newinto aBox. Automatically imported by the autocxx prelude and implemented by any (autocxx-related)moveit::New. - Within
BoxTrivial  - Emulates the 
WithinBoxtrait, but for trivial (plain old data) types. This allows such types to behave identically if a type is changed fromgenerate!togenerate_pod!. - Within
Unique Ptr  - Provides utility functions to emplace any 
moveit::Newinto acxx::UniquePtr. Automatically imported by the autocxx prelude and implemented by any (autocxx-related)moveit::New. - Within
Unique PtrTrivial  - Emulates the 
WithinUniquePtrtrait, but for trivial (plain old data) types. This allows such types to behave identically if a type is changed fromgenerate!togenerate_pod!. 
Functions§
- as_copy
 - Explicitly force a value parameter to be taken by copy.
 - as_mov
 - Explicitly force a value parameter to be taken using C++ move semantics.
 - as_new
 - Explicitly force a value parameter to be taken using any type of 
crate::moveit::new::New, i.e. a constructor.