begone, proc_macro! removes a bunch of dependencies that came through darling.

This commit is contained in:
Lynne Megido 2021-02-15 00:30:12 +10:00
parent 3963910e1e
commit 3ae4ec53d8
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
3 changed files with 20 additions and 106 deletions

90
Cargo.lock generated
View file

@ -6,15 +6,6 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "async-mutex"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e"
dependencies = [
"event-listener",
]
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.14" version = "0.2.14"
@ -44,32 +35,10 @@ version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e2afe73808fbaac302e39c9754bfc3c4b4d0f99c9c240b9f4e4efc841ad1b74" checksum = "5e2afe73808fbaac302e39c9754bfc3c4b4d0f99c9c240b9f4e4efc841ad1b74"
dependencies = [ dependencies = [
"async-mutex",
"cached_proc_macro",
"cached_proc_macro_types",
"hashbrown", "hashbrown",
"once_cell", "once_cell",
] ]
[[package]]
name = "cached_proc_macro"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf857ae42d910aede5c5186e62684b0d7a597ce2fe3bd14448ab8f7ef439848c"
dependencies = [
"async-mutex",
"cached_proc_macro_types",
"darling",
"quote",
"syn",
]
[[package]]
name = "cached_proc_macro_types"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "0.1.10" version = "0.1.10"
@ -166,41 +135,6 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "darling"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]] [[package]]
name = "dirs-next" name = "dirs-next"
version = "2.0.0" version = "2.0.0"
@ -239,12 +173,6 @@ dependencies = [
"termcolor", "termcolor",
] ]
[[package]]
name = "event-listener"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59"
[[package]] [[package]]
name = "fif" name = "fif"
version = "0.1.0" version = "0.1.0"
@ -261,12 +189,6 @@ dependencies = [
"xdg-mime", "xdg-mime",
] ]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.2" version = "0.2.2"
@ -308,12 +230,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.6.1" version = "1.6.1"
@ -554,12 +470,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strsim"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.60" version = "1.0.60"

View file

@ -34,7 +34,6 @@ features = ["termcolor", "atty"]
[dependencies.cached] [dependencies.cached]
version = "0.23.0" version = "0.23.0"
default-features = false default-features = false
features = ["proc_macro"]
[profile.release] [profile.release]
lto = "thin" lto = "thin"

View file

@ -1,11 +1,13 @@
use xdg_mime::SharedMimeInfo;
use std::path::Path;
use std::io;
use mime_guess::Mime;
use std::fs::File; use std::fs::File;
use std::io;
use std::io::{Read, Seek, SeekFrom}; use std::io::{Read, Seek, SeekFrom};
use std::path::Path;
use cached::cached;
use mime_guess::Mime;
use smartstring::alias::String; use smartstring::alias::String;
use cached::proc_macro::cached; use xdg_mime::SharedMimeInfo;
// use log::{debug, warn}; // use log::{debug, warn};
// from looking at the files in https://github.com/bojand/infer/tree/master/src/matchers, the format with the largest // from looking at the files in https://github.com/bojand/infer/tree/master/src/matchers, the format with the largest
@ -41,17 +43,20 @@ pub fn mime_type(db: &SharedMimeInfo, path: &Path) -> io::Result<Option<Mime>, >
Ok(db.get_mime_type_for_data(&buffer).map(|m| m.0)) Ok(db.get_mime_type_for_data(&buffer).map(|m| m.0))
} }
#[cached]
// TODO: avoid cloning mime if possible, although i don't really see how it would be - maybe instead of passing the mime // TODO: avoid cloning mime if possible, although i don't really see how it would be - maybe instead of passing the mime
// object, pass a hash of it? // object, pass a hash of it?
pub fn mime_extension_lookup(mime: Mime) -> Option<Vec<String>> { cached! {
if mime == mime_guess::mime::IMAGE_JPEG { MIMEXT;
// jpeg files are given the primary extension "jpe", due to the extension list being stored in alphabetical order. fn mime_extension_lookup(mime: Mime) -> Option<Vec<String>> = {
// to handle this particular case, return a custom vector consisting of just "jpg" and "jpeg". if mime == mime_guess::mime::IMAGE_JPEG {
return Some(vec![String::from("jpg"), String::from("jpeg")]); // jpeg files are given the primary extension "jpe", due to the extension list being stored in alphabetical order.
} // to handle this particular case, return a custom vector consisting of just "jpg" and "jpeg".
match mime_guess::get_mime_extensions(&mime) { // get a list of possible extensions for this mime type return Some(vec![String::from("jpg"), String::from("jpeg")]);
Some(exts) => Some(exts.iter().map(|e| String::from(*e)).collect()), }
None => None match mime_guess::get_mime_extensions(&mime) { // get a list of possible extensions for this mime type
Some(exts) => Some(exts.iter().map(|e| String::from(*e)).collect()),
None => None
}
} }
} }