Skip to content

Commit bf4f0e5

Browse files
committed
clippy updates
1 parent 4806b78 commit bf4f0e5

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/cookie_store.rs

Lines changed: 2 additions & 2 deletions
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,7 +32,7 @@ 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)?;
35+
let serialized = base64::decode(cookie_value)?;
3636
let session: Session = bincode::deserialize(&serialized)?;
3737
Ok(session.validate())
3838
}

src/memory_store.rs

Lines changed: 2 additions & 4 deletions
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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Session {
139139
pub fn id_from_cookie_value(string: &str) -> Result<String, base64::DecodeError> {
140140
let decoded = base64::decode(string)?;
141141
let hash = blake3::hash(&decoded);
142-
Ok(base64::encode(&hash.as_bytes()))
142+
Ok(base64::encode(hash.as_bytes()))
143143
}
144144

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

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

0 commit comments

Comments
 (0)