Struct syn::LitStr[][src]

pub struct LitStr { /* fields omitted */ }

A UTF-8 string literal: "foo".

This type is available if Syn is built with the "derive" or "full" feature.

Methods

impl LitStr
[src]

Parse a syntax tree node from the content of this string literal.

All spans in the syntax tree will point to the span of this LitStr.

Example

use proc_macro2::Span;
use syn::{Attribute, Ident, Lit, Meta, MetaNameValue, Path};
use syn::parse::{Error, Result};

// Parses the path from an attribute that looks like:
//
//     #[path = "a::b::c"]
//
// or returns the path `Self` as a default if the attribute is not of
// that form.
fn get_path(attr: &Attribute) -> Result<Path> {
    let default = || Path::from(Ident::new("Self", Span::call_site()));

    let meta = match attr.interpret_meta() {
        Some(meta) => meta,
        None => return Ok(default()),
    };

    if meta.name() != "path" {
        return Ok(default());
    }

    match meta {
        Meta::NameValue(MetaNameValue { lit: Lit::Str(lit_str), .. }) => {
            lit_str.parse()
        }
        _ => {
            let error_span = attr.bracket_token.span;
            let message = "expected #[path = \"...\"]";
            Err(Error::new(error_span, message))
        }
    }
}

Trait Implementations

impl Token for LitStr
[src]

impl Parse for LitStr
[src]

impl ToTokens for LitStr
[src]

Write self to the given TokenStream. Read more

Convert self directly into a TokenStream object. Read more

impl Debug for LitStr
[src]

Formats the value using the given formatter. Read more

impl Clone for LitStr
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl From<LitStr> for Lit
[src]

Performs the conversion.

impl Eq for LitStr
[src]

impl PartialEq for LitStr
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Hash for LitStr
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl !Send for LitStr

impl !Sync for LitStr