Skip to content

Instantly share code, notes, and snippets.

@themasch
Created October 6, 2017 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themasch/49279c848bbf7d1ccbd6873b5a9fdf5f to your computer and use it in GitHub Desktop.
Save themasch/49279c848bbf7d1ccbd6873b5a9fdf5f to your computer and use it in GitHub Desktop.
error[E0277]: the trait bound `errors::Error: storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<std::sync::PoisonError<std::sync::MutexGuard<'_, rocksdb::DB>>>` is not satisfied
--> src/storage.rs:28:15
|
28 | match self.db.lock()?.get(format!("user:{}", username).as_bytes()) {
| ^^^^^^^^^^^^^^^ the trait `storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<std::sync::PoisonError<std::sync::MutexGuard<'_, rocksdb::DB>>>` is not implemented for `errors::Error`
|
= help: the following implementations were found:
<errors::Error as storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<std::num::ParseIntError>>
<errors::Error as storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<std::io::Error>>
<errors::Error as storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<chrono::ParseError>>
<errors::Error as storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<rocksdb::Error>>
and 4 others
= note: required by `storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From::from`
error[E0277]: the trait bound `errors::Error: storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<std::sync::PoisonError<std::sync::MutexGuard<'_, rocksdb::DB>>>` is not satisfied
--> src/storage.rs:44:33
|
44 | Err(err) => Err(err.into())
| ^^^^ the trait `storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<std::sync::PoisonError<std::sync::MutexGuard<'_, rocksdb::DB>>>` is not implemented for `errors::Error`
|
= help: the following implementations were found:
<errors::Error as storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<std::num::ParseIntError>>
<errors::Error as storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<std::io::Error>>
<errors::Error as storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<chrono::ParseError>>
<errors::Error as storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::From<rocksdb::Error>>
and 4 others
= note: required because of the requirements on the impl of `storage::_IMPL_DESERIALIZE_FOR_User::_serde::export::Into<errors::Error>` for `std::sync::PoisonError<std::sync::MutexGuard<'_, rocksdb::DB>>`
error: aborting due to 2 previous errors
error: Could not compile `quotevote`.
To learn more, run the command again with --verbose.
Process finished with exit code 101
use errors::*;
use rocksdb::DB;
use rocksdb::Options;
use std::path::Path;
use serde_json::{from_str, to_string};
use std::sync::Mutex;
#[derive(Serialize, Deserialize, Debug)]
pub struct User {
username: String,
password: String
}
pub struct Storage {
db: Mutex<DB>
}
impl Storage {
pub fn new(path: &Path) -> Result<Storage> {
let mut options = Options::default();
options.create_if_missing(true);
let db = DB::open(&options, path)?;
Ok(Storage { db: Mutex::new(db) })
}
pub fn find_user<'a>(&self, username: &'a str) -> Result<Option<User>> {
match self.db.lock()?.get(format!("user:{}", username).as_bytes()) {
Ok(Some(result)) => match result.to_utf8() {
Some(userdata) => Ok(Some(from_str(userdata)?)),
None => Ok(None)
},
Ok(None) => Ok(None),
Err(err) => Err(err.into())
}
}
pub fn store_user(&mut self, user: &User) -> Result<()> {
match self.db.lock() {
Ok(db) => Ok(db.put(
format!("user:{}", user.username).as_bytes(),
to_string(user)?.as_bytes()
)?),
Err(err) => Err(err.into())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment