Struct build_const::ConstWriter [] [src]

pub struct ConstWriter { /* fields omitted */ }

Primary object used to write constant files.

Example

use build_const::ConstWriter;
 
// use `for_build` in `build.rs`
let mut consts = ConstWriter::from_path(
    &Path::new("/tmp/constants.rs")
).unwrap();
 
// add an external dependency (`use xyz::Point`)
consts.add_dependency("xyz::Point");
 
// finish dependencies and starting writing constants
let mut consts = consts.finish_dependencies();

// add an array of values
let values: Vec<u8> = vec![1, 2, 3, 36];
consts.add_array("ARRAY", "u8", &values);

// Add a value that is a result of "complex" calculations
consts.add_value("VALUE", "u8", values.iter().sum::<u8>());
 
// Add a value from an external crate (must implement `Debug`)
consts.add_value("VALUE", "Point", &Point { x: 3, y: 7});

Methods

impl ConstWriter
[src]

[src]

Create a ConstWriter to be used for your crate's build.rs

[src]

Create a new ConstWriter to write to an path. If a file already exists at the path then it will be deleted.

[src]

finish writing dependencies and start writing constants

[src]

Add a dependency to your constants file.

[src]

Add a raw string to the constants file.

This method only changes raw by adding a \n at the end.

Trait Implementations

Auto Trait Implementations

impl Send for ConstWriter

impl Sync for ConstWriter