Skip to content

Commit 6c0a7c3

Browse files
committed
Store DbError in a Box
This shrinks the error enums by an order of magnitude - 376 bytes to 32/34.
1 parent de8c882 commit 6c0a7c3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/error.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ impl DbErrorNew for DbError {
6767

6868
fn new_connect<T>(fields: Vec<(u8, String)>) -> result::Result<T, ConnectError> {
6969
match DbError::new_raw(fields) {
70-
Ok(err) => Err(ConnectError::DbError(err)),
70+
Ok(err) => Err(ConnectError::DbError(Box::new(err))),
7171
Err(()) => Err(ConnectError::IoError(::bad_response())),
7272
}
7373
}
7474

7575
fn new<T>(fields: Vec<(u8, String)>) -> Result<T> {
7676
match DbError::new_raw(fields) {
77-
Ok(err) => Err(Error::DbError(err)),
77+
Ok(err) => Err(Error::DbError(Box::new(err))),
7878
Err(()) => Err(Error::IoError(::bad_response())),
7979
}
8080
}
@@ -198,7 +198,7 @@ pub enum ConnectError {
198198
/// The URL was missing a user.
199199
MissingUser,
200200
/// An error from the Postgres server itself.
201-
DbError(DbError),
201+
DbError(Box<DbError>),
202202
/// A password was required but not provided in the URL.
203203
MissingPassword,
204204
/// The Postgres server requested an authentication method not supported
@@ -244,7 +244,7 @@ impl error::Error for ConnectError {
244244
fn cause(&self) -> Option<&error::Error> {
245245
match *self {
246246
ConnectError::BadConnectParams(ref err) => Some(&**err),
247-
ConnectError::DbError(ref err) => Some(err),
247+
ConnectError::DbError(ref err) => Some(&**err),
248248
ConnectError::SslError(ref err) => Some(&**err),
249249
ConnectError::IoError(ref err) => Some(err),
250250
_ => None
@@ -260,7 +260,7 @@ impl From<io::Error> for ConnectError {
260260

261261
impl From<DbError> for ConnectError {
262262
fn from(err: DbError) -> ConnectError {
263-
ConnectError::DbError(err)
263+
ConnectError::DbError(Box::new(err))
264264
}
265265
}
266266

@@ -288,7 +288,7 @@ pub enum ErrorPosition {
288288
#[derive(Debug)]
289289
pub enum Error {
290290
/// An error reported by the Postgres server.
291-
DbError(DbError),
291+
DbError(Box<DbError>),
292292
/// An error communicating with the Postgres server.
293293
IoError(io::Error),
294294
/// An attempt was made to convert between incompatible Rust and Postgres
@@ -326,7 +326,7 @@ impl error::Error for Error {
326326

327327
fn cause(&self) -> Option<&error::Error> {
328328
match *self {
329-
Error::DbError(ref err) => Some(err),
329+
Error::DbError(ref err) => Some(&**err),
330330
Error::IoError(ref err) => Some(err),
331331
Error::Conversion(ref err) => Some(&**err),
332332
_ => None
@@ -336,7 +336,7 @@ impl error::Error for Error {
336336

337337
impl From<DbError> for Error {
338338
fn from(err: DbError) -> Error {
339-
Error::DbError(err)
339+
Error::DbError(Box::new(err))
340340
}
341341
}
342342

0 commit comments

Comments
 (0)