Skip to main content

State

Struct State 

Source
pub struct State {
    pub schema: u32,
    pub machine: String,
    pub accounts: Vec<Account>,
    pub active: BTreeMap<String, String>,
    pub slot: BTreeMap<String, String>,
    pub discarded: Vec<String>,
    pub foreign: Vec<String>,
}

Fields§

§schema: u32§machine: String§accounts: Vec<Account>§active: BTreeMap<String, String>

Which account is signed in, per provider.

One string until schema 4, which stopped being true the moment a machine could have a Claude Code login and a Codex login at the same time. They are different programs reading different stores; neither signs the other out.

§slot: BTreeMap<String, String>

The credential slot each provider’s active was recorded for. One state file serves every slot a machine uses, and a tool’s own home variable changes which store is the live one, so a record made in one slot says nothing about another.

§discarded: Vec<String>

Parked items no account refers to any more. Listed in the same save that drops them and removed once deleted, so a delete that fails or is interrupted is retried.

§foreign: Vec<String>

Parked items an account here holds that this home never wrote down: logins pitboard repair found in the store and gave back. On macOS every PITBOARD_HOME shares the login keychain, so each may be another pitboard’s parked login, and letting one go unused must leave it where it is. Removed once nothing here holds it. Always empty where the vault is a directory inside this home, which nobody else parks in.

Implementations§

Source§

impl State

Source

pub fn active_for(&self, provider: ProviderId) -> Option<&str>

Which account is signed in for this provider, as pitboard last recorded it.

Source

pub fn set_active(&mut self, provider: ProviderId, label: Option<String>)

Source

pub fn slot_for(&self, provider: ProviderId) -> Option<&str>

The credential slot this provider’s active was recorded for.

Source

pub fn set_slot(&mut self, provider: ProviderId, slot: String)

Source

pub fn typed(&self, key: &Key) -> String

The account’s name as a command would take it here: bare for the tool a bare name means, unless another tool has an account of the same name, in which case a bare name would be refused as ambiguous and the tool is said.

What every message that tells somebody what to type uses, so the command it names is one that works on this machine.

Source

pub fn labels(&self, provider: ProviderId) -> Enrolled

Every label this tool has enrolled, for a message that would otherwise send someone to another command to find out.

Source

pub fn names(&self, service: &str) -> bool

Whether anything in the state refers to this vault item: an account holding it, or the list of ones waiting to be deleted.

Source

pub fn get(&self, key: &Key) -> Option<&Account>

The account under this key.

Callers that took a name from a person should go through crate::label::resolve first, which knows what to do when two tools share a label.

Source

pub fn by_uuid(&self, provider: ProviderId, uuid: &str) -> Option<&Account>

This tool’s account with this identity.

Source

pub fn owner_of_park(&self, uuid: &str) -> Option<&Account>

The account a parked item was written for.

A park’s name carries the account’s identity and not its tool, because names were fixed before there was a second tool and every item already on a machine is filed under one. The identities cannot collide in practice: Claude Code’s and Codex’s are UUIDs, and Gemini’s is Google’s numeric subject.

Source

pub fn park(&mut self, key: &Key, park: Park)

Hold park for the account, releasing whatever it replaces. A newer park does not use the one before it, so that one is let go rather than consumed.

Source

pub fn park_foreign(&mut self, key: &Key, park: Park)

Hold a park this home did not write, found in the store and given back. It is used like any other, and deleted only once it has been.

Source

pub fn is_foreign(&self, service: &str) -> bool

Whether an account here holds service without this home having written it.

Source

pub fn used_here(&mut self, service: &str)

Take service as this home’s own from now on, because this home has used it: a renewal presented its refresh token. Letting it go afterwards deletes it.

Source

pub fn discard(&mut self, service: &str)

Stop holding service because it has been used up, and list it for deletion whoever wrote it: it has been installed, a renewal has spent it, or it copies a login that is still signed in. Nothing can use it again, and for a tool whose park may never be a copy it must not stay beside the login it copies.

Source

pub fn release(&mut self, service: &str)

Stop holding service because nothing here wants it any more: a newer park replaced it, or its account was dropped. Listed for deletion only when this home wrote it. One repair gave back may be another pitboard’s parked login, which this one never used, and deleting it would end that account’s session for somebody who never ran the command that did it.

Source

pub fn references(&self, service: &str) -> bool

Source

pub fn used(&mut self, key: &Key, at: i64)

Record that the account under key was just put to use.

Source

pub fn upsert(&mut self, account: Account)

Add the account, or replace the one this tool already has under its label.

Source

pub fn relabel(&mut self, from: &Key, to: &str) -> Result<&Account>

Enroll the account under from as to instead, inside the same tool. Only the label changes: parked logins are named by account, not by label.

Source

pub fn remove(&mut self, key: &Key) -> Option<Account>

Drop the account, releasing its park.

Trait Implementations§

Source§

impl Clone for State

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for State

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for State

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for State

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for State

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnsafeUnpin for State

§

impl UnwindSafe for State

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.