From 10c5968676838ee61c5f22e47e271781b0b8b181 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 8 Jun 2023 21:55:07 +0200 Subject: [PATCH] convert to library --- Cargo.toml | 9 +++++++++ src/headers.rs | 2 +- src/lib.rs | 3 +++ src/{main.rs => parse.rs} | 4 +--- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/lib.rs rename src/{main.rs => parse.rs} (82%) diff --git a/Cargo.toml b/Cargo.toml index 0cc91b6..c43aa3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,5 +5,14 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +name = "imf_codec" +path = "src/lib.rs" + + +[[bin]] +name = "imf_parse" +path = "src/parse.rs" + [dependencies] nom = "7" diff --git a/src/headers.rs b/src/headers.rs index 41ce921..7c49060 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -124,7 +124,7 @@ fn unstructured(input: &str) -> IResult<&str, String> { let body = match r.as_slice() { [(None, content)] => content.to_string(), [(Some(ws), content)] => ws.to_string() + content, - lines => lines.iter().fold(String::with_capacity(255), |mut acc, item| { + lines => lines.iter().fold(String::with_capacity(255), |acc, item| { let (may_ws, content) = item; match may_ws { Some(ws) => acc + ws + content, diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..023e824 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +pub mod headers; +pub mod model; +mod abnf; diff --git a/src/main.rs b/src/parse.rs similarity index 82% rename from src/main.rs rename to src/parse.rs index e054ba5..bd548c7 100644 --- a/src/main.rs +++ b/src/parse.rs @@ -1,6 +1,4 @@ -mod headers; -mod model; -mod abnf; +use imf_codec::headers; fn main() { let header = "Subject: Hello\r\n World\r\nFrom: \r\n\r\n";