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]
pub fn for_build(mod_name: &str) -> Result<ConstWriter>
[src]
Create a ConstWriter to be used for your crate's build.rs
pub fn from_path(path: &Path) -> Result<ConstWriter>
[src]
Create a new ConstWriter to write to an path. If a file already exists at the path then it will be deleted.
pub fn finish_dependencies(self) -> ConstValueWriter
[src]
finish writing dependencies and start writing constants
pub fn add_dependency(&mut self, lib: &str)
[src]
Add a dependency to your constants file.
pub fn add_raw(&mut self, raw: &str)
[src]
Add a raw string to the constants file.
This method only changes raw
by adding a \n
at the end.