Struct capnpc::CompilerCommand

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

A builder object for schema compiler commands.

Implementations§

source§

impl CompilerCommand

source

pub fn new() -> Self

Creates a new, empty command.

source

pub fn file<P>(&mut self, path: P) -> &mut Self
where P: AsRef<Path>,

Adds a file to be compiled.

source

pub fn src_prefix<P>(&mut self, prefix: P) -> &mut Self
where P: AsRef<Path>,

Adds a –src-prefix flag. For all files specified for compilation that start with prefix, removes the prefix when computing output filenames.

source

pub fn import_path<P>(&mut self, dir: P) -> &mut Self
where P: AsRef<Path>,

Adds an –import_path flag. Adds dir to the list of directories searched for absolute imports.

source

pub fn crate_provides( &mut self, crate_name: impl Into<String>, files: impl IntoIterator<Item = u64> ) -> &mut Self

Specify that crate_name provides generated code for files.

This means that when your schema refers to types defined in files we will generate Rust code that uses identifiers in crate_name.

Arguments
  • crate_name: The Rust identifier of the crate
  • files: the Capnp file ids the crate provides generated code for
When to use

You only need this when your generated code needs to refer to types in the external crate. If you just want to use an annotation and the argument to that annotation is a builtin type (e.g. $Json.name) this isn’t necessary.

Example

If you write a schema like so

// my_schema.capnp

using Json = import "/capnp/compat/json.capnp";

struct Foo {
    value @0 :Json.Value;
}

you’d look at json.capnp to see its capnp id.

// json.capnp

# Copyright (c) 2015 Sandstorm Development Group, Inc. and contributors ...
@0x8ef99297a43a5e34;

If you want the foo::Builder::get_value method generated for your schema to return a capnp_json::json_capnp::value::Reader you’d add a dependency on capnp_json to your Cargo.toml and specify it provides json.capnp in your build.rs.

// build.rs

capnpc::CompilerCommand::new()
    .crate_provides("json_capnp", [0x8ef99297a43a5e34])
    .file("my_schema.capnp")
    .run()
    .unwrap();
source

pub fn no_standard_import(&mut self) -> &mut Self

Adds the –no-standard-import flag, indicating that the default import paths of /usr/include and /usr/local/include should not bet included.

source

pub fn output_path<P>(&mut self, path: P) -> &mut Self
where P: AsRef<Path>,

Sets the output directory of generated code. Default is OUT_DIR

source

pub fn capnp_executable<P>(&mut self, path: P) -> &mut Self
where P: AsRef<Path>,

Specify the executable which is used for the ‘capnp’ tool. When this method is not called, the command looks for a name ‘capnp’ on the system (e.g. in working directory or in PATH environment variable).

source

pub fn default_parent_module( &mut self, default_parent_module: Vec<String> ) -> &mut Self

Sets the default parent module. This indicates the scope in your crate where you will add a module containing the generated code. For example, if you set this option to vec!["foo".into(), "bar".into()], and you are generating code for baz.capnp, then your crate should have this structure:

pub mod foo {
   pub mod bar {
       pub mod baz_capnp {
           include!(concat!(env!("OUT_DIR"), "/baz_capnp.rs"));
       }
   }
}

This option can be overridden by the parentModule annotation defined in rust.capnp.

If this option is unset, the default is the crate root.

source

pub fn raw_code_generator_request_path<P>(&mut self, path: P) -> &mut Self
where P: AsRef<Path>,

If set, the generator will also write a file containing the raw code generator request to the specified path.

source

pub fn run(&mut self) -> Result<()>

Runs the command. Returns an error if OUT_DIR or a custom output directory was not set, or if capnp compile fails.

Trait Implementations§

source§

impl Default for CompilerCommand

source§

fn default() -> CompilerCommand

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

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, 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.