syn_utils/
type_ext.rs

1use crate::*;
2
3pub trait TypeExt {
4  fn as_path(&self) -> syn::Result<&Path>;
5  fn as_path_mut(&mut self) -> syn::Result<&mut Path>;
6}
7
8impl TypeExt for Type {
9  fn as_path(&self) -> syn::Result<&Path> {
10    if let Type::Path(path) = self {
11      Ok(&path.path)
12    } else {
13      bail!(self, "Expected a type path");
14    }
15  }
16
17  fn as_path_mut(&mut self) -> syn::Result<&mut Path> {
18    if let Type::Path(path) = self {
19      Ok(&mut path.path)
20    } else {
21      bail!(self, "Expected a type path");
22    }
23  }
24}