pub struct LitBool {
pub value: bool,
pub span: Span,
}Expand description
A parsed boolean literal bundled with its source location.
true and false are identifier tokens in Rust’s token stream, not literal
tokens. The FromLit implementation overrides FromLit::from_ident to handle
them. FromLit::from_lit always returns an error.
Use LitBool when you need the span. Use bool when you only need the value.
§Example
ⓘ
use litext::{litext, TokenStream};
use litext::literal::LitBool;
pub fn my_macro(input: TokenStream) -> TokenStream {
let lit: LitBool = litext!(input as LitBool);
if !lit.value() {
return comperr::error(lit.span(), "feature must be enabled");
}
quote::quote! { /* use lit.value() */ }
}Fields§
§value: boolThe parsed boolean value.
span: SpanThe source location of the literal.
Implementations§
Trait Implementations§
Source§impl FromLit for LitBool
impl FromLit for LitBool
Source§fn from_ident(ident: Ident) -> Result<Self, TokenStream>
fn from_ident(ident: Ident) -> Result<Self, TokenStream>
Source§fn from_negative_lit(lit: Literal) -> Result<Self, TokenStream>
fn from_negative_lit(lit: Literal) -> Result<Self, TokenStream>
Source§impl ToTokens for LitBool
impl ToTokens for LitBool
Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
true and false are Ident tokens, not Literal tokens.
Auto Trait Implementations§
impl Freeze for LitBool
impl RefUnwindSafe for LitBool
impl !Send for LitBool
impl !Sync for LitBool
impl Unpin for LitBool
impl UnsafeUnpin for LitBool
impl UnwindSafe for LitBool
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
Mutably borrows from an owned value. Read more