Skip to content

Commit b856e83

Browse files
committed
remove redundant stuff
1 parent cf99921 commit b856e83

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

rust/functora-tagged/src/lib.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::error::Error;
12
use std::fmt::{Debug, Display};
23
use std::marker::PhantomData;
34
use std::str::FromStr;
@@ -21,7 +22,6 @@ impl<Rep, Tag> Tagged<Rep, Tag> {
2122
{
2223
rep.refine().map(|rep| Tagged(rep, PhantomData))
2324
}
24-
2525
pub fn rep(&self) -> &Rep {
2626
&self.0
2727
}
@@ -123,15 +123,14 @@ mod diesel_impl {
123123
use diesel::deserialize::FromSql;
124124
use diesel::expression::AsExpression;
125125
use diesel::serialize::{Output, ToSql};
126-
use diesel::sql_types::{SingleValue, SqlType};
126+
use diesel::sql_types::SingleValue;
127127

128128
impl<Rep, Tag, ST> AsExpression<ST> for Tagged<Rep, Tag>
129129
where
130130
Rep: Clone + AsExpression<ST>,
131-
ST: SqlType + SingleValue,
131+
ST: SingleValue,
132132
{
133-
type Expression =
134-
<Rep as AsExpression<ST>>::Expression;
133+
type Expression = Rep::Expression;
135134
fn as_expression(self) -> Self::Expression {
136135
self.rep().clone().as_expression()
137136
}
@@ -140,10 +139,9 @@ mod diesel_impl {
140139
impl<Rep, Tag, ST> AsExpression<ST> for &Tagged<Rep, Tag>
141140
where
142141
Rep: Clone + AsExpression<ST>,
143-
ST: SqlType + SingleValue,
142+
ST: SingleValue,
144143
{
145-
type Expression =
146-
<Rep as AsExpression<ST>>::Expression;
144+
type Expression = Rep::Expression;
147145
fn as_expression(self) -> Self::Expression {
148146
self.rep().clone().as_expression()
149147
}
@@ -152,7 +150,6 @@ mod diesel_impl {
152150
impl<DB, Rep, Tag, ST> ToSql<ST, DB> for Tagged<Rep, Tag>
153151
where
154152
Rep: ToSql<ST, DB>,
155-
ST: SqlType + SingleValue,
156153
DB: Backend,
157154
Tag: Debug,
158155
{
@@ -167,37 +164,30 @@ mod diesel_impl {
167164
impl<DB, Rep, Tag, ST> FromSql<ST, DB> for Tagged<Rep, Tag>
168165
where
169166
Rep: FromSql<ST, DB> + Refine<Tag>,
170-
Rep::RefineError: Display,
171-
ST: SqlType + SingleValue,
167+
Rep::RefineError: 'static + Error + Send + Sync,
172168
DB: Backend,
173169
{
174170
fn from_sql(
175171
bytes: DB::RawValue<'_>,
176172
) -> diesel::deserialize::Result<Self> {
177173
let rep = Rep::from_sql(bytes)?;
178-
Tagged::new(rep).map_err(|e| {
179-
format!("Refine failed: {e}").into()
180-
})
174+
Ok(Tagged::new(rep).map_err(Box::new)?)
181175
}
182176
}
183177

184178
impl<Rep, Tag, ST, DB> Queryable<ST, DB>
185179
for Tagged<Rep, Tag>
186180
where
187181
Rep: Queryable<ST, DB> + Refine<Tag>,
188-
Rep::RefineError: Display,
189-
ST: SqlType + SingleValue,
182+
Rep::RefineError: 'static + Error + Send + Sync,
190183
DB: Backend,
191184
{
192-
type Row = <Rep as Queryable<ST, DB>>::Row;
185+
type Row = Rep::Row;
193186
fn build(
194187
row: Self::Row,
195188
) -> diesel::deserialize::Result<Self> {
196-
let rep =
197-
<Rep as Queryable<ST, DB>>::build(row)?;
198-
Tagged::new(rep).map_err(|e| {
199-
format!("Refine failed: {e}").into()
200-
})
189+
let rep = Queryable::build(row)?;
190+
Ok(Tagged::new(rep).map_err(Box::new)?)
201191
}
202192
}
203193
}

rust/functora-tagged/tests/integration.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ mod diesel_tests {
277277
let err = sql_query("SELECT id, email FROM users")
278278
.load::<UserRow>(&mut conn)
279279
.unwrap_err();
280-
assert!(err.to_string().contains("Refine failed"));
280+
assert!(
281+
err.to_string()
282+
.contains("Invalid UserId format")
283+
);
281284
}
282285

283286
#[test]

0 commit comments

Comments
 (0)