diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-09-28 09:59:15 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@sequoia-pgp.org> | 2021-09-30 08:31:13 +0300 |
commit | 18ab269a0e6967d78df8527679f2479c39650250 (patch) | |
tree | 300c052956f3d14422765e0b0c2ddc1e6a13dc8e | |
parent | 93bf23b79a6ae7bf1a81964a338754d0c16d2ca0 (diff) |
Add an is_empty method when len is there
It is customary for Rust data container structures to have both
is_empty and len, methods, because is_empty can both more to the point
and also faster to implement.
Sometimes is_empty makes no sense, as it doesn't for
openpgp::types::Curve, which isn't a container structure. Arguably it
would be better to rename Curve::len to something like Curve::bits,
but as that would change the API, I've opted to tell clippy that not
having is_empty in this case is OK.
Found by clippy lint len_without_is_empty:
https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
-rw-r--r-- | net/src/updates.rs | 5 | ||||
-rw-r--r-- | openpgp/src/types/mod.rs | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/net/src/updates.rs b/net/src/updates.rs index 8313cd62..32b35206 100644 --- a/net/src/updates.rs +++ b/net/src/updates.rs @@ -92,6 +92,11 @@ impl Manifest { self.end } + /// Is the Manifest empty? + pub fn is_empty(&self) -> bool { + self.prefixes.is_empty() + } + /// Returns the number of fingerprint prefixes in this Update /// Manifest. pub fn len(&self) -> usize { diff --git a/openpgp/src/types/mod.rs b/openpgp/src/types/mod.rs index cdad569f..833ca480 100644 --- a/openpgp/src/types/mod.rs +++ b/openpgp/src/types/mod.rs @@ -387,6 +387,7 @@ const ED25519_OID: &[u8] = const CV25519_OID: &[u8] = &[0x2B, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01]; +#[allow(clippy::len_without_is_empty)] impl Curve { /// Parses the given OID. /// |