3 releases

0.1.2 Sep 25, 2022
0.1.1 Sep 25, 2022
0.1.0 Sep 25, 2022

#2082 in Development tools

31 downloads per month

MIT/Apache

33KB
593 lines

intern-str-codegen

Convert a Graph into its Rust code equivalent.

This allows one to generate a Graph at build time and then insert it into the binary. This allows large graphs to be used in embedded systems with next to no cost.

License

intern_str is licensed under one of the following:

at your option.


lib.rs:

Convert a Graph into its Rust code equivalent.

This allows one to generate a Graph at build time and then insert it into the binary. This allows large graphs to be used in embedded systems with next to no cost.

Example

use intern_str::{Graph, Segmentable};
use intern_str::builder::{Builder, Utf8Graph};
use intern_str_codegen::generate;
use std::{fs::File, io::{prelude::*, BufWriter}};

let mut builder = Builder::<_, Utf8Graph>::new();

builder.add("hello", 1).unwrap();
builder.add("world", 2).unwrap();

let mut buffer = Vec::new();
let graph = builder.build(&mut buffer);

// Convert to string.
let code = generate(
    &graph,
    "&'static str",
    "usize",
    |f, out| write!(f, "{}", out),
);

let mut out = BufWriter::new(File::create("graph.rs").unwrap());
writeln!(
    out,
    "const GRAPH: intern_str::Graph<'static, 'static, &'static str, usize> = {}",
    code,
)?;

Dependencies