What am I doing wrong here? #rust
@fredvanzwieten Looks fine. Run `cargo build` and it should give you a clear explanation of what it wants. Or if it builds fine, it means you've ran into an edge case where rust-analyzer is mistaken.
@kornel Nope, cargo build complains more or less in the same way:
@fredvanzwieten @kornel did you accidentally shadow the Ok enum somehow? Either via another import or some bad code higher up in the function? If you are able, try sharing more of your code as the problem may be outside what you've shared so far.
@gibwar @kornel YES! you nailed it!! In had this laying around from some try-out before:
use anyhow::Ok;
@fredvanzwieten I don’t know, but you should try #rustlang hashtag as well.

@fredvanzwieten the example shared on the docs at https://docs.rs/jsonwebtoken/7.2.0/jsonwebtoken/fn.encode.html worked for me to where rust-analyzer and cargo build worked for me. Have you tried running `cargo build` by hand to see if there are any additional diagnostics output? I am using the latest version of the crate as I just installed it but maybe a full build will give you a better hint.

#rust #RustLang #jwt

jsonwebtoken::encode - Rust

API documentation for the Rust `encode` fn in crate `jsonwebtoken`.

@fredvanzwieten Get rid of the `: String`.
@nuttycom I tried that. It can't determine the type by itself (which is also weird and might be a clue) #rust #rustlang
@fredvanzwieten @nuttycom What does cargo check say? It seems that the compiler is deducing that the Ok path is never reached (! Is the Never type) which makes me think that your input to encode is invalid and the compiler can determine that statically. Is the key encoded with HS256? The header and key algorithms must match, and Header defaults to HS256.

@fredvanzwieten Hm, so I would try it explicitly ascribing `let token: String = ` ... but *not* ascribing within the match? This is pretty weird though, because the result type of `encode` isn't polymorphic, it really *should* be able to figure this out.

I don't know why it would make a difference, but you could also try explicitly ascribing the type of your claims as `match encode::<MyClaimsType>(...) { ... }` just to give the compiler all the hints it needs?

@fredvanzwieten I believe you may have defined or imported something named `Ok` which shadows the one provided by the std

@lewdum Yes! this was the problem. Thanks!

use anyhow::Ok;

@fredvanzwieten Did you try to replace the `Ok(t)` by `std::result::Ok(t)` to nudge the compiler in the right direction? Looks as if it is mistaken the tuple type for some function.
@fredvanzwieten what's the return type of `encode`?