forked from projectmoon/tenebrous-dicebot
Avoid nested map when retrieving room info from db.
This commit is contained in:
parent
91cfc52e5b
commit
c8c38ac1d4
|
@ -237,12 +237,13 @@ impl Rooms {
|
||||||
pub fn get_room_info(&self, info: &RoomInfo) -> Result<Option<RoomInfo>, DataError> {
|
pub fn get_room_info(&self, info: &RoomInfo) -> Result<Option<RoomInfo>, DataError> {
|
||||||
let key = info.room_id.as_bytes();
|
let key = info.room_id.as_bytes();
|
||||||
|
|
||||||
//swap/flatten Result<Option<Result>> down into the return type.
|
let room_info: Option<RoomInfo> = self
|
||||||
self.roomid_roominfo
|
.roomid_roominfo
|
||||||
.get(key)
|
.get(key)?
|
||||||
.map(|bytes| bytes.map(|b| bincode::deserialize::<RoomInfo>(&b)))?
|
.map(|bytes| bincode::deserialize(&bytes))
|
||||||
.transpose()
|
.transpose()?;
|
||||||
.map_err(|e| e.into())
|
|
||||||
|
Ok(room_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_rooms_for_user(&self, username: &str) -> Result<HashSet<String>, DataError> {
|
pub fn get_rooms_for_user(&self, username: &str) -> Result<HashSet<String>, DataError> {
|
||||||
|
|
Loading…
Reference in New Issue