Skip to main content

Options

Struct Options 

Source
#[non_exhaustive]
pub struct Options { pub macro_name: Option<Ident>, pub mock: Option<Path>, pub repeater: Option<Path>, pub allow_primitive: bool, pub allow_std_prelude: bool, pub krate: Option<Path>, pub emit_item: bool, pub layout: Layout, pub docs: bool, pub checks: Vec<Check>, pub metas: Vec<Check>, /* private fields */ }
Expand description

The parsed arguments of #[announce(..)].

Parse it from the attribute’s tokens with syn::parse2; the grammar and the meaning of every option are those of the #[announce] attribute (announce::announce). Build one in code with Options::default and the public fields. Turn it back into attribute arguments with ToTokens (opts.to_token_stream()), for example to hand it to announce().

The most useful field for a library is krate: the path to the announce crate that the generated code uses (see Options::krate()). Without it the path is read from the Cargo.toml of the crate being compiled, which only works when that crate depends on announce itself.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§macro_name: Option<Ident>

macro_name = Name: name of the emitted macro. Default: the item’s name. All the announcements of one item must give the same name, the item’s name where it is not set: one item has one trampoline.

§mock: Option<Path>

mock = path: the item is a stand-in for the item at path.

§repeater: Option<Path>

repeater = path: emit the type-leak table against this repeater trait.

§allow_primitive: bool

type-leak: primitives resolve everywhere (default true).

§allow_std_prelude: bool

type-leak: std prelude names resolve everywhere (default false).

§krate: Option<Path>

crate = path: path to the announce crate in generated code. When it is None, Options::krate() looks the crate up in Cargo.toml.

§emit_item: bool

emit_item = false: do not re-emit the item (it is emitted by someone else). Default true.

§layout: Layout

layout = auto | single | direct: how the trampoline holds the item. Default auto: by the size of the item (advanced).

§docs: bool

docs = true: keep the doc attributes (#[doc = ".."], so /// and //! too) in the item that callbacks and checks receive. Default false: they are removed there, which makes the trampoline smaller. The item that is compiled keeps its docs either way.

§checks: Vec<Check>

Checks: bare path / path(args) entries. They run at the definition.

§metas: Vec<Check>

meta = path(args): listed in META like a check, but never invoked.

Implementations§

Source§

impl Options

Source

pub fn krate(&self) -> Path

The path to the announce crate that the generated code uses.

crate = .. (the krate field) wins. Otherwise it is the name that the Cargo.toml of the crate being compiled (CARGO_MANIFEST_DIR) gives to its announce dependency, renames included, else ::announce.

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Options

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Parse for Options

Source§

fn parse(input: ParseStream<'_>) -> Result<Self>

Source§

impl ToTokens for Options

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

Write self to the given TokenStream. Read more
Source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
Source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Spanned for T
where T: Spanned + ?Sized,

Source§

fn span(&self) -> Span

Returns a Span covering the complete contents of this syntax tree node, or Span::call_site() if this node is empty.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.