pub struct DeprecatedWarningBuilder { /* private fields */ }Expand description
Gradually build a “deprecated” Warning.
Example
use proc_macro_warning::Warning;
let warning = Warning::new_deprecated("my_macro")
.old("my_macro()")
.new("my_macro::new()")
.help_link("https:://example.com")
.span(proc_macro2::Span::call_site())
.build();
// Use the warning in a proc macro
let tokens = quote::quote!(#warning);
let warnings = vec![warning];
// In a proc macro you would expand them inside a module:
quote::quote! {
mod warnings {
#(
#warnings
)*
}
};Implementations§
source§impl DeprecatedWarningBuilder
impl DeprecatedWarningBuilder
sourcepub fn from_title(title: &str) -> DeprecatedWarningBuilder
pub fn from_title(title: &str) -> DeprecatedWarningBuilder
Create a new deprecated warning builder with the given title.
The title must be unique for each warning.
sourcepub fn index(self, index: usize) -> DeprecatedWarningBuilder
pub fn index(self, index: usize) -> DeprecatedWarningBuilder
Set an optional index in case that a warning appears multiple times.
Must be set if a warning appears multiple times.
sourcepub fn old(self, old: &str) -> DeprecatedWarningBuilder
pub fn old(self, old: &str) -> DeprecatedWarningBuilder
The old deprecated way of doing something.
Should complete the sentence “It is deprecated to …”.
sourcepub fn new(self, new: &str) -> DeprecatedWarningBuilder
pub fn new(self, new: &str) -> DeprecatedWarningBuilder
The new way of doing something.
Should complete the sentence “Please instead …”.
sourcepub fn help_link(self, link: &str) -> DeprecatedWarningBuilder
pub fn help_link(self, link: &str) -> DeprecatedWarningBuilder
A help link for the user to explain the transition and justification.
sourcepub fn help_links(self, links: &[&str]) -> DeprecatedWarningBuilder
pub fn help_links(self, links: &[&str]) -> DeprecatedWarningBuilder
Multiple help links for the user to explain the transition and justification.
sourcepub fn span(self, span: Span) -> DeprecatedWarningBuilder
pub fn span(self, span: Span) -> DeprecatedWarningBuilder
The span of the warning.
sourcepub fn maybe_build(self) -> Result<Warning, String>
pub fn maybe_build(self) -> Result<Warning, String>
Build the warning.
sourcepub fn build(self) -> Warning
pub fn build(self) -> Warning
Unwraps Self::maybe_build for convenience.
Trait Implementations§
source§impl Default for DeprecatedWarningBuilder
impl Default for DeprecatedWarningBuilder
source§fn default() -> DeprecatedWarningBuilder
fn default() -> DeprecatedWarningBuilder
Returns the “default value” for a type. Read more