Rust + Apache Flight: how to get around a library trait method defined on &self

100 Views Asked by At

The Apache Arrow Flight protocol's Rust implementation defines a FlightService trait with a static lifetime

pub trait FlightService: Send + Sync + 'static {
...

and a non-mutable handshake method:

    // Required methods
    fn handshake<'life0, 'async_trait>(
        &'life0 self,
        request: Request<Streaming<HandshakeRequest>>
    ) ...

This seems to put me in quite a bind -- by necessity the handshake method must authenticate users and respond with a bearer token, and it seems quite natural to want to track the assigned tokens, e.g. to authenticate other requests with tokens in their headers, and to look up the creation time of a token to see if it has expired. But, since the handshake method is on &self, I cannot put a mutable data structure in my implementation of the FlightService trait. Moreover, since the trait has static lifetime, I can't seem to declare my implementation to have a lifetime bound to a mutable reference to some other token store object -- although I'm quite new to Rust and could be misunderstanding the lifetime limitation.

So, I seem to be between a rock and a hard place, unable to do any sort of handshake operation that explicitly generate and stores session info on valid tokens. There must be some way that the library intends this handshake method to be useful -- how can I go about mutating something within it that has a wider scope? Or am I intended to be forced to make a token through some cryptographic hash of the user/timestamp that can be verified later?

0

There are 0 best solutions below