A few more self-fixes

These are a bit more questionable but still keep things cleaner a bit, at least in some cases?

Most of these were the result of `cargo clippy --fix -- -W clippy::use_self`
pull/739/head
Yuri Astrakhan 8 months ago committed by Thomas Tanon
parent 405b95b4bd
commit 5be6f55155
  1. 12
      lib/oxrdf/src/parser.rs
  2. 6
      lib/oxrdfio/src/error.rs
  3. 24
      lib/oxrdfxml/src/parser.rs
  4. 8
      lib/oxsdatatypes/src/date_time.rs
  5. 24
      lib/oxsdatatypes/src/duration.rs
  6. 2
      lib/oxttl/src/line_formats.rs
  7. 2
      lib/oxttl/src/n3.rs
  8. 2
      lib/oxttl/src/terse.rs
  9. 2
      lib/oxttl/src/toolkit/error.rs
  10. 32
      lib/sparopt/src/algebra.rs
  11. 6
      lib/src/sparql/eval.rs
  12. 4
      lib/src/storage/error.rs
  13. 4
      lib/src/storage/small_string.rs

@ -28,7 +28,7 @@ impl FromStr for NamedNode {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let (term, left) = read_named_node(s)?; let (term, left) = read_named_node(s)?;
if !left.is_empty() { if !left.is_empty() {
return Err(TermParseError::msg( return Err(Self::Err::msg(
"Named node serialization should end with a >", "Named node serialization should end with a >",
)); ));
} }
@ -50,7 +50,7 @@ impl FromStr for BlankNode {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let (term, left) = read_blank_node(s)?; let (term, left) = read_blank_node(s)?;
if !left.is_empty() { if !left.is_empty() {
return Err(TermParseError::msg( return Err(Self::Err::msg(
"Blank node serialization should not contain whitespaces", "Blank node serialization should not contain whitespaces",
)); ));
} }
@ -78,7 +78,7 @@ impl FromStr for Literal {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let (term, left) = read_literal(s)?; let (term, left) = read_literal(s)?;
if !left.is_empty() { if !left.is_empty() {
return Err(TermParseError::msg("Invalid literal serialization")); return Err(Self::Err::msg("Invalid literal serialization"));
} }
Ok(term) Ok(term)
} }
@ -103,7 +103,7 @@ impl FromStr for Term {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let (term, left) = read_term(s, 0)?; let (term, left) = read_term(s, 0)?;
if !left.is_empty() { if !left.is_empty() {
return Err(TermParseError::msg("Invalid term serialization")); return Err(Self::Err::msg("Invalid term serialization"));
} }
Ok(term) Ok(term)
} }
@ -122,11 +122,11 @@ impl FromStr for Variable {
/// ``` /// ```
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
if !s.starts_with('?') && !s.starts_with('$') { if !s.starts_with('?') && !s.starts_with('$') {
return Err(TermParseError::msg( return Err(Self::Err::msg(
"Variable serialization should start with ? or $", "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 { kind: TermParseErrorKind::Variable {
value: s.to_owned(), value: s.to_owned(),
error, error,

@ -42,7 +42,7 @@ impl Error for ParseError {
impl From<oxttl::SyntaxError> for SyntaxError { impl From<oxttl::SyntaxError> for SyntaxError {
#[inline] #[inline]
fn from(error: oxttl::SyntaxError) -> Self { fn from(error: oxttl::SyntaxError) -> Self {
SyntaxError { Self {
inner: SyntaxErrorKind::Turtle(error), inner: SyntaxErrorKind::Turtle(error),
} }
} }
@ -61,7 +61,7 @@ impl From<oxttl::ParseError> for ParseError {
impl From<oxrdfxml::SyntaxError> for SyntaxError { impl From<oxrdfxml::SyntaxError> for SyntaxError {
#[inline] #[inline]
fn from(error: oxrdfxml::SyntaxError) -> Self { fn from(error: oxrdfxml::SyntaxError) -> Self {
SyntaxError { Self {
inner: SyntaxErrorKind::RdfXml(error), inner: SyntaxErrorKind::RdfXml(error),
} }
} }
@ -166,7 +166,7 @@ impl From<SyntaxError> for io::Error {
match error.inner { match error.inner {
SyntaxErrorKind::Turtle(error) => error.into(), SyntaxErrorKind::Turtle(error) => error.into(),
SyntaxErrorKind::RdfXml(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),
} }
} }
} }

@ -399,23 +399,23 @@ enum RdfXmlState {
impl RdfXmlState { impl RdfXmlState {
fn base_iri(&self) -> Option<&Iri<String>> { fn base_iri(&self) -> Option<&Iri<String>> {
match self { match self {
RdfXmlState::Doc { base_iri, .. } Self::Doc { base_iri, .. }
| RdfXmlState::Rdf { base_iri, .. } | Self::Rdf { base_iri, .. }
| RdfXmlState::NodeElt { base_iri, .. } | Self::NodeElt { base_iri, .. }
| RdfXmlState::PropertyElt { base_iri, .. } | Self::PropertyElt { base_iri, .. }
| RdfXmlState::ParseTypeCollectionPropertyElt { base_iri, .. } | Self::ParseTypeCollectionPropertyElt { base_iri, .. }
| RdfXmlState::ParseTypeLiteralPropertyElt { base_iri, .. } => base_iri.as_ref(), | Self::ParseTypeLiteralPropertyElt { base_iri, .. } => base_iri.as_ref(),
} }
} }
fn language(&self) -> Option<&String> { fn language(&self) -> Option<&String> {
match self { match self {
RdfXmlState::Doc { .. } => None, Self::Doc { .. } => None,
RdfXmlState::Rdf { language, .. } Self::Rdf { language, .. }
| RdfXmlState::NodeElt { language, .. } | Self::NodeElt { language, .. }
| RdfXmlState::PropertyElt { language, .. } | Self::PropertyElt { language, .. }
| RdfXmlState::ParseTypeCollectionPropertyElt { language, .. } | Self::ParseTypeCollectionPropertyElt { language, .. }
| RdfXmlState::ParseTypeLiteralPropertyElt { language, .. } => language.as_ref(), | Self::ParseTypeLiteralPropertyElt { language, .. } => language.as_ref(),
} }
} }
} }

@ -1504,13 +1504,13 @@ impl TryFrom<DayTimeDuration> for TimezoneOffset {
let result = Self::new( let result = Self::new(
offset_in_minutes offset_in_minutes
.try_into() .try_into()
.map_err(|_| InvalidTimezoneError { offset_in_minutes })?, .map_err(|_| Self::Error { offset_in_minutes })?,
)?; )?;
if DayTimeDuration::from(result) == value { if DayTimeDuration::from(result) == value {
Ok(result) Ok(result)
} else { } else {
// The value is not an integral number of minutes or overflow problems // 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<Duration> for TimezoneOffset {
#[inline] #[inline]
fn try_from(value: Duration) -> Result<Self, Self::Error> { fn try_from(value: Duration) -> Result<Self, Self::Error> {
DayTimeDuration::try_from(value) DayTimeDuration::try_from(value)
.map_err(|_| InvalidTimezoneError { .map_err(|_| Self::Error {
offset_in_minutes: 0, offset_in_minutes: 0,
})? })?
.try_into() .try_into()
@ -2426,7 +2426,7 @@ impl Error for DateTimeOverflowError {}
impl From<DateTimeOverflowError> for ParseDateTimeError { impl From<DateTimeOverflowError> for ParseDateTimeError {
fn from(error: DateTimeOverflowError) -> Self { fn from(error: DateTimeOverflowError) -> Self {
ParseDateTimeError { Self {
kind: ParseDateTimeErrorKind::Overflow(error), kind: ParseDateTimeErrorKind::Overflow(error),
} }
} }

@ -187,7 +187,7 @@ impl FromStr for Duration {
fn from_str(input: &str) -> Result<Self, Self::Err> { fn from_str(input: &str) -> Result<Self, Self::Err> {
let parts = ensure_complete(input, duration_parts)?; let parts = ensure_complete(input, duration_parts)?;
if parts.year_month.is_none() && parts.day_time.is_none() { 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( Ok(Self::new(
parts.year_month.unwrap_or(0), parts.year_month.unwrap_or(0),
@ -409,13 +409,15 @@ impl FromStr for YearMonthDuration {
fn from_str(input: &str) -> Result<Self, Self::Err> { fn from_str(input: &str) -> Result<Self, Self::Err> {
let parts = ensure_complete(input, duration_parts)?; let parts = ensure_complete(input, duration_parts)?;
if parts.day_time.is_some() { 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", "There must not be any day or time component in a yearMonthDuration",
)); ));
} }
Ok(Self::new(parts.year_month.ok_or( Ok(Self::new(
ParseDurationError::msg("No year and month values found"), parts
)?)) .year_month
.ok_or(Self::Err::msg("No year and month values found"))?,
))
} }
} }
@ -621,7 +623,7 @@ impl TryFrom<DayTimeDuration> for StdDuration {
.ok_or(DurationOverflowError)? .ok_or(DurationOverflowError)?
.checked_floor() .checked_floor()
.ok_or(DurationOverflowError)?; .ok_or(DurationOverflowError)?;
Ok(StdDuration::new( Ok(Self::new(
secs.as_i128() secs.as_i128()
.try_into() .try_into()
.map_err(|_| DurationOverflowError)?, .map_err(|_| DurationOverflowError)?,
@ -639,13 +641,15 @@ impl FromStr for DayTimeDuration {
fn from_str(input: &str) -> Result<Self, Self::Err> { fn from_str(input: &str) -> Result<Self, Self::Err> {
let parts = ensure_complete(input, duration_parts)?; let parts = ensure_complete(input, duration_parts)?;
if parts.year_month.is_some() { 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", "There must not be any year or month component in a dayTimeDuration",
)); ));
} }
Ok(Self::new(parts.day_time.ok_or(ParseDurationError::msg( Ok(Self::new(
"No day or time values found", parts
))?)) .day_time
.ok_or(Self::Err::msg("No day or time values found"))?,
))
} }
} }

@ -274,7 +274,7 @@ impl NQuadsRecognizer {
true, true,
Some(b"#"), Some(b"#"),
), ),
NQuadsRecognizer { Self {
stack: vec![NQuadsState::ExpectSubject], stack: vec![NQuadsState::ExpectSubject],
subjects: Vec::new(), subjects: Vec::new(),
predicates: Vec::new(), predicates: Vec::new(),

@ -1214,7 +1214,7 @@ impl N3Recognizer {
true, true,
Some(b"#"), Some(b"#"),
), ),
N3Recognizer { Self {
stack: vec![N3State::N3Doc], stack: vec![N3State::N3Doc],
terms: Vec::new(), terms: Vec::new(),
predicates: Vec::new(), predicates: Vec::new(),

@ -844,7 +844,7 @@ impl TriGRecognizer {
true, true,
Some(b"#"), Some(b"#"),
), ),
TriGRecognizer { Self {
stack: vec![TriGState::TriGDoc], stack: vec![TriGState::TriGDoc],
cur_subject: Vec::new(), cur_subject: Vec::new(),
cur_predicate: Vec::new(), cur_predicate: Vec::new(),

@ -72,7 +72,7 @@ impl Error for SyntaxError {}
impl From<SyntaxError> for io::Error { impl From<SyntaxError> for io::Error {
#[inline] #[inline]
fn from(error: SyntaxError) -> Self { fn from(error: SyntaxError) -> Self {
io::Error::new(io::ErrorKind::InvalidData, error) Self::new(io::ErrorKind::InvalidData, error)
} }
} }

@ -364,25 +364,25 @@ impl Expression {
fn returns_boolean(&self) -> bool { fn returns_boolean(&self) -> bool {
match self { match self {
Expression::Or(_) Self::Or(_)
| Expression::And(_) | Self::And(_)
| Expression::Equal(_, _) | Self::Equal(_, _)
| Expression::SameTerm(_, _) | Self::SameTerm(_, _)
| Expression::Greater(_, _) | Self::Greater(_, _)
| Expression::GreaterOrEqual(_, _) | Self::GreaterOrEqual(_, _)
| Expression::Less(_, _) | Self::Less(_, _)
| Expression::LessOrEqual(_, _) | Self::LessOrEqual(_, _)
| Expression::Not(_) | Self::Not(_)
| Expression::Exists(_) | Self::Exists(_)
| Expression::Bound(_) | Self::Bound(_)
| Expression::FunctionCall( | Self::FunctionCall(
Function::IsBlank | Function::IsIri | Function::IsLiteral | Function::IsNumeric, Function::IsBlank | Function::IsIri | Function::IsLiteral | Function::IsNumeric,
_, _,
) => true, ) => true,
#[cfg(feature = "rdf-star")] #[cfg(feature = "rdf-star")]
Expression::FunctionCall(Function::IsTriple, _) => true, Self::FunctionCall(Function::IsTriple, _) => true,
Expression::Literal(literal) => literal.datatype() == xsd::BOOLEAN, Self::Literal(literal) => literal.datatype() == xsd::BOOLEAN,
Expression::If(_, a, b) => a.returns_boolean() && b.returns_boolean(), Self::If(_, a, b) => a.returns_boolean() && b.returns_boolean(),
_ => false, _ => false,
} }
} }
@ -847,7 +847,7 @@ impl GraphPattern {
} }
} }
if all.is_empty() { if all.is_empty() {
GraphPattern::empty() Self::empty()
} else { } else {
Self::Union { Self::Union {
inner: order_vec(all), inner: order_vec(all),

@ -3892,9 +3892,9 @@ impl TupleSelector {
fn get_pattern_value(&self, tuple: &EncodedTuple) -> Option<EncodedTerm> { fn get_pattern_value(&self, tuple: &EncodedTuple) -> Option<EncodedTerm> {
match self { match self {
TupleSelector::Constant(c) => Some(c.clone()), Self::Constant(c) => Some(c.clone()),
TupleSelector::Variable(v) => tuple.get(*v).cloned(), Self::Variable(v) => tuple.get(*v).cloned(),
TupleSelector::TriplePattern(triple) => Some( Self::TriplePattern(triple) => Some(
EncodedTriple { EncodedTriple {
subject: triple.subject.get_pattern_value(tuple)?, subject: triple.subject.get_pattern_value(tuple)?,
predicate: triple.predicate.get_pattern_value(tuple)?, predicate: triple.predicate.get_pattern_value(tuple)?,

@ -179,7 +179,7 @@ impl From<LoaderError> for io::Error {
LoaderError::Storage(error) => error.into(), LoaderError::Storage(error) => error.into(),
LoaderError::Parsing(error) => error.into(), LoaderError::Parsing(error) => error.into(),
LoaderError::InvalidBaseIri { .. } => { 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<SerializerError> for io::Error {
SerializerError::Storage(error) => error.into(), SerializerError::Storage(error) => error.into(),
SerializerError::Io(error) => error, SerializerError::Io(error) => error,
SerializerError::DatasetFormatExpected(_) => { SerializerError::DatasetFormatExpected(_) => {
io::Error::new(io::ErrorKind::InvalidInput, error.to_string()) Self::new(io::ErrorKind::InvalidInput, error.to_string())
} }
} }
} }

@ -153,10 +153,10 @@ impl FromStr for SmallString {
inner[15] = value inner[15] = value
.len() .len()
.try_into() .try_into()
.map_err(|_| BadSmallStringError::TooLong(value.len()))?; .map_err(|_| Self::Err::TooLong(value.len()))?;
Ok(Self { inner }) Ok(Self { inner })
} else { } else {
Err(BadSmallStringError::TooLong(value.len())) Err(Self::Err::TooLong(value.len()))
} }
} }
} }

Loading…
Cancel
Save