From 677b1ccec9142c29e979aa5ddf8219a5c0d81f1f Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 7 Aug 2024 12:54:06 +0200 Subject: [PATCH] deser: fix doc tests by removing ParseError --- scylla-cql/src/types/deserialize/mod.rs | 60 ++++++++++++++----------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/scylla-cql/src/types/deserialize/mod.rs b/scylla-cql/src/types/deserialize/mod.rs index 2d8f0713e8..cc6ef7cfc1 100644 --- a/scylla-cql/src/types/deserialize/mod.rs +++ b/scylla-cql/src/types/deserialize/mod.rs @@ -46,30 +46,31 @@ //! //! ```rust //! # use scylla_cql::frame::response::result::ColumnType; -//! # use scylla_cql::frame::frame_errors::ParseError; //! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError}; //! # use scylla_cql::types::deserialize::value::DeserializeValue; +//! # use thiserror::Error; //! struct MyVec(Vec); +//! #[derive(Debug, Error)] +//! enum MyDeserError { +//! #[error("Expected bytes")] +//! ExpectedBytes, +//! #[error("Expected non-null")] +//! ExpectedNonNull, +//! } //! impl<'frame> DeserializeValue<'frame> for MyVec { //! fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> { //! if let ColumnType::Blob = typ { //! return Ok(()); //! } -//! Err(TypeCheckError::new( -//! ParseError::BadIncomingData("Expected bytes".to_owned()) -//! )) +//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes)) //! } //! //! fn deserialize( //! _typ: &'frame ColumnType, //! v: Option>, //! ) -> Result { -//! v.ok_or_else(|| { -//! DeserializationError::new( -//! ParseError::BadIncomingData("Expected non-null value".to_owned()) -//! ) -//! }) -//! .map(|v| Self(v.as_slice().to_vec())) +//! v.ok_or_else(|| DeserializationError::new(MyDeserError::ExpectedNonNull)) +//! .map(|v| Self(v.as_slice().to_vec())) //! } //! } //! ``` @@ -85,11 +86,18 @@ //! For example: //! //! ```rust -//! # use scylla_cql::frame::frame_errors::ParseError; //! # use scylla_cql::frame::response::result::ColumnType; //! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError}; //! # use scylla_cql::types::deserialize::value::DeserializeValue; +//! # use thiserror::Error; //! struct MySlice<'a>(&'a [u8]); +//! #[derive(Debug, Error)] +//! enum MyDeserError { +//! #[error("Expected bytes")] +//! ExpectedBytes, +//! #[error("Expected non-null")] +//! ExpectedNonNull, +//! } //! impl<'a, 'frame> DeserializeValue<'frame> for MySlice<'a> //! where //! 'frame: 'a, @@ -98,21 +106,15 @@ //! if let ColumnType::Blob = typ { //! return Ok(()); //! } -//! Err(TypeCheckError::new( -//! ParseError::BadIncomingData("Expected bytes".to_owned()) -//! )) +//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes)) //! } //! //! fn deserialize( //! _typ: &'frame ColumnType, //! v: Option>, //! ) -> Result { -//! v.ok_or_else(|| { -//! DeserializationError::new( -//! ParseError::BadIncomingData("Expected non-null value".to_owned()) -//! ) -//! }) -//! .map(|v| Self(v.as_slice())) +//! v.ok_or_else(|| DeserializationError::new(MyDeserError::ExpectedNonNull)) +//! .map(|v| Self(v.as_slice())) //! } //! } //! ``` @@ -135,32 +137,36 @@ //! Example: //! //! ```rust -//! # use scylla_cql::frame::frame_errors::ParseError; //! # use scylla_cql::frame::response::result::ColumnType; //! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError}; //! # use scylla_cql::types::deserialize::value::DeserializeValue; //! # use bytes::Bytes; +//! # use thiserror::Error; //! struct MyBytes(Bytes); +//! #[derive(Debug, Error)] +//! enum MyDeserError { +//! #[error("Expected bytes")] +//! ExpectedBytes, +//! #[error("Expected non-null")] +//! ExpectedNonNull, +//! } //! impl<'frame> DeserializeValue<'frame> for MyBytes { //! fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> { //! if let ColumnType::Blob = typ { //! return Ok(()); //! } -//! Err(TypeCheckError::new(ParseError::BadIncomingData("Expected bytes".to_owned()))) +//! Err(TypeCheckError::new(MyDeserError::ExpectedBytes)) //! } //! //! fn deserialize( //! _typ: &'frame ColumnType, //! v: Option>, //! ) -> Result { -//! v.ok_or_else(|| { -//! DeserializationError::new(ParseError::BadIncomingData("Expected non-null value".to_owned())) -//! }) -//! .map(|v| Self(v.to_bytes())) +//! v.ok_or_else(|| DeserializationError::new(MyDeserError::ExpectedNonNull)) +//! .map(|v| Self(v.to_bytes())) //! } //! } //! ``` -// TODO: in the above module docstring, stop abusing ParseError once errors are refactored. pub mod frame_slice; pub mod result;