diff --git a/lib/oxrdf/src/parser.rs b/lib/oxrdf/src/parser.rs index f15c0b28..326868f5 100644 --- a/lib/oxrdf/src/parser.rs +++ b/lib/oxrdf/src/parser.rs @@ -28,7 +28,7 @@ impl FromStr for NamedNode { fn from_str(s: &str) -> Result { let (term, left) = read_named_node(s)?; if !left.is_empty() { - return Err(TermParseError::msg( + return Err(Self::Err::msg( "Named node serialization should end with a >", )); } @@ -50,7 +50,7 @@ impl FromStr for BlankNode { fn from_str(s: &str) -> Result { let (term, left) = read_blank_node(s)?; if !left.is_empty() { - return Err(TermParseError::msg( + return Err(Self::Err::msg( "Blank node serialization should not contain whitespaces", )); } @@ -78,7 +78,7 @@ impl FromStr for Literal { fn from_str(s: &str) -> Result { let (term, left) = read_literal(s)?; if !left.is_empty() { - return Err(TermParseError::msg("Invalid literal serialization")); + return Err(Self::Err::msg("Invalid literal serialization")); } Ok(term) } @@ -103,7 +103,7 @@ impl FromStr for Term { fn from_str(s: &str) -> Result { let (term, left) = read_term(s, 0)?; if !left.is_empty() { - return Err(TermParseError::msg("Invalid term serialization")); + return Err(Self::Err::msg("Invalid term serialization")); } Ok(term) } @@ -122,11 +122,11 @@ impl FromStr for Variable { /// ``` fn from_str(s: &str) -> Result { if !s.starts_with('?') && !s.starts_with('$') { - return Err(TermParseError::msg( + return Err(Self::Err::msg( "Variable serialization should start with ? or $", )); } - Self::new(&s[1..]).map_err(|error| TermParseError { + Self::new(&s[1..]).map_err(|error| Self::Err { kind: TermParseErrorKind::Variable { value: s.to_owned(), error, diff --git a/lib/oxrdfio/src/error.rs b/lib/oxrdfio/src/error.rs index 235ba1b7..3b4691f9 100644 --- a/lib/oxrdfio/src/error.rs +++ b/lib/oxrdfio/src/error.rs @@ -42,7 +42,7 @@ impl Error for ParseError { impl From for SyntaxError { #[inline] fn from(error: oxttl::SyntaxError) -> Self { - SyntaxError { + Self { inner: SyntaxErrorKind::Turtle(error), } } @@ -61,7 +61,7 @@ impl From for ParseError { impl From for SyntaxError { #[inline] fn from(error: oxrdfxml::SyntaxError) -> Self { - SyntaxError { + Self { inner: SyntaxErrorKind::RdfXml(error), } } @@ -166,7 +166,7 @@ impl From for io::Error { match error.inner { SyntaxErrorKind::Turtle(error) => error.into(), SyntaxErrorKind::RdfXml(error) => error.into(), - SyntaxErrorKind::Msg { msg } => io::Error::new(io::ErrorKind::InvalidData, msg), + SyntaxErrorKind::Msg { msg } => Self::new(io::ErrorKind::InvalidData, msg), } } } diff --git a/lib/oxrdfxml/src/parser.rs b/lib/oxrdfxml/src/parser.rs index 69f87711..3c6b23ff 100644 --- a/lib/oxrdfxml/src/parser.rs +++ b/lib/oxrdfxml/src/parser.rs @@ -399,23 +399,23 @@ enum RdfXmlState { impl RdfXmlState { fn base_iri(&self) -> Option<&Iri> { match self { - RdfXmlState::Doc { base_iri, .. } - | RdfXmlState::Rdf { base_iri, .. } - | RdfXmlState::NodeElt { base_iri, .. } - | RdfXmlState::PropertyElt { base_iri, .. } - | RdfXmlState::ParseTypeCollectionPropertyElt { base_iri, .. } - | RdfXmlState::ParseTypeLiteralPropertyElt { base_iri, .. } => base_iri.as_ref(), + Self::Doc { base_iri, .. } + | Self::Rdf { base_iri, .. } + | Self::NodeElt { base_iri, .. } + | Self::PropertyElt { base_iri, .. } + | Self::ParseTypeCollectionPropertyElt { base_iri, .. } + | Self::ParseTypeLiteralPropertyElt { base_iri, .. } => base_iri.as_ref(), } } fn language(&self) -> Option<&String> { match self { - RdfXmlState::Doc { .. } => None, - RdfXmlState::Rdf { language, .. } - | RdfXmlState::NodeElt { language, .. } - | RdfXmlState::PropertyElt { language, .. } - | RdfXmlState::ParseTypeCollectionPropertyElt { language, .. } - | RdfXmlState::ParseTypeLiteralPropertyElt { language, .. } => language.as_ref(), + Self::Doc { .. } => None, + Self::Rdf { language, .. } + | Self::NodeElt { language, .. } + | Self::PropertyElt { language, .. } + | Self::ParseTypeCollectionPropertyElt { language, .. } + | Self::ParseTypeLiteralPropertyElt { language, .. } => language.as_ref(), } } } diff --git a/lib/oxsdatatypes/src/date_time.rs b/lib/oxsdatatypes/src/date_time.rs index 575d06f1..d2405692 100644 --- a/lib/oxsdatatypes/src/date_time.rs +++ b/lib/oxsdatatypes/src/date_time.rs @@ -1504,13 +1504,13 @@ impl TryFrom for TimezoneOffset { let result = Self::new( offset_in_minutes .try_into() - .map_err(|_| InvalidTimezoneError { offset_in_minutes })?, + .map_err(|_| Self::Error { offset_in_minutes })?, )?; if DayTimeDuration::from(result) == value { Ok(result) } else { // The value is not an integral number of minutes or overflow problems - Err(InvalidTimezoneError { offset_in_minutes }) + Err(Self::Error { offset_in_minutes }) } } } @@ -1521,7 +1521,7 @@ impl TryFrom for TimezoneOffset { #[inline] fn try_from(value: Duration) -> Result { DayTimeDuration::try_from(value) - .map_err(|_| InvalidTimezoneError { + .map_err(|_| Self::Error { offset_in_minutes: 0, })? .try_into() @@ -2426,7 +2426,7 @@ impl Error for DateTimeOverflowError {} impl From for ParseDateTimeError { fn from(error: DateTimeOverflowError) -> Self { - ParseDateTimeError { + Self { kind: ParseDateTimeErrorKind::Overflow(error), } } diff --git a/lib/oxsdatatypes/src/duration.rs b/lib/oxsdatatypes/src/duration.rs index 8d73cd4a..93dac7d6 100644 --- a/lib/oxsdatatypes/src/duration.rs +++ b/lib/oxsdatatypes/src/duration.rs @@ -187,7 +187,7 @@ impl FromStr for Duration { fn from_str(input: &str) -> Result { let parts = ensure_complete(input, duration_parts)?; if parts.year_month.is_none() && parts.day_time.is_none() { - return Err(ParseDurationError::msg("Empty duration")); + return Err(Self::Err::msg("Empty duration")); } Ok(Self::new( parts.year_month.unwrap_or(0), @@ -409,13 +409,15 @@ impl FromStr for YearMonthDuration { fn from_str(input: &str) -> Result { let parts = ensure_complete(input, duration_parts)?; if parts.day_time.is_some() { - return Err(ParseDurationError::msg( + return Err(Self::Err::msg( "There must not be any day or time component in a yearMonthDuration", )); } - Ok(Self::new(parts.year_month.ok_or( - ParseDurationError::msg("No year and month values found"), - )?)) + Ok(Self::new( + parts + .year_month + .ok_or(Self::Err::msg("No year and month values found"))?, + )) } } @@ -621,7 +623,7 @@ impl TryFrom for StdDuration { .ok_or(DurationOverflowError)? .checked_floor() .ok_or(DurationOverflowError)?; - Ok(StdDuration::new( + Ok(Self::new( secs.as_i128() .try_into() .map_err(|_| DurationOverflowError)?, @@ -639,13 +641,15 @@ impl FromStr for DayTimeDuration { fn from_str(input: &str) -> Result { let parts = ensure_complete(input, duration_parts)?; if parts.year_month.is_some() { - return Err(ParseDurationError::msg( + return Err(Self::Err::msg( "There must not be any year or month component in a dayTimeDuration", )); } - Ok(Self::new(parts.day_time.ok_or(ParseDurationError::msg( - "No day or time values found", - ))?)) + Ok(Self::new( + parts + .day_time + .ok_or(Self::Err::msg("No day or time values found"))?, + )) } } diff --git a/lib/oxttl/src/line_formats.rs b/lib/oxttl/src/line_formats.rs index fc48cd53..e7d39e09 100644 --- a/lib/oxttl/src/line_formats.rs +++ b/lib/oxttl/src/line_formats.rs @@ -274,7 +274,7 @@ impl NQuadsRecognizer { true, Some(b"#"), ), - NQuadsRecognizer { + Self { stack: vec![NQuadsState::ExpectSubject], subjects: Vec::new(), predicates: Vec::new(), diff --git a/lib/oxttl/src/n3.rs b/lib/oxttl/src/n3.rs index 929f5c0f..a1c23f25 100644 --- a/lib/oxttl/src/n3.rs +++ b/lib/oxttl/src/n3.rs @@ -1214,7 +1214,7 @@ impl N3Recognizer { true, Some(b"#"), ), - N3Recognizer { + Self { stack: vec![N3State::N3Doc], terms: Vec::new(), predicates: Vec::new(), diff --git a/lib/oxttl/src/terse.rs b/lib/oxttl/src/terse.rs index bc092c1f..86fad434 100644 --- a/lib/oxttl/src/terse.rs +++ b/lib/oxttl/src/terse.rs @@ -844,7 +844,7 @@ impl TriGRecognizer { true, Some(b"#"), ), - TriGRecognizer { + Self { stack: vec![TriGState::TriGDoc], cur_subject: Vec::new(), cur_predicate: Vec::new(), diff --git a/lib/oxttl/src/toolkit/error.rs b/lib/oxttl/src/toolkit/error.rs index df50b950..e279dab4 100644 --- a/lib/oxttl/src/toolkit/error.rs +++ b/lib/oxttl/src/toolkit/error.rs @@ -72,7 +72,7 @@ impl Error for SyntaxError {} impl From for io::Error { #[inline] fn from(error: SyntaxError) -> Self { - io::Error::new(io::ErrorKind::InvalidData, error) + Self::new(io::ErrorKind::InvalidData, error) } } diff --git a/lib/sparopt/src/algebra.rs b/lib/sparopt/src/algebra.rs index e5cb0952..51ecf6fa 100644 --- a/lib/sparopt/src/algebra.rs +++ b/lib/sparopt/src/algebra.rs @@ -364,25 +364,25 @@ impl Expression { fn returns_boolean(&self) -> bool { match self { - Expression::Or(_) - | Expression::And(_) - | Expression::Equal(_, _) - | Expression::SameTerm(_, _) - | Expression::Greater(_, _) - | Expression::GreaterOrEqual(_, _) - | Expression::Less(_, _) - | Expression::LessOrEqual(_, _) - | Expression::Not(_) - | Expression::Exists(_) - | Expression::Bound(_) - | Expression::FunctionCall( + Self::Or(_) + | Self::And(_) + | Self::Equal(_, _) + | Self::SameTerm(_, _) + | Self::Greater(_, _) + | Self::GreaterOrEqual(_, _) + | Self::Less(_, _) + | Self::LessOrEqual(_, _) + | Self::Not(_) + | Self::Exists(_) + | Self::Bound(_) + | Self::FunctionCall( Function::IsBlank | Function::IsIri | Function::IsLiteral | Function::IsNumeric, _, ) => true, #[cfg(feature = "rdf-star")] - Expression::FunctionCall(Function::IsTriple, _) => true, - Expression::Literal(literal) => literal.datatype() == xsd::BOOLEAN, - Expression::If(_, a, b) => a.returns_boolean() && b.returns_boolean(), + Self::FunctionCall(Function::IsTriple, _) => true, + Self::Literal(literal) => literal.datatype() == xsd::BOOLEAN, + Self::If(_, a, b) => a.returns_boolean() && b.returns_boolean(), _ => false, } } @@ -847,7 +847,7 @@ impl GraphPattern { } } if all.is_empty() { - GraphPattern::empty() + Self::empty() } else { Self::Union { inner: order_vec(all), diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index 785c64cd..25c4b3cf 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -3892,9 +3892,9 @@ impl TupleSelector { fn get_pattern_value(&self, tuple: &EncodedTuple) -> Option { match self { - TupleSelector::Constant(c) => Some(c.clone()), - TupleSelector::Variable(v) => tuple.get(*v).cloned(), - TupleSelector::TriplePattern(triple) => Some( + Self::Constant(c) => Some(c.clone()), + Self::Variable(v) => tuple.get(*v).cloned(), + Self::TriplePattern(triple) => Some( EncodedTriple { subject: triple.subject.get_pattern_value(tuple)?, predicate: triple.predicate.get_pattern_value(tuple)?, diff --git a/lib/src/storage/error.rs b/lib/src/storage/error.rs index 8c874d77..89895349 100644 --- a/lib/src/storage/error.rs +++ b/lib/src/storage/error.rs @@ -179,7 +179,7 @@ impl From for io::Error { LoaderError::Storage(error) => error.into(), LoaderError::Parsing(error) => error.into(), LoaderError::InvalidBaseIri { .. } => { - io::Error::new(io::ErrorKind::InvalidInput, error.to_string()) + Self::new(io::ErrorKind::InvalidInput, error.to_string()) } } } @@ -242,7 +242,7 @@ impl From for io::Error { SerializerError::Storage(error) => error.into(), SerializerError::Io(error) => error, SerializerError::DatasetFormatExpected(_) => { - io::Error::new(io::ErrorKind::InvalidInput, error.to_string()) + Self::new(io::ErrorKind::InvalidInput, error.to_string()) } } } diff --git a/lib/src/storage/small_string.rs b/lib/src/storage/small_string.rs index 70a15676..c2862ff4 100644 --- a/lib/src/storage/small_string.rs +++ b/lib/src/storage/small_string.rs @@ -153,10 +153,10 @@ impl FromStr for SmallString { inner[15] = value .len() .try_into() - .map_err(|_| BadSmallStringError::TooLong(value.len()))?; + .map_err(|_| Self::Err::TooLong(value.len()))?; Ok(Self { inner }) } else { - Err(BadSmallStringError::TooLong(value.len())) + Err(Self::Err::TooLong(value.len())) } } }