use quote::ToTokens; use core_extensions::prelude::*; use std::fmt::{self,Write}; #[allow(dead_code)] pub(crate) fn display_totokens_list(val:I,separator:&str)->AlwaysDisplay where I:IntoIterator, I::Item:ToTokens, { let mut buffer=String::new(); for elem in val{ write_tokens(elem,&mut buffer); buffer.push_str(separator); } AlwaysDisplay( buffer ) } #[allow(dead_code)] pub(crate) fn display_totokens(val:&T)->AlwaysDisplay where T:ToTokens { AlwaysDisplay( tokens_to_string(val) ) } pub(crate) fn tokens_to_string(val:T)->String where T:ToTokens { String::new().mutated(|buff| write_tokens(val,buff) ) } pub(crate) fn totoken_iter_to_string(i:I)->String where I:IntoIterator, I::Item:ToTokens, { let mut buffer="\n".to_string(); for elem in i { write_tokens(elem,&mut buffer); buffer.push_str("\n"); } buffer } pub(crate) fn write_tokens(val:T,buffer:&mut String) where T:ToTokens { write!(buffer,"{}",val.into_token_stream()).drop_() } #[allow(dead_code)] pub(crate) struct AlwaysDisplay(pub T); impl fmt::Debug for AlwaysDisplay where T:fmt::Display { fn fmt(&self,f:&mut fmt::Formatter)->fmt::Result{ fmt::Display::fmt(&self.0,f) } }