Makes a lot of dumb functions inline

pull/190/head
Tpt 3 years ago
parent ec5c7c86be
commit fc26fa87a5
  1. 12
      Cargo.lock
  2. 1
      lib/Cargo.toml
  3. 2
      lib/oxrdf/Cargo.toml
  4. 5
      lib/oxrdf/src/blank_node.rs
  5. 2
      lib/oxrdf/src/interning.rs
  6. 51
      lib/oxrdf/src/sophia.rs
  7. 3
      lib/sparesults/src/solution.rs
  8. 2
      lib/spargebra/src/parser.rs
  9. 11
      lib/src/io/error.rs
  10. 6
      lib/src/io/format.rs
  11. 4
      lib/src/io/read.rs
  12. 2
      lib/src/io/write.rs
  13. 13
      lib/src/sparql/error.rs
  14. 20
      lib/src/storage/error.rs

12
Cargo.lock generated

@ -351,16 +351,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "dashmap"
version = "4.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
dependencies = [
"cfg-if",
"num_cpus",
]
[[package]]
name = "digest"
version = "0.10.1"
@ -625,7 +615,6 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aeb7b21a526375c5ca55f1a6dfd4e1fad9fa4edd750f530252a718a44b2608f0"
dependencies = [
"dashmap",
"hashbrown",
]
@ -841,7 +830,6 @@ dependencies = [
"getrandom",
"hex",
"js-sys",
"lasso",
"lazy_static",
"libc",
"md-5",

@ -36,7 +36,6 @@ rio_xml = "0.6"
hex = "0.4"
nom = "7"
siphasher = "0.3"
lasso = {version="0.6", features=["multi-threaded", "inline-more"]}
lazy_static = "1"
sophia_api = { version = "0.7", optional = true }
num_cpus = "1"

@ -20,7 +20,7 @@ rdf-star = []
rand = "0.8"
oxilangtag = "0.1"
oxiri = "0.1"
lasso = { version="0.6", features = ["multi-threaded", "inline-more"] }
lasso = { version = "0.6", features = ["inline-more"] }
sophia_api = { version = "0.7", optional = true }
[package.metadata.docs.rs]

@ -49,6 +49,7 @@ impl BlankNode {
/// according to N-Triples, Turtle and SPARQL grammars.
///
/// [`BlankNode::new()`] is a safe version of this constructor and should be used for untrusted data.
#[inline]
pub fn new_unchecked(id: impl Into<String>) -> Self {
let id = id.into();
if let Some(numerical_id) = to_integer_id(&id) {
@ -158,6 +159,7 @@ impl<'a> BlankNodeRef<'a> {
/// according to N-Triples, Turtle and SPARQL grammars.
///
/// [`BlankNodeRef::new()`) is a safe version of this constructor and should be used for untrusted data.
#[inline]
pub fn new_unchecked(id: &'a str) -> Self {
if let Some(numerical_id) = to_integer_id(id) {
Self(BlankNodeRefContent::Anonymous {
@ -246,12 +248,14 @@ impl PartialEq<BlankNodeRef<'_>> for BlankNode {
struct IdStr([u8; 32]);
impl IdStr {
#[inline]
fn new(id: u128) -> Self {
let mut str = [0; 32];
write!(&mut str[..], "{:x}", id).unwrap();
Self(str)
}
#[inline]
fn as_str(&self) -> &str {
let len = self.0.iter().position(|x| x == &0).unwrap_or(32);
str::from_utf8(&self.0[..len]).unwrap()
@ -317,6 +321,7 @@ fn validate_blank_node_identifier(id: &str) -> Result<(), BlankNodeIdParseError>
}
}
#[inline]
fn to_integer_id(id: &str) -> Option<u128> {
let digits = id.as_bytes();
let mut value: u128 = 0;

@ -172,6 +172,7 @@ impl InternedLiteral {
}
}
#[allow(missing_copy_implementations)]
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub enum InternedSubject {
NamedNode(InternedNamedNode),
@ -297,6 +298,7 @@ impl InternedGraphName {
}
}
#[allow(missing_copy_implementations)]
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub enum InternedTerm {
NamedNode(InternedNamedNode),

@ -5,14 +5,17 @@ use sophia_api::term::*;
use std::fmt;
impl TTerm for BlankNode {
#[inline]
fn kind(&self) -> TermKind {
TermKind::BlankNode
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
self.as_str().into()
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
self
}
@ -21,6 +24,7 @@ impl TTerm for BlankNode {
impl TryCopyTerm for BlankNode {
type Error = SophiaToOxigraphConversionError;
#[inline]
fn try_copy<T>(other: &T) -> Result<Self, Self::Error>
where
T: TTerm + ?Sized,
@ -33,28 +37,34 @@ impl TryCopyTerm for BlankNode {
}
impl<'a> TTerm for BlankNodeRef<'a> {
#[inline]
fn kind(&self) -> TermKind {
TermKind::BlankNode
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
self.as_str().into()
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
self
}
}
impl TTerm for Literal {
#[inline]
fn kind(&self) -> TermKind {
TermKind::Literal
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
Self::value(self).into()
}
#[inline]
fn datatype(&self) -> Option<SimpleIri<'_>> {
Some(SimpleIri::new_unchecked(
Self::datatype(self).as_str(),
@ -62,10 +72,12 @@ impl TTerm for Literal {
))
}
#[inline]
fn language(&self) -> Option<&str> {
Self::language(self)
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
self
}
@ -74,6 +86,7 @@ impl TTerm for Literal {
impl TryCopyTerm for Literal {
type Error = SophiaToOxigraphConversionError;
#[inline]
fn try_copy<T>(other: &T) -> Result<Self, Self::Error>
where
T: TTerm + ?Sized,
@ -95,14 +108,17 @@ impl TryCopyTerm for Literal {
}
impl<'a> TTerm for LiteralRef<'a> {
#[inline]
fn kind(&self) -> TermKind {
TermKind::Literal
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
LiteralRef::value(*self).into()
}
#[inline]
fn datatype(&self) -> Option<SimpleIri<'_>> {
Some(SimpleIri::new_unchecked(
LiteralRef::datatype(*self).as_str(),
@ -110,24 +126,29 @@ impl<'a> TTerm for LiteralRef<'a> {
))
}
#[inline]
fn language(&self) -> Option<&str> {
LiteralRef::language(*self)
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
self
}
}
impl TTerm for NamedNode {
#[inline]
fn kind(&self) -> TermKind {
TermKind::Iri
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
self.as_str().into()
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
self
}
@ -136,6 +157,7 @@ impl TTerm for NamedNode {
impl TryCopyTerm for NamedNode {
type Error = SophiaToOxigraphConversionError;
#[inline]
fn try_copy<T>(other: &T) -> Result<Self, Self::Error>
where
T: TTerm + ?Sized,
@ -148,26 +170,31 @@ impl TryCopyTerm for NamedNode {
}
impl<'a> From<SimpleIri<'a>> for NamedNode {
#[inline]
fn from(other: SimpleIri<'a>) -> Self {
Self::new_unchecked(other.value())
}
}
impl<'a> TTerm for NamedNodeRef<'a> {
#[inline]
fn kind(&self) -> TermKind {
TermKind::BlankNode
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
self.as_str().into()
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
self
}
}
impl From<GraphName> for Option<Term> {
#[inline]
fn from(other: GraphName) -> Self {
match other {
GraphName::NamedNode(n) => Some(n.into()),
@ -178,6 +205,7 @@ impl From<GraphName> for Option<Term> {
}
impl<'a> From<GraphNameRef<'a>> for Option<TermRef<'a>> {
#[inline]
fn from(other: GraphNameRef<'a>) -> Self {
match other {
GraphNameRef::NamedNode(n) => Some(n.into()),
@ -188,6 +216,7 @@ impl<'a> From<GraphNameRef<'a>> for Option<TermRef<'a>> {
}
impl TTerm for Subject {
#[inline]
fn kind(&self) -> TermKind {
match self {
Self::NamedNode(_) => TermKind::Iri,
@ -196,6 +225,7 @@ impl TTerm for Subject {
}
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
match self {
Self::NamedNode(n) => n.value_raw(),
@ -204,6 +234,7 @@ impl TTerm for Subject {
}
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
match self {
Self::NamedNode(n) => n.as_dyn(),
@ -216,6 +247,7 @@ impl TTerm for Subject {
impl TryCopyTerm for Subject {
type Error = SophiaToOxigraphConversionError;
#[inline]
fn try_copy<T>(other: &T) -> Result<Self, Self::Error>
where
T: TTerm + ?Sized,
@ -229,6 +261,7 @@ impl TryCopyTerm for Subject {
}
impl<'a> TTerm for SubjectRef<'a> {
#[inline]
fn kind(&self) -> TermKind {
match self {
Self::NamedNode(_) => TermKind::Iri,
@ -237,6 +270,7 @@ impl<'a> TTerm for SubjectRef<'a> {
}
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
match self {
Self::NamedNode(n) => n.value_raw(),
@ -245,6 +279,7 @@ impl<'a> TTerm for SubjectRef<'a> {
}
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
match self {
Self::NamedNode(n) => n.as_dyn(),
@ -255,6 +290,7 @@ impl<'a> TTerm for SubjectRef<'a> {
}
impl TTerm for Term {
#[inline]
fn kind(&self) -> TermKind {
match self {
Self::NamedNode(_) => TermKind::Iri,
@ -264,6 +300,7 @@ impl TTerm for Term {
}
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
match self {
Self::NamedNode(n) => n.value_raw(),
@ -273,6 +310,7 @@ impl TTerm for Term {
}
}
#[inline]
fn datatype(&self) -> Option<SimpleIri<'_>> {
if let Self::Literal(l) = self {
TTerm::datatype(l)
@ -281,6 +319,7 @@ impl TTerm for Term {
}
}
#[inline]
fn language(&self) -> Option<&str> {
if let Self::Literal(l) = self {
TTerm::language(l)
@ -289,6 +328,7 @@ impl TTerm for Term {
}
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
match self {
Self::NamedNode(n) => n.as_dyn(),
@ -302,6 +342,7 @@ impl TTerm for Term {
impl TryCopyTerm for Term {
type Error = SophiaToOxigraphConversionError;
#[inline]
fn try_copy<T>(other: &T) -> Result<Self, Self::Error>
where
T: TTerm + ?Sized,
@ -316,6 +357,7 @@ impl TryCopyTerm for Term {
}
impl<'a> TTerm for TermRef<'a> {
#[inline]
fn kind(&self) -> TermKind {
match self {
Self::NamedNode(_) => TermKind::Iri,
@ -325,6 +367,7 @@ impl<'a> TTerm for TermRef<'a> {
}
}
#[inline]
fn datatype(&self) -> Option<SimpleIri<'_>> {
if let Self::Literal(l) = self {
TTerm::datatype(l)
@ -333,6 +376,7 @@ impl<'a> TTerm for TermRef<'a> {
}
}
#[inline]
fn language(&self) -> Option<&str> {
if let Self::Literal(l) = self {
TTerm::language(l)
@ -341,6 +385,7 @@ impl<'a> TTerm for TermRef<'a> {
}
}
#[inline]
fn value_raw(&self) -> RawValue<'_> {
match self {
Self::NamedNode(n) => n.value_raw(),
@ -350,6 +395,7 @@ impl<'a> TTerm for TermRef<'a> {
}
}
#[inline]
fn as_dyn(&self) -> &dyn TTerm {
match self {
Self::NamedNode(n) => n.as_dyn(),
@ -361,6 +407,7 @@ impl<'a> TTerm for TermRef<'a> {
}
impl From<Quad> for ([Term; 3], Option<Term>) {
#[inline]
fn from(other: Quad) -> Self {
(
[other.subject.into(), other.predicate.into(), other.object],
@ -370,6 +417,7 @@ impl From<Quad> for ([Term; 3], Option<Term>) {
}
impl<'a> From<QuadRef<'a>> for ([TermRef<'a>; 3], Option<TermRef<'a>>) {
#[inline]
fn from(other: QuadRef<'a>) -> Self {
(
[other.subject.into(), other.predicate.into(), other.object],
@ -379,12 +427,14 @@ impl<'a> From<QuadRef<'a>> for ([TermRef<'a>; 3], Option<TermRef<'a>>) {
}
impl From<Triple> for [Term; 3] {
#[inline]
fn from(other: Triple) -> Self {
[other.subject.into(), other.predicate.into(), other.object]
}
}
impl<'a> From<TripleRef<'a>> for [TermRef<'a>; 3] {
#[inline]
fn from(other: TripleRef<'a>) -> Self {
[other.subject.into(), other.predicate.into(), other.object]
}
@ -397,6 +447,7 @@ impl<'a> From<TripleRef<'a>> for [TermRef<'a>; 3] {
pub struct SophiaToOxigraphConversionError;
impl fmt::Display for SophiaToOxigraphConversionError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}

@ -129,6 +129,7 @@ impl<'a> IntoIterator for &'a QuerySolution {
type Item = (&'a Variable, &'a Term);
type IntoIter = Iter<'a>;
#[inline]
fn into_iter(self) -> Iter<'a> {
Iter {
inner: self.variables.iter().zip(&self.values),
@ -152,6 +153,7 @@ pub struct Iter<'a> {
impl<'a> Iterator for Iter<'a> {
type Item = (&'a Variable, &'a Term);
#[inline]
fn next(&mut self) -> Option<(&'a Variable, &'a Term)> {
for (variable, value) in &mut self.inner {
if let Some(value) = value {
@ -161,6 +163,7 @@ impl<'a> Iterator for Iter<'a> {
None
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(0, self.inner.size_hint().1)
}

@ -78,6 +78,7 @@ enum ParseErrorKind {
}
impl fmt::Display for ParseError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.inner {
ParseErrorKind::InvalidBaseIri(e) => {
@ -89,6 +90,7 @@ impl fmt::Display for ParseError {
}
impl Error for ParseError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self.inner {
ParseErrorKind::InvalidBaseIri(ref e) => Some(e),

@ -14,6 +14,7 @@ pub enum ParseError {
}
impl ParseError {
#[inline]
pub(crate) fn invalid_base_iri(iri: &str, error: IriParseError) -> Self {
Self::Syntax(SyntaxError {
inner: SyntaxErrorKind::InvalidBaseIri {
@ -25,6 +26,7 @@ impl ParseError {
}
impl fmt::Display for ParseError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => e.fmt(f),
@ -34,6 +36,7 @@ impl fmt::Display for ParseError {
}
impl Error for ParseError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Io(e) => Some(e),
@ -44,6 +47,7 @@ impl Error for ParseError {
#[allow(clippy::fallible_impl_from)]
impl From<TurtleError> for ParseError {
#[inline]
fn from(error: TurtleError) -> Self {
let error = io::Error::from(error);
if error.get_ref().map_or(false, |e| e.is::<TurtleError>()) {
@ -58,6 +62,7 @@ impl From<TurtleError> for ParseError {
#[allow(clippy::fallible_impl_from)]
impl From<RdfXmlError> for ParseError {
#[inline]
fn from(error: RdfXmlError) -> Self {
let error = io::Error::from(error);
if error.get_ref().map_or(false, |e| e.is::<RdfXmlError>()) {
@ -71,18 +76,21 @@ impl From<RdfXmlError> for ParseError {
}
impl From<io::Error> for ParseError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl From<SyntaxError> for ParseError {
#[inline]
fn from(error: SyntaxError) -> Self {
Self::Syntax(error)
}
}
impl From<ParseError> for io::Error {
#[inline]
fn from(error: ParseError) -> Self {
match error {
ParseError::Io(error) => error,
@ -105,6 +113,7 @@ enum SyntaxErrorKind {
}
impl fmt::Display for SyntaxError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.inner {
SyntaxErrorKind::Turtle(e) => e.fmt(f),
@ -117,6 +126,7 @@ impl fmt::Display for SyntaxError {
}
impl Error for SyntaxError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match &self.inner {
SyntaxErrorKind::Turtle(e) => Some(e),
@ -127,6 +137,7 @@ impl Error for SyntaxError {
}
impl From<SyntaxError> for io::Error {
#[inline]
fn from(error: SyntaxError) -> Self {
match error.inner {
SyntaxErrorKind::Turtle(error) => error.into(),

@ -71,6 +71,7 @@ impl GraphFormat {
///
/// assert_eq!(GraphFormat::from_media_type("text/turtle; charset=utf-8"), Some(GraphFormat::Turtle))
/// ```
#[inline]
pub fn from_media_type(media_type: &str) -> Option<Self> {
match media_type.split(';').next()?.trim() {
"application/n-triples" | "text/plain" => Some(Self::NTriples),
@ -90,6 +91,7 @@ impl GraphFormat {
///
/// assert_eq!(GraphFormat::from_extension("nt"), Some(GraphFormat::NTriples))
/// ```
#[inline]
pub fn from_extension(extension: &str) -> Option<Self> {
match extension {
"nt" | "txt" => Some(Self::NTriples),
@ -167,6 +169,7 @@ impl DatasetFormat {
///
/// assert_eq!(DatasetFormat::from_media_type("application/n-quads; charset=utf-8"), Some(DatasetFormat::NQuads))
/// ```
#[inline]
pub fn from_media_type(media_type: &str) -> Option<Self> {
match media_type.split(';').next()?.trim() {
"application/n-quads" | "text/x-nquads" | "text/nquads" => Some(Self::NQuads),
@ -185,6 +188,7 @@ impl DatasetFormat {
///
/// assert_eq!(DatasetFormat::from_extension("nq"), Some(DatasetFormat::NQuads))
/// ```
#[inline]
pub fn from_extension(extension: &str) -> Option<Self> {
match extension {
"nq" | "txt" => Some(Self::NQuads),
@ -198,6 +202,7 @@ impl TryFrom<DatasetFormat> for GraphFormat {
type Error = ();
/// Attempts to find a graph format that is a subset of this [`DatasetFormat`].
#[inline]
fn try_from(value: DatasetFormat) -> Result<Self, ()> {
match value {
DatasetFormat::NQuads => Ok(Self::NTriples),
@ -210,6 +215,7 @@ impl TryFrom<GraphFormat> for DatasetFormat {
type Error = ();
/// Attempts to find a dataset format that is a superset of this [`GraphFormat`].
#[inline]
fn try_from(value: GraphFormat) -> Result<Self, ()> {
match value {
GraphFormat::NTriples => Ok(Self::NQuads),

@ -38,6 +38,7 @@ pub struct GraphParser {
impl GraphParser {
/// Builds a parser for the given format.
#[inline]
pub fn from_format(format: GraphFormat) -> Self {
Self {
format,
@ -60,6 +61,7 @@ impl GraphParser {
///assert_eq!(triples[0].subject.to_string(), "<http://example.com/s>");
/// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ```
#[inline]
pub fn with_base_iri(mut self, base_iri: impl Into<String>) -> Result<Self, IriParseError> {
self.base_iri = Some(Iri::parse(base_iri.into())?);
Ok(self)
@ -187,6 +189,7 @@ pub struct DatasetParser {
impl DatasetParser {
/// Builds a parser for the given format.
#[inline]
pub fn from_format(format: DatasetFormat) -> Self {
Self {
format,
@ -209,6 +212,7 @@ impl DatasetParser {
///assert_eq!(triples[0].subject.to_string(), "<http://example.com/s>");
/// # Result::<_,Box<dyn std::error::Error>>::Ok(())
/// ```
#[inline]
pub fn with_base_iri(mut self, base_iri: impl Into<String>) -> Result<Self, IriParseError> {
self.base_iri = Some(Iri::parse(base_iri.into())?);
Ok(self)

@ -37,6 +37,7 @@ pub struct GraphSerializer {
impl GraphSerializer {
/// Builds a serializer for the given format
#[inline]
pub fn from_format(format: GraphFormat) -> Self {
Self { format }
}
@ -182,6 +183,7 @@ pub struct DatasetSerializer {
impl DatasetSerializer {
/// Builds a serializer for the given format
#[inline]
pub fn from_format(format: DatasetFormat) -> Self {
Self { format }
}

@ -35,6 +35,7 @@ enum QueryErrorKind {
}
impl fmt::Display for EvaluationError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Parsing(error) => error.fmt(f),
@ -48,6 +49,7 @@ impl fmt::Display for EvaluationError {
}
impl fmt::Display for QueryError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.inner {
QueryErrorKind::Msg { msg } => write!(f, "{}", msg),
@ -57,6 +59,7 @@ impl fmt::Display for QueryError {
}
impl error::Error for EvaluationError {
#[inline]
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Self::Parsing(e) => Some(e),
@ -70,6 +73,7 @@ impl error::Error for EvaluationError {
}
impl error::Error for QueryError {
#[inline]
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match &self.inner {
QueryErrorKind::Msg { .. } => None,
@ -80,6 +84,7 @@ impl error::Error for QueryError {
impl EvaluationError {
/// Wraps another error.
#[inline]
pub(crate) fn wrap(error: impl error::Error + Send + Sync + 'static) -> Self {
Self::Query(QueryError {
inner: QueryErrorKind::Other(Box::new(error)),
@ -87,6 +92,7 @@ impl EvaluationError {
}
/// Builds an error from a printable error message.
#[inline]
pub(crate) fn msg(msg: impl Into<String>) -> Self {
Self::Query(QueryError {
inner: QueryErrorKind::Msg { msg: msg.into() },
@ -95,42 +101,49 @@ impl EvaluationError {
}
impl From<Infallible> for EvaluationError {
#[inline]
fn from(error: Infallible) -> Self {
match error {}
}
}
impl From<spargebra::ParseError> for EvaluationError {
#[inline]
fn from(error: spargebra::ParseError) -> Self {
Self::Parsing(error)
}
}
impl From<StorageError> for EvaluationError {
#[inline]
fn from(error: StorageError) -> Self {
Self::Storage(error)
}
}
impl From<io::Error> for EvaluationError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl From<ParseError> for EvaluationError {
#[inline]
fn from(error: ParseError) -> Self {
Self::GraphParsing(error)
}
}
impl From<sparesults::ParseError> for EvaluationError {
#[inline]
fn from(error: sparesults::ParseError) -> Self {
Self::ResultsParsing(error)
}
}
impl From<EvaluationError> for io::Error {
#[inline]
fn from(error: EvaluationError) -> Self {
match error {
EvaluationError::Parsing(error) => Self::new(io::ErrorKind::InvalidData, error),

@ -16,6 +16,7 @@ pub enum StorageError {
}
impl fmt::Display for StorageError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => e.fmt(f),
@ -26,6 +27,7 @@ impl fmt::Display for StorageError {
}
impl Error for StorageError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Io(e) => Some(e),
@ -36,12 +38,14 @@ impl Error for StorageError {
}
impl From<io::Error> for StorageError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl From<StorageError> for io::Error {
#[inline]
fn from(error: StorageError) -> Self {
match error {
StorageError::Io(error) => error,
@ -65,6 +69,7 @@ enum CorruptionErrorKind {
impl CorruptionError {
/// Builds an error from a printable error message.
#[inline]
pub(crate) fn new(error: impl Into<Box<dyn Error + Send + Sync + 'static>>) -> Self {
Self {
inner: CorruptionErrorKind::Other(error.into()),
@ -72,6 +77,7 @@ impl CorruptionError {
}
/// Builds an error from a printable error message.
#[inline]
pub(crate) fn msg(msg: impl Into<String>) -> Self {
Self {
inner: CorruptionErrorKind::Msg(msg.into()),
@ -80,6 +86,7 @@ impl CorruptionError {
}
impl fmt::Display for CorruptionError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.inner {
CorruptionErrorKind::Msg(e) => e.fmt(f),
@ -89,6 +96,7 @@ impl fmt::Display for CorruptionError {
}
impl Error for CorruptionError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match &self.inner {
CorruptionErrorKind::Msg(_) => None,
@ -98,12 +106,14 @@ impl Error for CorruptionError {
}
impl From<CorruptionError> for StorageError {
#[inline]
fn from(error: CorruptionError) -> Self {
Self::Corruption(error)
}
}
impl From<CorruptionError> for io::Error {
#[inline]
fn from(error: CorruptionError) -> Self {
Self::new(io::ErrorKind::InvalidData, error)
}
@ -119,6 +129,7 @@ pub enum LoaderError {
}
impl fmt::Display for LoaderError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Parsing(e) => e.fmt(f),
@ -128,6 +139,7 @@ impl fmt::Display for LoaderError {
}
impl Error for LoaderError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Parsing(e) => Some(e),
@ -137,18 +149,21 @@ impl Error for LoaderError {
}
impl From<ParseError> for LoaderError {
#[inline]
fn from(error: ParseError) -> Self {
Self::Parsing(error)
}
}
impl From<StorageError> for LoaderError {
#[inline]
fn from(error: StorageError) -> Self {
Self::Storage(error)
}
}
impl From<LoaderError> for io::Error {
#[inline]
fn from(error: LoaderError) -> Self {
match error {
LoaderError::Storage(error) => error.into(),
@ -167,6 +182,7 @@ pub enum SerializerError {
}
impl fmt::Display for SerializerError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => e.fmt(f),
@ -176,6 +192,7 @@ impl fmt::Display for SerializerError {
}
impl Error for SerializerError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Io(e) => Some(e),
@ -185,18 +202,21 @@ impl Error for SerializerError {
}
impl From<io::Error> for SerializerError {
#[inline]
fn from(error: io::Error) -> Self {
Self::Io(error)
}
}
impl From<StorageError> for SerializerError {
#[inline]
fn from(error: StorageError) -> Self {
Self::Storage(error)
}
}
impl From<SerializerError> for io::Error {
#[inline]
fn from(error: SerializerError) -> Self {
match error {
SerializerError::Storage(error) => error.into(),

Loading…
Cancel
Save