murf-macros 0.2.0

Murf's proc macros
Documentation
use lazy_static::lazy_static;
use quote::ToTokens;
use regex::{Captures, Regex};

pub(crate) trait FormattedString {
    fn to_formatted_string(&self) -> String;
}

impl<X> FormattedString for X
where
    X: ToTokens,
{
    fn to_formatted_string(&self) -> String {
        let code = self.to_token_stream().to_string();
        let code = PATH_FORMAT_1.replace_all(&code, |c: &Captures<'_>| c[1].to_string());
        let code = PATH_FORMAT_2.replace_all(&code, "&");

        code.into_owned()
    }
}

lazy_static! {
    static ref PATH_FORMAT_1: Regex = Regex::new(r"\s*(<|>)\s*").unwrap();
    static ref PATH_FORMAT_2: Regex = Regex::new(r"&\s*").unwrap();
}