libp2p_swarm_derive/
syn_ext.rs

1use syn::{Expr, ExprLit, Lit};
2
3pub(crate) trait RequireStrLit {
4    fn require_str_lit(&self) -> syn::Result<String>;
5}
6
7impl RequireStrLit for Expr {
8    fn require_str_lit(&self) -> syn::Result<String> {
9        match self {
10            Expr::Lit(ExprLit {
11                lit: Lit::Str(str), ..
12            }) => Ok(str.value()),
13            _ => Err(syn::Error::new_spanned(self, "expected a string literal")),
14        }
15    }
16}