Skip to content

Commit a4de37f

Browse files
committed
incorporate clippy changes from main
# Conflicts: # src/cookie_store.rs
1 parent fc710b2 commit a4de37f

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/cookie_store.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{async_trait, Result, Session, SessionStore};
1919
/// CookieStore, and noop. Destroying a session must be done at the
2020
/// cookie setting level, which is outside of the scope of this crate.
2121
22-
#[derive(Debug, Clone, Copy)]
22+
#[derive(Default, Debug, Clone, Copy)]
2323
pub struct CookieStore;
2424

2525
impl CookieStore {
@@ -32,8 +32,8 @@ impl CookieStore {
3232
#[async_trait]
3333
impl SessionStore for CookieStore {
3434
async fn load_session(&self, cookie_value: String) -> Result<Option<Session>> {
35-
let serialized = base64::decode(&cookie_value)?;
36-
let session: Session = bincode::deserialize(&serialized[..])?;
35+
let serialized = base64::decode(cookie_value)?;
36+
let session: Session = bincode::deserialize(&serialized)?;
3737
Ok(session.validate())
3838
}
3939

src/memory_store.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::{collections::HashMap, sync::Arc};
2626
/// - [async-redis-session](https://crates.io/crates/async-redis-session)
2727
/// - [async-mongodb-session](https://crates.io/crates/async-mongodb-session)
2828
///
29-
#[derive(Debug, Clone)]
29+
#[derive(Default, Debug, Clone)]
3030
pub struct MemoryStore {
3131
inner: Arc<RwLock<HashMap<String, Session>>>,
3232
}
@@ -72,9 +72,7 @@ impl SessionStore for MemoryStore {
7272
impl MemoryStore {
7373
/// Create a new instance of MemoryStore
7474
pub fn new() -> Self {
75-
Self {
76-
inner: Arc::new(RwLock::new(HashMap::new())),
77-
}
75+
Self::default()
7876
}
7977

8078
/// Performs session cleanup. This should be run on an

src/session.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl Session {
140140
pub fn id_from_cookie_value(string: &str) -> Result<String, base64::DecodeError> {
141141
let decoded = base64::decode(string)?;
142142
let hash = blake3::hash(&decoded);
143-
Ok(base64::encode(&hash.as_bytes()))
143+
Ok(base64::encode(hash.as_bytes()))
144144
}
145145

146146
/// mark this session for destruction. the actual session record
@@ -297,8 +297,21 @@ impl Session {
297297
/// assert_eq!(session.len(), 1);
298298
/// ```
299299
pub fn len(&self) -> usize {
300-
let data = self.data.read().unwrap();
301-
data.len()
300+
self.data.read().unwrap().len()
301+
}
302+
303+
/// returns a boolean indicating whether there are zero elements in the session hashmap
304+
///
305+
/// # Example
306+
///
307+
/// ```rust
308+
/// # use async_session::Session;
309+
/// let mut session = Session::new();
310+
/// assert!(session.is_empty());
311+
/// session.insert("key", 0);
312+
/// assert!(!session.is_empty());
313+
pub fn is_empty(&self) -> bool {
314+
return self.data.read().unwrap().is_empty();
302315
}
303316

304317
/// Generates a new id and cookie for this session

0 commit comments

Comments
 (0)