surrealdb_core/ctx/
reason.rs1use crate::err::Error;
2use std::fmt;
3use std::io;
4
5#[derive(Copy, Clone, Eq, PartialEq, Debug)]
6#[non_exhaustive]
7pub enum Reason {
8 Timedout,
9 Canceled,
10}
11
12impl fmt::Display for Reason {
13 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14 match *self {
15 Reason::Timedout => write!(f, "Context timedout"),
16 Reason::Canceled => write!(f, "Context canceled"),
17 }
18 }
19}
20
21impl From<Reason> for Error {
22 fn from(reason: Reason) -> Self {
23 match reason {
24 Reason::Timedout => Error::QueryTimedout,
25 Reason::Canceled => Error::QueryCancelled,
26 }
27 }
28}
29
30impl From<Reason> for io::Error {
31 fn from(reason: Reason) -> Self {
32 let kind = match reason {
33 Reason::Timedout => io::ErrorKind::TimedOut,
34 Reason::Canceled => io::ErrorKind::Other,
35 };
36 io::Error::new(kind, reason.to_string())
37 }
38}