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 10 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> {
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<Self, Self::Err> {
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<Self, Self::Err> {
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<Self, Self::Err> {
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<Self, Self::Err> {
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,

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

@ -399,23 +399,23 @@ enum RdfXmlState {
impl RdfXmlState {
fn base_iri(&self) -> Option<&Iri<String>> {
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(),
}
}
}

@ -1504,13 +1504,13 @@ impl TryFrom<DayTimeDuration> 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<Duration> for TimezoneOffset {
#[inline]
fn try_from(value: Duration) -> Result<Self, Self::Error> {
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<DateTimeOverflowError> for ParseDateTimeError {
fn from(error: DateTimeOverflowError) -> Self {
ParseDateTimeError {
Self {
kind: ParseDateTimeErrorKind::Overflow(error),
}
}

@ -187,7 +187,7 @@ impl FromStr for Duration {
fn from_str(input: &str) -> Result<Self, Self::Err> {
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<Self, Self::Err> {
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<DayTimeDuration> 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<Self, Self::Err> {
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"))?,
))
}
}

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

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

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

@ -72,7 +72,7 @@ impl Error for SyntaxError {}
impl From<SyntaxError> for io::Error {
#[inline]
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 {
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),

@ -3892,9 +3892,9 @@ impl TupleSelector {
fn get_pattern_value(&self, tuple: &EncodedTuple) -> Option<EncodedTerm> {
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)?,

@ -179,7 +179,7 @@ impl From<LoaderError> 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<SerializerError> 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())
}
}
}

@ -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()))
}
}
}

Loading…
Cancel
Save