|
46 | 46 | //!
|
47 | 47 | //! ```rust
|
48 | 48 | //! # use scylla_cql::frame::response::result::ColumnType;
|
49 |
| -//! # use scylla_cql::frame::frame_errors::ParseError; |
50 | 49 | //! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
|
51 | 50 | //! # use scylla_cql::types::deserialize::value::DeserializeValue;
|
| 51 | +//! # use thiserror::Error; |
52 | 52 | //! struct MyVec(Vec<u8>);
|
| 53 | +//! #[derive(Debug, Error)] |
| 54 | +//! enum MyDeserError { |
| 55 | +//! #[error("Expected bytes")] |
| 56 | +//! ExpectedBytes, |
| 57 | +//! #[error("Expected non-null")] |
| 58 | +//! ExpectedNonNull, |
| 59 | +//! } |
53 | 60 | //! impl<'frame> DeserializeValue<'frame> for MyVec {
|
54 | 61 | //! fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> {
|
55 | 62 | //! if let ColumnType::Blob = typ {
|
56 | 63 | //! return Ok(());
|
57 | 64 | //! }
|
58 |
| -//! Err(TypeCheckError::new( |
59 |
| -//! ParseError::BadIncomingData("Expected bytes".to_owned()) |
60 |
| -//! )) |
| 65 | +//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes)) |
61 | 66 | //! }
|
62 | 67 | //!
|
63 | 68 | //! fn deserialize(
|
64 | 69 | //! _typ: &'frame ColumnType,
|
65 | 70 | //! v: Option<FrameSlice<'frame>>,
|
66 | 71 | //! ) -> Result<Self, DeserializationError> {
|
67 |
| -//! v.ok_or_else(|| { |
68 |
| -//! DeserializationError::new( |
69 |
| -//! ParseError::BadIncomingData("Expected non-null value".to_owned()) |
70 |
| -//! ) |
71 |
| -//! }) |
72 |
| -//! .map(|v| Self(v.as_slice().to_vec())) |
| 72 | +//! v.ok_or_else(|| DeserializationError::new(MyDeserError::ExpectedNonNull)) |
| 73 | +//! .map(|v| Self(v.as_slice().to_vec())) |
73 | 74 | //! }
|
74 | 75 | //! }
|
75 | 76 | //! ```
|
|
85 | 86 | //! For example:
|
86 | 87 | //!
|
87 | 88 | //! ```rust
|
88 |
| -//! # use scylla_cql::frame::frame_errors::ParseError; |
89 | 89 | //! # use scylla_cql::frame::response::result::ColumnType;
|
90 | 90 | //! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
|
91 | 91 | //! # use scylla_cql::types::deserialize::value::DeserializeValue;
|
| 92 | +//! # use thiserror::Error; |
92 | 93 | //! struct MySlice<'a>(&'a [u8]);
|
| 94 | +//! #[derive(Debug, Error)] |
| 95 | +//! enum MyDeserError { |
| 96 | +//! #[error("Expected bytes")] |
| 97 | +//! ExpectedBytes, |
| 98 | +//! #[error("Expected non-null")] |
| 99 | +//! ExpectedNonNull, |
| 100 | +//! } |
93 | 101 | //! impl<'a, 'frame> DeserializeValue<'frame> for MySlice<'a>
|
94 | 102 | //! where
|
95 | 103 | //! 'frame: 'a,
|
|
98 | 106 | //! if let ColumnType::Blob = typ {
|
99 | 107 | //! return Ok(());
|
100 | 108 | //! }
|
101 |
| -//! Err(TypeCheckError::new( |
102 |
| -//! ParseError::BadIncomingData("Expected bytes".to_owned()) |
103 |
| -//! )) |
| 109 | +//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes)) |
104 | 110 | //! }
|
105 | 111 | //!
|
106 | 112 | //! fn deserialize(
|
107 | 113 | //! _typ: &'frame ColumnType,
|
108 | 114 | //! v: Option<FrameSlice<'frame>>,
|
109 | 115 | //! ) -> Result<Self, DeserializationError> {
|
110 |
| -//! v.ok_or_else(|| { |
111 |
| -//! DeserializationError::new( |
112 |
| -//! ParseError::BadIncomingData("Expected non-null value".to_owned()) |
113 |
| -//! ) |
114 |
| -//! }) |
115 |
| -//! .map(|v| Self(v.as_slice())) |
| 116 | +//! v.ok_or_else(|| DeserializationError::new(MyDeserError::ExpectedNonNull)) |
| 117 | +//! .map(|v| Self(v.as_slice())) |
116 | 118 | //! }
|
117 | 119 | //! }
|
118 | 120 | //! ```
|
|
135 | 137 | //! Example:
|
136 | 138 | //!
|
137 | 139 | //! ```rust
|
138 |
| -//! # use scylla_cql::frame::frame_errors::ParseError; |
139 | 140 | //! # use scylla_cql::frame::response::result::ColumnType;
|
140 | 141 | //! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
|
141 | 142 | //! # use scylla_cql::types::deserialize::value::DeserializeValue;
|
142 | 143 | //! # use bytes::Bytes;
|
| 144 | +//! # use thiserror::Error; |
143 | 145 | //! struct MyBytes(Bytes);
|
| 146 | +//! #[derive(Debug, Error)] |
| 147 | +//! enum MyDeserError { |
| 148 | +//! #[error("Expected bytes")] |
| 149 | +//! ExpectedBytes, |
| 150 | +//! #[error("Expected non-null")] |
| 151 | +//! ExpectedNonNull, |
| 152 | +//! } |
144 | 153 | //! impl<'frame> DeserializeValue<'frame> for MyBytes {
|
145 | 154 | //! fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> {
|
146 | 155 | //! if let ColumnType::Blob = typ {
|
147 | 156 | //! return Ok(());
|
148 | 157 | //! }
|
149 |
| -//! Err(TypeCheckError::new(ParseError::BadIncomingData("Expected bytes".to_owned()))) |
| 158 | +//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes)) |
150 | 159 | //! }
|
151 | 160 | //!
|
152 | 161 | //! fn deserialize(
|
153 | 162 | //! _typ: &'frame ColumnType,
|
154 | 163 | //! v: Option<FrameSlice<'frame>>,
|
155 | 164 | //! ) -> Result<Self, DeserializationError> {
|
156 |
| -//! v.ok_or_else(|| { |
157 |
| -//! DeserializationError::new(ParseError::BadIncomingData("Expected non-null value".to_owned())) |
158 |
| -//! }) |
159 |
| -//! .map(|v| Self(v.to_bytes())) |
| 165 | +//! v.ok_or_else(|| DeserializationError::new(MyDeserError::ExpectedNonNull)) |
| 166 | +//! .map(|v| Self(v.to_bytes())) |
160 | 167 | //! }
|
161 | 168 | //! }
|
162 | 169 | //! ```
|
163 |
| -// TODO: in the above module docstring, stop abusing ParseError once errors are refactored. |
164 | 170 |
|
165 | 171 | pub mod frame_slice;
|
166 | 172 | pub mod result;
|
|
0 commit comments