Skip to content

Commit ac863a4

Browse files
patowenRalith
authored andcommitted
Box redb errors to avoid clippy::result_large_error warning
Errors from redb are 160 bytes long, which could potentially cause unexpected overhead.
1 parent f2b3f29 commit ac863a4

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

save/src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Save {
3737
init_meta_table(&db, &defaults)?;
3838
defaults
3939
}
40-
Err(e) => return Err(OpenError::Db(DbError(e.into()))),
40+
Err(e) => return Err(OpenError::Db(DbError(Box::new(e.into())))),
4141
}
4242
};
4343
Ok(Self { meta, db })
@@ -65,8 +65,8 @@ impl Save {
6565
}
6666
}
6767

68-
fn init_meta_table(db: &Database, value: &Meta) -> Result<(), redb::Error> {
69-
let tx = db.begin_write()?;
68+
fn init_meta_table(db: &Database, value: &Meta) -> Result<(), DbError> {
69+
let tx = db.begin_write().map_err(redb::Error::from)?;
7070
let mut meta = tx.open_table(META_TABLE)?;
7171
let mut cctx = cctx();
7272
let mut plain = Vec::new();
@@ -281,7 +281,7 @@ pub enum OpenError {
281281

282282
impl From<redb::Error> for OpenError {
283283
fn from(x: redb::Error) -> Self {
284-
OpenError::Db(DbError(x))
284+
OpenError::Db(DbError(Box::new(x)))
285285
}
286286
}
287287

@@ -297,34 +297,40 @@ pub enum GetError {
297297

298298
impl From<redb::Error> for GetError {
299299
fn from(x: redb::Error) -> Self {
300-
GetError::Db(DbError(x))
300+
GetError::Db(DbError(Box::new(x)))
301301
}
302302
}
303303

304304
impl From<redb::StorageError> for GetError {
305305
fn from(x: redb::StorageError) -> Self {
306-
GetError::Db(DbError(x.into()))
306+
GetError::Db(DbError(Box::new(x.into())))
307307
}
308308
}
309309

310310
#[derive(Debug, Error)]
311311
#[error(transparent)]
312-
pub struct DbError(#[from] redb::Error);
312+
pub struct DbError(Box<redb::Error>);
313+
314+
impl From<redb::Error> for DbError {
315+
fn from(x: redb::Error) -> Self {
316+
DbError(Box::new(x))
317+
}
318+
}
313319

314320
impl From<redb::StorageError> for DbError {
315321
fn from(x: redb::StorageError) -> Self {
316-
DbError(x.into())
322+
DbError(Box::new(x.into()))
317323
}
318324
}
319325

320326
impl From<redb::CommitError> for DbError {
321327
fn from(x: redb::CommitError) -> Self {
322-
DbError(x.into())
328+
DbError(Box::new(x.into()))
323329
}
324330
}
325331

326332
impl From<redb::TableError> for DbError {
327333
fn from(x: redb::TableError) -> Self {
328-
DbError(x.into())
334+
DbError(Box::new(x.into()))
329335
}
330336
}

0 commit comments

Comments
 (0)