Do more linting
This commit is contained in:
parent
588a5777db
commit
b561b48aa3
3 changed files with 40 additions and 0 deletions
|
@ -123,8 +123,11 @@ impl Default for ClaimValueData {
|
||||||
/// A statement rank.
|
/// A statement rank.
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||||
pub enum Rank {
|
pub enum Rank {
|
||||||
|
/// The deprecated rank, indicating outdated/wrong info.
|
||||||
Deprecated,
|
Deprecated,
|
||||||
|
/// Normal rank, the default.
|
||||||
Normal,
|
Normal,
|
||||||
|
/// Preferred rank, indicates the claim is most recent or accurate.
|
||||||
Preferred,
|
Preferred,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,15 +149,19 @@ pub struct ReferenceGroup {
|
||||||
pub struct ClaimValue {
|
pub struct ClaimValue {
|
||||||
/// The data of the claim.
|
/// The data of the claim.
|
||||||
pub data: ClaimValueData,
|
pub data: ClaimValueData,
|
||||||
|
/// The rank of this claim.
|
||||||
pub rank: Rank,
|
pub rank: Rank,
|
||||||
/// The globally unique claim ID.
|
/// The globally unique claim ID.
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
/// All of the qualifiers for this claim.
|
||||||
pub qualifiers: Vec<(Pid, ClaimValueData)>,
|
pub qualifiers: Vec<(Pid, ClaimValueData)>,
|
||||||
|
/// All of the groups of references for this claim.
|
||||||
pub references: Vec<ReferenceGroup>,
|
pub references: Vec<ReferenceGroup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity {
|
impl Entity {
|
||||||
/// All of the values of "instance of" on the entity.
|
/// All of the values of "instance of" on the entity.
|
||||||
|
#[must_use]
|
||||||
pub fn instances(&self) -> Vec<Qid> {
|
pub fn instances(&self) -> Vec<Qid> {
|
||||||
let mut instances = Vec::with_capacity(1);
|
let mut instances = Vec::with_capacity(1);
|
||||||
for (pid, claim) in &self.claims {
|
for (pid, claim) in &self.claims {
|
||||||
|
@ -169,6 +176,7 @@ impl Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When the entity started existing.
|
/// When the entity started existing.
|
||||||
|
#[must_use]
|
||||||
pub fn start_time(&self) -> Option<DateTime<chrono::offset::Utc>> {
|
pub fn start_time(&self) -> Option<DateTime<chrono::offset::Utc>> {
|
||||||
for (pid, claim) in &self.claims {
|
for (pid, claim) in &self.claims {
|
||||||
if *pid == consts::DATE_OF_BIRTH {
|
if *pid == consts::DATE_OF_BIRTH {
|
||||||
|
@ -181,6 +189,7 @@ impl Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When the entity stopped existing.
|
/// When the entity stopped existing.
|
||||||
|
#[must_use]
|
||||||
pub fn end_time(&self) -> Option<DateTime<chrono::offset::Utc>> {
|
pub fn end_time(&self) -> Option<DateTime<chrono::offset::Utc>> {
|
||||||
for (pid, claim) in &self.claims {
|
for (pid, claim) in &self.claims {
|
||||||
if *pid == consts::DATE_OF_DEATH {
|
if *pid == consts::DATE_OF_DEATH {
|
||||||
|
@ -197,21 +206,37 @@ impl Entity {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum EntityError {
|
pub enum EntityError {
|
||||||
|
/// A float couldn't be parsed.
|
||||||
FloatParse,
|
FloatParse,
|
||||||
|
/// A string was expected but not found
|
||||||
ExpectedString,
|
ExpectedString,
|
||||||
|
/// A valid Qid URI was expected but not found
|
||||||
ExpectedQidString,
|
ExpectedQidString,
|
||||||
|
/// A time string was empty
|
||||||
TimeEmpty,
|
TimeEmpty,
|
||||||
|
/// An ID was invalid
|
||||||
BadId,
|
BadId,
|
||||||
|
/// A date didn't have a year
|
||||||
NoDateYear,
|
NoDateYear,
|
||||||
|
/// No date matched the day/month/year
|
||||||
NoDateMatched,
|
NoDateMatched,
|
||||||
|
/// An ambiguous date was specified
|
||||||
DateAmbiguous,
|
DateAmbiguous,
|
||||||
|
/// The datatype was invalid
|
||||||
InvalidDatatype,
|
InvalidDatatype,
|
||||||
|
/// The datatype was invalid or unknown
|
||||||
UnknownDatatype,
|
UnknownDatatype,
|
||||||
|
/// The time was missing an hour
|
||||||
MissingHour,
|
MissingHour,
|
||||||
|
/// The time was missing an minute
|
||||||
MissingMinute,
|
MissingMinute,
|
||||||
|
/// The time was missing an second
|
||||||
MissingSecond,
|
MissingSecond,
|
||||||
|
/// The snaktype was invalid
|
||||||
InvalidSnaktype,
|
InvalidSnaktype,
|
||||||
|
/// The precision level was invalid
|
||||||
InvalidPrecision,
|
InvalidPrecision,
|
||||||
|
/// No rank was specified
|
||||||
NoRank,
|
NoRank,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,6 +340,9 @@ fn parse_wb_time(time: &str) -> Result<chrono::DateTime<chrono::offset::Utc>, En
|
||||||
|
|
||||||
impl ClaimValueData {
|
impl ClaimValueData {
|
||||||
/// Parses a snak.
|
/// 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<Self, EntityError> {
|
pub fn parse_snak(mut snak: json::JsonValue) -> Result<Self, EntityError> {
|
||||||
let mut datavalue: json::JsonValue = take_prop("datavalue", &mut snak);
|
let mut datavalue: json::JsonValue = take_prop("datavalue", &mut snak);
|
||||||
let datatype: &str = &get_json_string(take_prop("datatype", &mut snak))?;
|
let datatype: &str = &get_json_string(take_prop("datatype", &mut snak))?;
|
||||||
|
|
|
@ -98,6 +98,7 @@ impl ToString for Sid {
|
||||||
macro_rules! qid_consts (
|
macro_rules! qid_consts (
|
||||||
{ $($key:ident => $value:expr),+, } => {
|
{ $($key:ident => $value:expr),+, } => {
|
||||||
$(
|
$(
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub const $key: Qid = Qid($value);
|
pub const $key: Qid = Qid($value);
|
||||||
)+
|
)+
|
||||||
};
|
};
|
||||||
|
@ -105,6 +106,7 @@ macro_rules! qid_consts (
|
||||||
macro_rules! pid_consts (
|
macro_rules! pid_consts (
|
||||||
{ $($key:ident => $value:expr),+, } => {
|
{ $($key:ident => $value:expr),+, } => {
|
||||||
$(
|
$(
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub const $key: Pid = Pid($value);
|
pub const $key: Pid = Pid($value);
|
||||||
)+
|
)+
|
||||||
};
|
};
|
||||||
|
@ -128,6 +130,7 @@ macro_rules! qid_unit_suffixes {
|
||||||
|
|
||||||
impl Qid {
|
impl Qid {
|
||||||
/// If the Qid is a commonly used unit on Wikidata, get it as a unit suffix.
|
/// 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> {
|
pub fn unit_suffix(self) -> Option<&'static str> {
|
||||||
consts::unit_suffix(self)
|
consts::unit_suffix(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
//! Rust library for Wikidata. It has some support for Wikibase as well, although the main focus is
|
//! Rust library for Wikidata. It has some support for Wikibase as well, although the main focus is
|
||||||
//! supporting the Wikidata instance.
|
//! 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 entity;
|
||||||
pub(crate) mod ids;
|
pub(crate) mod ids;
|
||||||
pub(crate) mod text;
|
pub(crate) mod text;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue