Skip to content

Commit 8855a32

Browse files
committed
deser: fix doc tests by removing ParseError
1 parent 02efa63 commit 8855a32

File tree

1 file changed

+33
-27
lines changed
  • scylla-cql/src/types/deserialize

1 file changed

+33
-27
lines changed

scylla-cql/src/types/deserialize/mod.rs

+33-27
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,31 @@
4646
//!
4747
//! ```rust
4848
//! # use scylla_cql::frame::response::result::ColumnType;
49-
//! # use scylla_cql::frame::frame_errors::ParseError;
5049
//! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
5150
//! # use scylla_cql::types::deserialize::value::DeserializeValue;
51+
//! # use thiserror::Error;
5252
//! 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+
//! }
5360
//! impl<'frame> DeserializeValue<'frame> for MyVec {
5461
//! fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> {
5562
//! if let ColumnType::Blob = typ {
5663
//! return Ok(());
5764
//! }
58-
//! Err(TypeCheckError::new(
59-
//! ParseError::BadIncomingData("Expected bytes".to_owned())
60-
//! ))
65+
//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes))
6166
//! }
6267
//!
6368
//! fn deserialize(
6469
//! _typ: &'frame ColumnType,
6570
//! v: Option<FrameSlice<'frame>>,
6671
//! ) -> 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()))
7374
//! }
7475
//! }
7576
//! ```
@@ -85,11 +86,18 @@
8586
//! For example:
8687
//!
8788
//! ```rust
88-
//! # use scylla_cql::frame::frame_errors::ParseError;
8989
//! # use scylla_cql::frame::response::result::ColumnType;
9090
//! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
9191
//! # use scylla_cql::types::deserialize::value::DeserializeValue;
92+
//! # use thiserror::Error;
9293
//! 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+
//! }
93101
//! impl<'a, 'frame> DeserializeValue<'frame> for MySlice<'a>
94102
//! where
95103
//! 'frame: 'a,
@@ -98,21 +106,15 @@
98106
//! if let ColumnType::Blob = typ {
99107
//! return Ok(());
100108
//! }
101-
//! Err(TypeCheckError::new(
102-
//! ParseError::BadIncomingData("Expected bytes".to_owned())
103-
//! ))
109+
//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes))
104110
//! }
105111
//!
106112
//! fn deserialize(
107113
//! _typ: &'frame ColumnType,
108114
//! v: Option<FrameSlice<'frame>>,
109115
//! ) -> 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()))
116118
//! }
117119
//! }
118120
//! ```
@@ -135,32 +137,36 @@
135137
//! Example:
136138
//!
137139
//! ```rust
138-
//! # use scylla_cql::frame::frame_errors::ParseError;
139140
//! # use scylla_cql::frame::response::result::ColumnType;
140141
//! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
141142
//! # use scylla_cql::types::deserialize::value::DeserializeValue;
142143
//! # use bytes::Bytes;
144+
//! # use thiserror::Error;
143145
//! struct MyBytes(Bytes);
146+
//! #[derive(Debug, Error)]
147+
//! enum MyDeserError {
148+
//! #[error("Expected bytes")]
149+
//! ExpectedBytes,
150+
//! #[error("Expected non-null")]
151+
//! ExpectedNonNull,
152+
//! }
144153
//! impl<'frame> DeserializeValue<'frame> for MyBytes {
145154
//! fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> {
146155
//! if let ColumnType::Blob = typ {
147156
//! return Ok(());
148157
//! }
149-
//! Err(TypeCheckError::new(ParseError::BadIncomingData("Expected bytes".to_owned())))
158+
//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes))
150159
//! }
151160
//!
152161
//! fn deserialize(
153162
//! _typ: &'frame ColumnType,
154163
//! v: Option<FrameSlice<'frame>>,
155164
//! ) -> 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()))
160167
//! }
161168
//! }
162169
//! ```
163-
// TODO: in the above module docstring, stop abusing ParseError once errors are refactored.
164170
165171
pub mod frame_slice;
166172
pub mod result;

0 commit comments

Comments
 (0)