Closed coalooball closed 10 months ago
Hello @coalooball! Thanks for submitting an issue!
That's what happens when code is not automatically checked... :-) The examples are outdated and need to be fixed.
In the meantime: Could you try the examples from https://docs.rs/imap-codec/latest/imap_codec/ and see if they work for you?
Alternatively, you might find these examples (https://github.com/duesee/imap-codec/tree/main/imap-codec/examples) helpful, too.
We could use https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html#include-items-only-when-collecting-doctests (see how to include README) to test the example in the README.
Hello @duesee! Thanks for your prompt response.
I tried the examples from the two links you provided. I was able to run all the examples in this link (https://github.com/duesee/imap-codec/tree/main/imap-codec/examples). However, I encountered compilation errors when trying the examples from this link (https://docs.rs/imap-codec/latest/imap_codec/).
I need to execute the cargo add imap-types
command in the project's root directory, and I also need to modify the code of this example like this:
use imap_codec::{decode::Decoder, GreetingCodec};
use imap_types::response::{Code, Greeting, GreetingKind};
use imap_types::core::Text;
fn main() {
let (remaining, greeting) = GreetingCodec::default()
.decode(b"* OK [ALERT] Hello, World!\r\n<remaining>")
.unwrap();
assert_eq!(
greeting,
Greeting {
kind: GreetingKind::Ok,
code: Some(Code::Alert),
text: Text::try_from("Hello, World!").unwrap(),
}
);
assert_eq!(remaining, &b"<remaining>"[..])
}
I think it's worth reminding everyone to use use imap_types::response::{Code, Greeting, GreetingKind};
cause I tend to instinctively use use imap_codec::response::{Code, Greeting, GreetingKind};
.
By the way, my Cargo version is as follows:
cargo --version
cargo 1.75.0-nightly (6fa6fdc76 2023-10-10)
Thanks for your valuable input! I agree.
Currently, imap-codec
re-exports imap-types
and you could use imap_codec::imap_type::"
. BUT: I think this is confusing, and like to remove the re-export at some point.
Thus, I completely agree that the examples should mention to cargo add imap-types
, too, and tell what to use
.
As you already fixed it... are you in a position to make a PR? :-) I can do it, too, but as you already figured this all out, you should take the credit!
We could make two PRs: One fixing the outdated README (and making it so that it is automatically checked) -- I can do this PR quickly -- and one improving the examples -- possibly you? :-)
I made a PR :-) This commit https://github.com/duesee/imap-codec/pull/395/commits/953ce6b7c6051bc76f6d14acf49831ec7c4d4d7d will ensure that all examples in the READMEs are tested. So, hopefully, nothing can get out-of-sync anymore!
Reopened: Missed one README :P
Thank you very much for the CREDIT :) I have already submitted the PR for #394.
In addition, I think re-exports
is a good idea as well. To avoid duplication, I suggest that use imap_codec::imap_types::*
could be changed to use imap_codec::types::*
. Of course, it can also be use imap_types::*
, depending on your preference.
I think at some point we re-exported imap-types
as types
. But I felt it blurred that the whole imap-types
crate is just re-exported. The duplication is still unfortunate, though.
Hello! I just downloaded imap-codec using
cargo add imap-codec
, and I want to run the examples from https://crates.io/crates/imap-codec, but I'm getting a bunch of errors.Here are the error messages:
Here is my source code(from https://crates.io/crates/imap-codec) and Cargo.toml(generated by
cargo add imap-codec
) file: