Move icon helper.
This commit is contained in:
@@ -9,15 +9,11 @@ use syn::{ItemStruct, parse_macro_input};
|
|||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn log_id(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn log_id(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let input = parse_macro_input!(item as ItemStruct);
|
let input = parse_macro_input!(item as ItemStruct);
|
||||||
|
|
||||||
let struct_name = &input.ident;
|
let struct_name = &input.ident;
|
||||||
let generics = &input.generics;
|
let generics = &input.generics;
|
||||||
|
|
||||||
// This is the important part
|
|
||||||
let (impl_generics, type_generics, where_clause) = generics.split_for_impl();
|
let (impl_generics, type_generics, where_clause) = generics.split_for_impl();
|
||||||
|
|
||||||
let struct_name_str = struct_name.to_string();
|
let struct_name_str = struct_name.to_string();
|
||||||
|
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
#input
|
#input
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,4 @@
|
|||||||
|
|
||||||
pub mod entry_meta;
|
pub mod entry_meta;
|
||||||
|
|
||||||
use devicons::FileIcon;
|
pub use entry_meta::icon;
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
pub fn icon<P: AsRef<str>>(p: P) -> FileIcon {
|
|
||||||
let path = p.as_ref();
|
|
||||||
if Path::new(&path).is_dir() {
|
|
||||||
// Ensures directories are given a folder icon and not mistakenly resolved to a language.
|
|
||||||
// For example, a directory named `cpp` would otherwise return a C++ icon.
|
|
||||||
return FileIcon::from("dir/");
|
|
||||||
}
|
|
||||||
FileIcon::from(path)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -52,3 +52,13 @@ impl EntryMeta {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn icon<P: AsRef<str>>(p: P) -> FileIcon {
|
||||||
|
let path = p.as_ref();
|
||||||
|
if Path::new(&path).is_dir() {
|
||||||
|
// Ensures directories are given a folder icon and not mistakenly resolved to a language.
|
||||||
|
// For example, a directory named `cpp` would otherwise return a C++ icon.
|
||||||
|
return FileIcon::from("dir/");
|
||||||
|
}
|
||||||
|
FileIcon::from(path)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user