tree_magic icon indicating copy to clipboard operation
tree_magic copied to clipboard

nom v4

Open igor-raits opened this issue 6 years ago • 4 comments

It would be very cool if you would update obsolete nom v2 to latest v4. I tried to do that update myself, but it turned out to be not trivial.

Thanks!

igor-raits avatar Apr 28 '19 18:04 igor-raits

diff --git a/Cargo.toml b/Cargo.toml
index f5cc72a..7210b7b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,7 +11,7 @@ license = "MIT"
 
 [dependencies]
 petgraph = "^0.4"
-nom = "^2"
+nom = "^4"
 lazy_static = "^0.2"
 fnv = "^1"
 parking_lot = "^0.4"
diff --git a/src/fdo_magic/mod.rs b/src/fdo_magic/mod.rs
index 3a1bee4..5325a5c 100644
--- a/src/fdo_magic/mod.rs
+++ b/src/fdo_magic/mod.rs
@@ -237,10 +237,10 @@ pub mod ruleset {
        }
     
     pub fn from_u8(b: &[u8]) -> Result<FnvHashMap<MIME, DiGraph<super::MagicRule, u32>>, String> {
-        let tuplevec = from_u8_to_tuple_vec(b).to_result().map_err(|e| e.to_string())?;;
+        let tuplevec = from_u8_to_tuple_vec(b).map_err(|e| e.to_string())?;
         let mut res = FnvHashMap::<MIME, DiGraph<super::MagicRule, u32>>::default();
         
-        for x in tuplevec {
+        for x in tuplevec.1 {
             res.insert(x.0, gen_graph(x.1));
         }
         

This is something I tried, but that broke all tests with:

test from_u8::application_tar ... thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"application/octet-stream"`,
 right: `"application/x-tar"`', tests/from_u8.rs:70:9

It thinks that all files are octet-stream now.

igor-raits avatar Apr 28 '19 18:04 igor-raits

@Geal, would you be able to help me with this, please? :)

igor-raits avatar Apr 28 '19 18:04 igor-raits

I published a (temporary?) stripped-down fork that includes PR #20 (upgrade to nom 5):

https://crates.io/crates/tree_magic_mini

mbrubeck avatar Jun 15 '20 23:06 mbrubeck

tree_magic crate get warning at rustc 1.69.0-nightly (5243ea5c2 2023-02-20)

warning: the following packages contain code that will be rejected by a future version of Rust: nom v3.2.1 note: to see what the problems were, use the option --future-incompat-report

cargo tree -i -p [email protected]
nom v3.2.1
└── tree_magic v0.2.3

pymongo avatar Feb 22 '23 12:02 pymongo