mirror of
https://github.com/OMGeeky/google_bigquery_v2.git
synced 2026-01-05 11:10:42 +01:00
improve errors in map_err with or without data
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "google_bigquery_v2"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -45,7 +45,7 @@ pub enum QueryResultType<Table> {
|
||||
WithoutRowData(Result<()>),
|
||||
}
|
||||
|
||||
impl<T> QueryResultType<T> {
|
||||
impl<T: Debug> QueryResultType<T> {
|
||||
pub fn map_err_with_data(self, message: impl Into<String>) -> Result<Vec<T>> {
|
||||
match self {
|
||||
QueryResultType::WithRowData(data) => Ok(data),
|
||||
@@ -57,26 +57,19 @@ impl<T> QueryResultType<T> {
|
||||
pub fn map_err_without_data(self, message: impl Into<String>) -> Result<()> {
|
||||
match self {
|
||||
QueryResultType::WithoutRowData(result) => result,
|
||||
QueryResultType::WithRowData(_) => {
|
||||
Err(format!("map_err_without_data message:{}", message.into()).into())
|
||||
}
|
||||
QueryResultType::WithRowData(data) => Err(format!(
|
||||
"map_err_without_data message:'{}' data: {:?}",
|
||||
message.into(),
|
||||
data
|
||||
)
|
||||
.into()),
|
||||
}
|
||||
}
|
||||
pub fn expect_with_data(self, message: impl Into<String>) -> Vec<T> {
|
||||
match self {
|
||||
QueryResultType::WithRowData(data) => data,
|
||||
QueryResultType::WithoutRowData(_) => {
|
||||
panic!("expect_with_data message:{}", message.into())
|
||||
}
|
||||
}
|
||||
self.map_err_with_data(message).unwrap()
|
||||
}
|
||||
pub fn expect_without_data(self, message: impl Into<String>) -> Result<()> {
|
||||
match self {
|
||||
QueryResultType::WithoutRowData(result) => result,
|
||||
QueryResultType::WithRowData(_) => {
|
||||
panic!("expect_without_data message:{}", message.into())
|
||||
}
|
||||
}
|
||||
pub fn expect_without_data(self, message: impl Into<String>) -> () {
|
||||
self.map_err_without_data(message).unwrap()
|
||||
}
|
||||
pub fn is_with_row_data(&self) -> bool {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user