1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use syn::{Expr, ExprLit, Lit};

pub(crate) trait RequireStrLit {
    fn require_str_lit(&self) -> syn::Result<String>;
}

impl RequireStrLit for Expr {
    fn require_str_lit(&self) -> syn::Result<String> {
        match self {
            Expr::Lit(ExprLit {
                lit: Lit::Str(str), ..
            }) => Ok(str.value()),
            _ => Err(syn::Error::new_spanned(self, "expected a string literal")),
        }
    }
}