Keats / jsonwebtoken

JWT lib in rust
MIT License
1.64k stars 260 forks source link

style: use non-reference patterns instead of explicit ref in patterns #283

Closed samueltardieu closed 1 year ago

samueltardieu commented 1 year ago

By using non-reference patterns to match references, the ref keyword becomes unnecessary as it is added by the desugaring.

Keats commented 1 year ago

I'm still on the fence about this elision on whether it's good or not

samueltardieu commented 1 year ago

I've pushed a reformatted version so that cargo format doesn't complain.

I'm still on the fence about this elision on whether it's good or not

Non-reference patterns have been introduced in Rust 1.26 in an effort to make Rust match more ergonomic and avoid the explicit use of ref.

samueltardieu commented 1 year ago

Also note that non-reference patterns are already used in the code, for example at src/decoding.rs:180 (to make b a &[u8]):

    pub(crate) fn as_bytes(&self) -> &[u8] {
        match &self.kind {
            DecodingKeyKind::SecretOrDer(b) => b,
            DecodingKeyKind::RsaModulusExponent { .. } => unreachable!(),
        }
    }

or in src/crypto/mod.rs:99 (to make bytes a &[u8], and n and e are also auto-references there):

            match &key.kind {
                DecodingKeyKind::SecretOrDer(bytes) => verify_ring(alg, signature, message, bytes),
                DecodingKeyKind::RsaModulusExponent { n, e } => {
                    rsa::verify_from_components(alg, signature, message, (n, e))
                }
            }