#[repr(transparent)]pub struct PreservedStrExpr(pub Expr);
Expand description
A wrapper around Expr
that preserves the original expression
without evaluating it.
For compatibility reasons, darling
evaluates the expression inside string
literals, which might be undesirable. In many cases,
[darling::util::parse_expr::preserve_str_literal
] can be used. However,
when using Expr
inside a container (such as a
HashMap
), it is not possible to use it.
This wrapper preserves the original expression without evaluating it.
§Example
ⓘ
#[derive(FromMeta)]
#[darling(attributes(demo))]
struct Demo {
option: Option<HashMap<syn::Ident, PreservedStrExpr>>,
}
Tuple Fields§
§0: Expr
Trait Implementations§
Source§impl Clone for PreservedStrExpr
impl Clone for PreservedStrExpr
Source§fn clone(&self) -> PreservedStrExpr
fn clone(&self) -> PreservedStrExpr
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for PreservedStrExpr
impl Debug for PreservedStrExpr
Source§impl From<Expr> for PreservedStrExpr
impl From<Expr> for PreservedStrExpr
Source§fn from(value: Expr) -> PreservedStrExpr
fn from(value: Expr) -> PreservedStrExpr
Converts to this type from the input type.
Source§impl From<PreservedStrExpr> for Expr
impl From<PreservedStrExpr> for Expr
Source§fn from(value: PreservedStrExpr) -> Expr
fn from(value: PreservedStrExpr) -> Expr
Converts to this type from the input type.
Source§impl FromMeta for PreservedStrExpr
impl FromMeta for PreservedStrExpr
fn from_expr(expr: &Expr) -> Result<PreservedStrExpr, Error>
fn from_nested_meta(item: &NestedMeta) -> Result<Self, Error>
Source§fn from_meta(item: &Meta) -> Result<Self, Error>
fn from_meta(item: &Meta) -> Result<Self, Error>
Create an instance from a
syn::Meta
by dispatching to the format-appropriate
trait function. This generally should not be overridden by implementers. Read moreSource§fn from_none() -> Option<Self>
fn from_none() -> Option<Self>
When a field is omitted from a parent meta-item,
from_none
is used to attempt
recovery before a missing field error is generated. Read moreSource§fn from_word() -> Result<Self, Error>
fn from_word() -> Result<Self, Error>
Create an instance from the presence of the word in the attribute with no
additional options specified.
Source§fn from_list(items: &[NestedMeta]) -> Result<Self, Error>
fn from_list(items: &[NestedMeta]) -> Result<Self, Error>
Create an instance from a list of nested meta items.
Source§fn from_value(value: &Lit) -> Result<Self, Error>
fn from_value(value: &Lit) -> Result<Self, Error>
Create an instance from a literal value of either
foo = "bar"
or foo("bar")
.
This dispatches to the appropriate method based on the type of literal encountered,
and generally should not be overridden by implementers. Read moreSource§fn from_char(value: char) -> Result<Self, Error>
fn from_char(value: char) -> Result<Self, Error>
Create an instance from a char literal in a value position.
Source§impl Hash for PreservedStrExpr
impl Hash for PreservedStrExpr
Source§impl PartialEq for PreservedStrExpr
impl PartialEq for PreservedStrExpr
Source§impl ToTokens for PreservedStrExpr
impl ToTokens for PreservedStrExpr
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
impl Eq for PreservedStrExpr
impl StructuralPartialEq for PreservedStrExpr
Auto Trait Implementations§
impl Freeze for PreservedStrExpr
impl RefUnwindSafe for PreservedStrExpr
impl !Send for PreservedStrExpr
impl !Sync for PreservedStrExpr
impl Unpin for PreservedStrExpr
impl UnwindSafe for PreservedStrExpr
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Spanned for Twhere
T: Spanned + ?Sized,
impl<T> Spanned for Twhere
T: Spanned + ?Sized,
Source§fn span(&self) -> Span
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.