Struct rstml::recoverable::RecoverableContext
source · pub struct RecoverableContext { /* private fields */ }
Expand description
Context that is provided in ParseRecoverable
interface.
Used to save Diagnostic
messages or syn::Result
.
Also can be extended with user needs through RecoveryConfig
.
Implementations§
source§impl RecoverableContext
impl RecoverableContext
sourcepub fn parse_simple_until<T: Parse, E: Parse>(
&mut self,
input: ParseStream<'_>,
) -> Option<(T, E)>
pub fn parse_simple_until<T: Parse, E: Parse>( &mut self, input: ParseStream<'_>, ) -> Option<(T, E)>
Like parse_simple
, but splits the tokenstream at E
first only
parsing the tokens before it as T
.
Note: This is an internal function exported to make parsing of
custom nodes easier. It has some quirks, e.g.,
parse_simple_until<Expr, Token![>]>
, would not support any
Expr
containing a >
.
It is not considered stable.
sourcepub fn parse_tokens_until_call<T, F, U>(
&mut self,
input: ParseStream<'_>,
stop_fn: F,
) -> (Vec<T>, Option<U>)
pub fn parse_tokens_until_call<T, F, U>( &mut self, input: ParseStream<'_>, stop_fn: F, ) -> (Vec<T>, Option<U>)
Parse array of toknes using recoverable parser. Stops parsing when other branch could parse anything.
Note: This is an internal function exported to make parsing of custom nodes easier. It is not considered stable.
Example:
let tokens:proc_macro2::TokenStream = quote::quote!(few idents seperated by spaces and then minus sign - that will stop parsing).into();
let concat_idents_without_minus = |input: ParseStream| -> Result<String> {
let (idents, _minus) = parser.parse_tokens_until::<Ident, _, _>(input, |i|
i.parse::<Token![-]>()
)?;
let mut new_str = String::new();
for ident in idents {
new_str.push_str(&ident.to_string())
}
// .. skip rest idents in input
Ok(new_str)
};
let concated = concat_idents_without_minus.parse2(tokens)?;
assert_eq!(concated, "fewidentsseperatedbyspacesandthenminussign");
sourcepub fn parse_tokens_with_conflicted_ending<T, F, U>(
&mut self,
input: ParseStream<'_>,
separator: F,
) -> (Vec<T>, Option<U>)
pub fn parse_tokens_with_conflicted_ending<T, F, U>( &mut self, input: ParseStream<'_>, separator: F, ) -> (Vec<T>, Option<U>)
Two-phase parsing, firstly find separator, and then parses array of
tokens before separator.
For simple input this method will work like
parse_tokens_until
.
Internally it creates intermediate `TokenStream`` and
copy of all tokens until separator token is found. It is usefull
when separator (or it’s part) can be treated as part of token T.
Note: This is an internal function exported to make parsing of custom nodes easier. It is not considered stable.
Example:
let tokens = quote!(some_expr_seperated + with - lt_gt * tokens <> other part);
In this example “<” can can be parsed as part of expression, but we want to split tokens after “<>” was found. So instead of parsing all input as expression, firstly we need to seperate it into two chunks.
source§impl RecoverableContext
impl RecoverableContext
pub fn new(config: RecoveryConfig) -> Self
pub fn config(&self) -> &RecoveryConfig
pub fn parse_result<T>(self, val: Option<T>) -> ParsingResult<T>
sourcepub fn parse_simple<T: Parse>(&mut self, input: ParseStream<'_>) -> Option<T>
pub fn parse_simple<T: Parse>(&mut self, input: ParseStream<'_>) -> Option<T>
Parse token using syn::parse::Parse
sourcepub fn parse_mixed_fn<F, T>(
&mut self,
input: ParseStream<'_>,
parser: F,
) -> Option<T>
pub fn parse_mixed_fn<F, T>( &mut self, input: ParseStream<'_>, parser: F, ) -> Option<T>
Parse token using closure
sourcepub fn parse_recoverable<T: ParseRecoverable>(
&mut self,
input: ParseStream<'_>,
) -> Option<T>
pub fn parse_recoverable<T: ParseRecoverable>( &mut self, input: ParseStream<'_>, ) -> Option<T>
Parse token using ParseRecoverable
sourcepub fn save_diagnostics<T>(&mut self, val: Result<T>) -> Option<T>
pub fn save_diagnostics<T>(&mut self, val: Result<T>) -> Option<T>
Save diagnostic message of syn::Result
and convert result to Option
, that can be used directly
as output in ParseRecoverable::parse_recoverable
sourcepub fn push_diagnostic(&mut self, diagnostic: impl Into<Diagnostic>)
pub fn push_diagnostic(&mut self, diagnostic: impl Into<Diagnostic>)
Push custom message of syn::Error
or
proc_macro2_diagnostics::Diagnostic
Trait Implementations§
source§impl Clone for RecoverableContext
impl Clone for RecoverableContext
source§fn clone(&self) -> RecoverableContext
fn clone(&self) -> RecoverableContext
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RecoverableContext
impl Debug for RecoverableContext
source§impl Default for RecoverableContext
impl Default for RecoverableContext
source§fn default() -> RecoverableContext
fn default() -> RecoverableContext
source§impl PartialEq for RecoverableContext
impl PartialEq for RecoverableContext
impl Eq for RecoverableContext
Auto Trait Implementations§
impl Freeze for RecoverableContext
impl !RefUnwindSafe for RecoverableContext
impl !Send for RecoverableContext
impl !Sync for RecoverableContext
impl Unpin for RecoverableContext
impl !UnwindSafe for RecoverableContext
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.bright_black());
source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.bright_green());
source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.bright_yellow());
source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.bright_magenta());
source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.bright_white());
source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.on_bright_black());
source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.on_bright_green());
source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightYellow
.
§Example
println!("{}", value.on_bright_yellow());
source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlue
.
§Example
println!("{}", value.on_bright_blue());
source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightMagenta
.
§Example
println!("{}", value.on_bright_magenta());
source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightCyan
.
§Example
println!("{}", value.on_bright_cyan());
source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.on_bright_white());
source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::Underline
.
§Example
println!("{}", value.underline());
source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
§Example
println!("{}", value.rapid_blink());
source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);