Skip to content

Commit

Permalink
fix: run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander committed Jul 19, 2024
1 parent ed281f5 commit 2c8938f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
49 changes: 37 additions & 12 deletions src/spec_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,59 @@ use std::fmt::{Debug, Display};
pub struct SpecErrorWrapper<E>(pub E);

pub trait SpecError<E>: Sized {
fn __sqlx_spec_error(&self) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static>;
fn __sqlx_spec_error(
&self,
) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static>;
}

impl<E> SpecError<E> for &&&&SpecErrorWrapper<E> where E: Error + Send + Sync + 'static {
fn __sqlx_spec_error(&self) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
impl<E> SpecError<E> for &&&&SpecErrorWrapper<E>
where
E: Error + Send + Sync + 'static,
{
fn __sqlx_spec_error(
&self,
) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
|e| Box::new(e.0)
}
}

impl<E> SpecError<E> for &&&SpecErrorWrapper<E> where E: Display {
fn __sqlx_spec_error(&self) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
impl<E> SpecError<E> for &&&SpecErrorWrapper<E>
where
E: Display,
{
fn __sqlx_spec_error(
&self,
) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
|e| e.0.to_string().into()
}
}

impl<E> SpecError<E> for &&SpecErrorWrapper<E> where E: Debug {
fn __sqlx_spec_error(&self) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
impl<E> SpecError<E> for &&SpecErrorWrapper<E>
where
E: Debug,
{
fn __sqlx_spec_error(
&self,
) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
|e| format!("{:?}", e.0).into()
}
}

impl<E> SpecError<E> for &SpecErrorWrapper<E> where E: Any {
fn __sqlx_spec_error(&self) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
impl<E> SpecError<E> for &SpecErrorWrapper<E>
where
E: Any,
{
fn __sqlx_spec_error(
&self,
) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
|_e| format!("unprintable error: {}", std::any::type_name::<E>()).into()
}
}

impl<E> SpecError<E> for SpecErrorWrapper<E> {
fn __sqlx_spec_error(&self) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
fn __sqlx_spec_error(
&self,
) -> fn(SpecErrorWrapper<E>) -> Box<dyn Error + Send + Sync + 'static> {
|_e| "unprintable error: (unprintable type)".into()
}
}
Expand All @@ -58,7 +82,8 @@ fn test_spec_error() {

struct AnyError;

let _e: Box<dyn Error + Send + Sync + 'static> = __spec_error!(std::io::Error::from(std::io::ErrorKind::Unsupported));
let _e: Box<dyn Error + Send + Sync + 'static> =
__spec_error!(std::io::Error::from(std::io::ErrorKind::Unsupported));

let _e: Box<dyn Error + Send + Sync + 'static> = __spec_error!("displayable error");

Expand All @@ -67,4 +92,4 @@ fn test_spec_error() {
let _e: Box<dyn Error + Send + Sync + 'static> = __spec_error!(AnyError);

let _e: Box<dyn Error + Send + Sync + 'static> = __spec_error!(&1i32);
}
}
8 changes: 4 additions & 4 deletions tests/postgres/derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,23 +772,23 @@ async fn test_enum_with_schema() -> anyhow::Result<()> {

#[cfg(feature = "macros")]
#[sqlx_macros::test]
async fn test_from_row_hygiene() -> anyhow::Result<()> {
async fn test_from_row_hygiene() -> anyhow::Result<()> {
// A field named `row` previously would shadow the `row` parameter of `FromRow::from_row()`:
// https://github.com/launchbadge/sqlx/issues/3344
#[derive(Debug, sqlx::FromRow)]
pub struct Foo {
pub row: i32,
pub bar: i32
pub bar: i32,
}

let mut conn = new::<Postgres>().await?;

let foo: Foo = sqlx::query_as("SELECT 1234 as row, 5678 as bar")
.fetch_one(&mut conn)
.await?;

assert_eq!(foo.row, 1234);
assert_eq!(foo.bar, 5678);

Ok(())
}
}

0 comments on commit 2c8938f

Please sign in to comment.