use crate::syn_helpers;
use crate::{TracersError, TracersResult};
use proc_macro2::TokenStream;
use std::fmt;
#[derive(PartialEq)]
pub struct ProviderInitSpecification {
pub provider: syn::Path,
}
impl fmt::Debug for ProviderInitSpecification {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ProviderInitSpecification(")?;
write!(
f,
"provider={}",
syn_helpers::convert_to_string(&self.provider)
)?;
write!(f, ")")
}
}
impl ProviderInitSpecification {
pub fn from_token_stream(tokens: TokenStream) -> TracersResult<ProviderInitSpecification> {
match syn::parse2::<syn::Path>(tokens) {
Ok(path) => Self::from_path(path),
Err(e) => Err(TracersError::syn_error("Expected a type path", e)),
}
}
pub fn from_path(path: syn::Path) -> TracersResult<ProviderInitSpecification> {
Ok(ProviderInitSpecification { provider: path })
}
}