Struct string_cache_codegen::AtomType
source · [−]pub struct AtomType { /* private fields */ }
Expand description
A builder for a static atom set and relevant macros
Implementations
sourceimpl 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 atoms<I>(&mut self, iter: I) -> &mut Self where
I: IntoIterator,
I::Item: AsRef<str>,
pub fn atoms<I>(&mut self, iter: I) -> &mut Self where
I: IntoIterator,
I::Item: AsRef<str>,
Adds multiple atoms to the builder
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"))
Auto Trait Implementations
impl RefUnwindSafe for AtomType
impl Send for AtomType
impl Sync for AtomType
impl Unpin for AtomType
impl UnwindSafe for AtomType
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more