mssql_value_serializer/
errors.rs

1use std::{
2    error::Error,
3    fmt::{self, Display, Formatter},
4};
5
6/// Errors that occur when serializing a SQL Server literal.
7#[derive(Debug)]
8pub enum SqlLiteralError {
9    /// The floating-point value is not finite (`NaN` or `infinity`).
10    FloatNotFinite,
11}
12
13impl Display for SqlLiteralError {
14    #[inline]
15    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
16        match self {
17            Self::FloatNotFinite => f.write_str("float value is not finite"),
18        }
19    }
20}
21
22impl Error for SqlLiteralError {}
23
24/// Errors that occur when serializing a SQL Server literal for a value list.
25#[derive(Debug)]
26pub struct SqlLiteralErrorWithIndex {
27    pub index: usize,
28    pub error: SqlLiteralError,
29}
30
31impl Display for SqlLiteralErrorWithIndex {
32    #[inline]
33    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
34        f.write_fmt(format_args!("index = {}, ", self.index))?;
35
36        Display::fmt(&self.error, f)
37    }
38}
39
40impl Error for SqlLiteralErrorWithIndex {}