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

Split up Client and Server Callbacks with added type information. #35

Open
dequbed opened this issue Nov 28, 2023 · 0 comments
Open

Split up Client and Server Callbacks with added type information. #35

dequbed opened this issue Nov 28, 2023 · 0 comments
Milestone

Comments

@dequbed
Copy link
Owner

dequbed commented Nov 28, 2023

Splitting up the callback into a client & server variant makes sense as most users of this crate are either or, not both. This would also allow a better typing of the Callbacks as e.g. client callbacks don't need to implement validate, while server callbacks have to.

This would also allow a protocol implementation to require Callbacks with a given specialization. A server callback could thus statically type the additional data provided by SessionData and the type required for validate:

pub trait Specialization {
    /// Additional data provided by the protocol implementation in callbacks.
    type SessionData;

    /// Validation type returned on successful authentication
    type Validation;

    /// Error type returned specifically on failed authentication, can indicate type of failure.
    type ValidationError;
}

impl<S: Specialization> SessionData<S> {
    [...]
    fn protocol_session_data(&self) -> &S::SessionData { ... }
    [...]
}

pub trait ServerCallback<Specialization> {
    fn callback(&self, 
                session_data: &SessionData<Specialization::SessionData>,
                context: &Context,
                request: &mut Request
    ) -> Result<(), SessionError>;

    fn validate(&self, 
                session_data: &SessionData<Specialization>,
                context: &Context
    ) -> Result<Specialization::Validation, ValidationError<Specialization::ValidationError>>;
}
@dequbed dequbed added this to the v3.0.0 milestone Nov 28, 2023
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

No branches or pull requests

1 participant