The compiler complains that type annotations are needed. I was able to fix it by creating an unused variable with type parameters, commented out in the code snippet below. This feels like a weird workaround though, is there some way to add type parameters without needing to do this? It just seems like rust should know the type of key because Map is a defined type.
type Map = Arc<DashMap<[u8; 32], Session>>;
pub struct SessionManager {
map: Map,
db_wtx: WriteTx,
db_rtx: ReadTx,
}
impl SessionManager{
pub fn logout(&self, token: &str) {
if let Ok(decoded_vec) = base64::decode(token) {
if let Ok(key) = decoded_vec.try_into() {
//let _typed_key: [u8; 32] = key;
self.map.remove(&key);
}
}
}
}
Error msg:
error[E0282]: type annotations needed
--> src/login_handler.rs:244:14
|
244 | if let Ok(key) = decoded_vec.try_into() {
| ^^^ ---------------------- this method call resolves to `Result<T, <Self as TryInto<T>>::Error>`
| |
| cannot infer type
edit: for clarity I'm using the dashmap crate, which tries to mimic the api of std::hashmap closely while allowing multithreaded access.