pub struct AtomType { /* private fields */ }
Expand description
A builder for a static atom set and relevant macros
Implementations§
Source§impl AtomType
impl AtomType
Sourcepub fn new(path: &str, macro_name: &str) -> Self
pub fn new(path: &str, macro_name: &str) -> Self
Constructs a new static atom set builder
path
is a path within a crate of the atom type that will be created.
e.g. "FooAtom"
at the crate root or "foo::Atom"
if the generated code
is included in a foo
module.
macro_name
must end with !
.
For example, AtomType::new("foo::FooAtom", "foo_atom!")
will generate:
pub type FooAtom = ::string_cache::Atom<FooAtomStaticSet>;
pub struct FooAtomStaticSet;
impl ::string_cache::StaticAtomSet for FooAtomStaticSet {
// ...
}
#[macro_export]
macro_rules foo_atom {
// Expands to: $crate::foo::FooAtom { … }
}
Sourcepub fn with_atom_doc(&mut self, docs: &str) -> &mut Self
pub fn with_atom_doc(&mut self, docs: &str) -> &mut Self
Add some documentation to the generated Atom type alias.
This can help the user know that the type uses interned strings.
Note that docs
should not contain the ///
at the front of normal docs.
Sourcepub fn with_static_set_doc(&mut self, docs: &str) -> &mut Self
pub fn with_static_set_doc(&mut self, docs: &str) -> &mut Self
Add some documentation to the generated static set.
This can help the user know that this type is zero-sized and just references a static
lookup table, or point them to the Atom
type alias for more info.
Note that docs
should not contain the ///
at the front of normal docs.
Sourcepub fn with_macro_doc(&mut self, docs: &str) -> &mut Self
pub fn with_macro_doc(&mut self, docs: &str) -> &mut Self
Add some documentation to the generated macro.
Note that docs
should not contain the ///
at the front of normal docs.
Sourcepub fn write_to<W>(&mut self, destination: W) -> Result<()>where
W: Write,
pub fn write_to<W>(&mut self, destination: W) -> Result<()>where
W: Write,
Write generated code to destination
.
Sourcepub fn write_to_file(&mut self, path: &Path) -> Result<()>
pub fn write_to_file(&mut self, path: &Path) -> Result<()>
Create a new file at path
and write generated code there.
Typical usage:
.write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join("foo_atom.rs"))