Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overhaul this crate's interface #57

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jbr
Copy link
Member

@jbr jbr commented Feb 17, 2023

  • Remove interior mutability inside of Session
  • store values in memory as serde_json::Values instead of strings
  • add Session::take_value
  • use dashmap in MemoryStore
  • add an Error associated type instead of using anyhow
  • remove reexported but unused libraries
  • make memory-store and cookie-store cargo features (currently enabled by default)
  • upgrade base64

I plan to leave this open for a few days and merge if there are no concerns

@jbr jbr force-pushed the overhaul-session-and-session-store branch 5 times, most recently from 7d22fff to 3636ef2 Compare February 17, 2023 02:44
* Remove interior mutability inside of Session
* store values in memory as serde_json::Values instead of strings
* add Session::take_value
* use dashmap in MemoryStore
* add an Error associated type instead of using anyhow
* remove reexported but unused libraries
* make memory-store and cookie-store cargo features (currently enabled by default)
* updates base64
* adds Session::from_parts and Session::data
@MOZGIII
Copy link

MOZGIII commented Feb 17, 2023

Consider extracting the memory-store and cookie-store into separate crates. They seem to be fairly standalone to allow it, and this way you can control the dependencies more explicitly.


/// An async session backend.
#[async_trait]
pub trait SessionStore {
/// The [`std::error::Error`] type that this store returns
type Error: std::error::Error;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

@maxcountryman
Copy link
Contributor

It would be nice if v4 could also address the issue of not being able to clone without blowing away the session value. axum-sessions works around this by using RWLock but this interface is far from ideal. If libraries had some escape hatch to clone without destroying the value that would be helpful.

@jbr jbr force-pushed the overhaul-session-and-session-store branch from af484fd to 493fa04 Compare March 30, 2023 02:19
@@ -63,19 +63,6 @@ pub struct Session {
destroy: bool,
}

impl Clone for Session {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! 🙇‍♂️

@maxcountryman
Copy link
Contributor

@jbr do you have a sense for when this might be merged and released?

Comment on lines 249 to 255
pub fn get<T: serde::de::DeserializeOwned>(&self, key: &str) -> Option<T> {
let data = self.data.read().unwrap();
let string = data.get(key)?;
serde_json::from_str(string).ok()
self.get_value(key)
.map(serde_json::from_value)
.transpose()
.ok()
.flatten()
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this should return a Result<Option<T>, Err> instead of just an option. i'm running into an issue where i'm trying to get a value that does exist in the session store, but there must be some error in deserialization because it returns None.

IMO, there should be three cases:

  • Ok(Some(val)): That key is associated with this value
  • Ok(None): That key doesn't have any value in the session store
  • Err(...): there was an error fetching/deserializing the value stored in that key

thoughts? I'm not a rust expert by any means, so feel free to correct me if i'm missing something.
(see this issue i opened in another repo for reference)

@kaiserbh
Copy link

kaiserbh commented Aug 9, 2023

Hi @jbr I hope you been well, I was just wondering if this is ready to be merged or is there anything that's blocking this from getting merged?

@maxcountryman
Copy link
Contributor

If I can donate my time to help with the maintenance of this crate I'd be more than happy to. Let me know if that would be helpful, @jbr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants