Struct AtomType

Source
pub struct AtomType { /* private fields */ }
Expand description

A builder for a static atom set and relevant macros

Implementations§

Source§

impl AtomType

Source

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 { … }
}
Source

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.

Source

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.

Source

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.

Source

pub fn atom(&mut self, s: &str) -> &mut Self

Adds an atom to the builder

Source

pub fn atoms<I>(&mut self, iter: I) -> &mut Self
where I: IntoIterator, I::Item: AsRef<str>,

Adds multiple atoms to the builder

Source

pub fn write_to<W>(&mut self, destination: W) -> Result<()>
where W: Write,

Write generated code to destination.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.