macro_rules! with_api {
    ($S:ident, $self:ident, $m:ident) => { ... };
}
🔬This is a nightly-only experimental API. (proc_macro_internals #27812)
Expand description

Higher-order macro describing the server RPC API, allowing automatic generation of type-safe Rust APIs, both client-side and server-side.

with_api!(MySelf, my_self, my_macro) expands to:

my_macro! {
    // ...
    Literal {
        // ...
        fn character(ch: char) -> MySelf::Literal;
        // ...
        fn span(my_self: &MySelf::Literal) -> MySelf::Span;
        fn set_span(my_self: &mut MySelf::Literal, span: MySelf::Span);
    },
    // ...
}
Run

The first two arguments serve to customize the arguments names and argument/return types, to enable several different usecases:

If my_self is just self, then each fn signature can be used as-is for a method. If it’s anything else (self_ in practice), then the signatures don’t have a special self argument, and can, therefore, have a different one introduced.

If MySelf is just Self, then the types are only valid inside a trait or a trait impl, where the trait has associated types for each of the API types. If non-associated types are desired, a module name (self in practice) can be used instead of Self.