Skip to main content

gpui_query/core/error/
convert.rs

1//! Standard trait implementations for [`QueryError`](super::QueryError).
2
3use super::types::QueryError;
4
5impl std::fmt::Display for QueryError {
6    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7        write!(f, "{}: {}", self.kind(), self.message())
8    }
9}
10
11impl std::error::Error for QueryError {}
12
13impl AsRef<str> for QueryError {
14    fn as_ref(&self) -> &str {
15        self.message()
16    }
17}
18
19impl AsRef<std::sync::Arc<str>> for QueryError {
20    fn as_ref(&self) -> &std::sync::Arc<str> {
21        &self.message
22    }
23}
24
25impl From<String> for QueryError {
26    /// Creates a [`QueryError`] with kind [`QueryErrorKind::Unknown`](super::QueryErrorKind::Unknown).
27    ///
28    /// `From<String>` and `From<&str>` always map to `Unknown` because the
29    /// original error category cannot be recovered from a plain string. Use
30    /// [`QueryError::transport`], [`QueryError::response`], or
31    /// [`QueryError::cancelled`] for typed errors.
32    fn from(value: String) -> Self {
33        Self::unknown(value)
34    }
35}
36
37impl From<&str> for QueryError {
38    /// Creates a [`QueryError`] with kind [`QueryErrorKind::Unknown`](super::QueryErrorKind::Unknown).
39    ///
40    /// See [`From<String>`] for rationale on the `Unknown` mapping.
41    fn from(value: &str) -> Self {
42        Self::unknown(value)
43    }
44}