From b561b48aa34fb0ce8480aa51eed13d1418462f58 Mon Sep 17 00:00:00 2001 From: Smitty Date: Fri, 28 May 2021 13:04:06 -0400 Subject: [PATCH] Do more linting --- src/entity.rs | 28 ++++++++++++++++++++++++++++ src/ids.rs | 3 +++ src/lib.rs | 9 +++++++++ 3 files changed, 40 insertions(+) diff --git a/src/entity.rs b/src/entity.rs index 0da503d..4d08b9c 100755 --- a/src/entity.rs +++ b/src/entity.rs @@ -123,8 +123,11 @@ impl Default for ClaimValueData { /// A statement rank. #[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub enum Rank { + /// The deprecated rank, indicating outdated/wrong info. Deprecated, + /// Normal rank, the default. Normal, + /// Preferred rank, indicates the claim is most recent or accurate. Preferred, } @@ -146,15 +149,19 @@ pub struct ReferenceGroup { pub struct ClaimValue { /// The data of the claim. pub data: ClaimValueData, + /// The rank of this claim. pub rank: Rank, /// The globally unique claim ID. pub id: String, + /// All of the qualifiers for this claim. pub qualifiers: Vec<(Pid, ClaimValueData)>, + /// All of the groups of references for this claim. pub references: Vec, } impl Entity { /// All of the values of "instance of" on the entity. + #[must_use] pub fn instances(&self) -> Vec { let mut instances = Vec::with_capacity(1); for (pid, claim) in &self.claims { @@ -169,6 +176,7 @@ impl Entity { } /// When the entity started existing. + #[must_use] pub fn start_time(&self) -> Option> { for (pid, claim) in &self.claims { if *pid == consts::DATE_OF_BIRTH { @@ -181,6 +189,7 @@ impl Entity { } /// When the entity stopped existing. + #[must_use] pub fn end_time(&self) -> Option> { for (pid, claim) in &self.claims { if *pid == consts::DATE_OF_DEATH { @@ -197,21 +206,37 @@ impl Entity { #[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] pub enum EntityError { + /// A float couldn't be parsed. FloatParse, + /// A string was expected but not found ExpectedString, + /// A valid Qid URI was expected but not found ExpectedQidString, + /// A time string was empty TimeEmpty, + /// An ID was invalid BadId, + /// A date didn't have a year NoDateYear, + /// No date matched the day/month/year NoDateMatched, + /// An ambiguous date was specified DateAmbiguous, + /// The datatype was invalid InvalidDatatype, + /// The datatype was invalid or unknown UnknownDatatype, + /// The time was missing an hour MissingHour, + /// The time was missing an minute MissingMinute, + /// The time was missing an second MissingSecond, + /// The snaktype was invalid InvalidSnaktype, + /// The precision level was invalid InvalidPrecision, + /// No rank was specified NoRank, } @@ -315,6 +340,9 @@ fn parse_wb_time(time: &str) -> Result, En impl ClaimValueData { /// Parses a snak. + /// + /// # Errors + /// If the `snak` does not correspond to a valid snak, then an error will be returned. pub fn parse_snak(mut snak: json::JsonValue) -> Result { let mut datavalue: json::JsonValue = take_prop("datavalue", &mut snak); let datatype: &str = &get_json_string(take_prop("datatype", &mut snak))?; diff --git a/src/ids.rs b/src/ids.rs index 4b4e1b9..afe7d95 100755 --- a/src/ids.rs +++ b/src/ids.rs @@ -98,6 +98,7 @@ impl ToString for Sid { macro_rules! qid_consts ( { $($key:ident => $value:expr),+, } => { $( + #[allow(missing_docs)] pub const $key: Qid = Qid($value); )+ }; @@ -105,6 +106,7 @@ macro_rules! qid_consts ( macro_rules! pid_consts ( { $($key:ident => $value:expr),+, } => { $( + #[allow(missing_docs)] pub const $key: Pid = Pid($value); )+ }; @@ -128,6 +130,7 @@ macro_rules! qid_unit_suffixes { impl Qid { /// If the Qid is a commonly used unit on Wikidata, get it as a unit suffix. + #[must_use] pub fn unit_suffix(self) -> Option<&'static str> { consts::unit_suffix(self) } diff --git a/src/lib.rs b/src/lib.rs index 193ab9e..54c5fa7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,15 @@ //! Rust library for Wikidata. It has some support for Wikibase as well, although the main focus is //! supporting the Wikidata instance. +#![warn(clippy::pedantic)] +#![warn(missing_docs)] +#![allow(clippy::non_ascii_literal)] +#![allow(clippy::wildcard_imports)] +#![allow(clippy::cast_sign_loss)] +#![allow(clippy::cast_possible_truncation)] +#![allow(clippy::similar_names)] +#![allow(clippy::module_name_repetitions)] + pub(crate) mod entity; pub(crate) mod ids; pub(crate) mod text;