Struct IdentityManager

Source
pub struct IdentityManager { /* private fields */ }

Implementations§

Source§

impl IdentityManager

Source

pub fn new( store: Arc<CacheStore>, bus: Arc<ObserverBus>, clock: Arc<dyn Clock>, ) -> Self

Source

pub fn current_user(&self) -> User

Source

pub fn current_user_scope(&self) -> String

The user scope used by the local cache layer ONLY — app_user_id if identified, else rovenue_id. So a logged-in user’s cached entitlements live in their own namespace and flip on identify/log_out.

NEVER send this on the wire. Every server endpoint resolves the inbound identity header/field as a rovenueId (the app_user_id is a server-side label attached via POST /v1/identify). Use rovenue_id as the network identity instead; sending the app_user_id routes requests to an orphan subscriber row.

Source

pub fn set_app_user_id(&self, app_user_id: String) -> RovenueResult<bool>

Optimistic-local identity set. Persists the app_user_id with synced: false (a follow-up POST /v1/identify flips it to synced via [mark_synced]). Emits IdentityChanged only when the value actually changes. Returns true when the identity changed, false when it was already this app_user_id (no write, no emit).

Source

pub fn mark_synced(&self, sent: &PendingBind) -> RovenueResult<()>

Marks the persisted identity row as synced (server POST /v1/identify succeeded) — but ONLY when the row still carries the pair that was actually sent. This guards two races: identify(A)’s slow POST completing after identify(B) overwrote the row (stamping B synced though only A was sent), and an old device’s POST completing after log_out + identify(A) paired A with a new device (stamping the new pair synced though only the old one was sent). Runs under the identity lock so it cannot write back a row log_out just replaced. Does not touch the in-memory User or emit.

Source

pub fn pending_bind(&self) -> Option<PendingBind>

The pending identify bind, read as one pair from the persisted row under the identity lock — Some only while the row has synced == false, carries an app_user_id, and still matches the in-memory identity. A row the current identity no longer matches (the identity changed since it was written) yields None: the bind is skipped rather than sent for a device that has moved on.

Source

pub fn pending_app_user_id(&self) -> Option<String>

Returns the app_user_id awaiting server sync — the app_user_id of pending_bind.

Source

pub fn rovenue_id(&self) -> String

The current anonymous device id.

Source

pub fn log_out(&self) -> RovenueResult<()>

Resets identity to a fresh anonymous user: mints a new rovenue_id, drops any app_user_id, persists, and notifies observers. Callers that hold scope-bound caches must clear them after this returns.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more