Skip to main content

DataContext

Struct DataContext 

Source
pub struct DataContext {
    pub status: StatusContext,
    /* private fields */
}
Expand description

Bundle of every source a segment may read during a single render invocation. status is populated eagerly from the stdin payload; all other sources lazy-init on first access and cache their Result (including errors) for the lifetime of this context.

Accessors return Arc<Result<T, E>> so segments can hold the data across calls without tying lifetimes to &self. The Result shape preserves failure info for the plugin runtime’s tagged-map mirror (#{ kind: "ok"|"error", ... }) per plugin-api.md §ctx shape.

Fields§

§status: StatusContext

Eagerly-parsed stdin payload.

Implementations§

Source§

impl DataContext

Source

pub fn new(status: StatusContext) -> Self

Wrap a parsed StatusContext with lazy accessors for every other data source. cwd is None, so Self::git returns Ok(None) unless the caller switches to Self::with_cwd.

Source

pub fn with_cwd(status: StatusContext, cwd: Option<PathBuf>) -> Self

Construct with an explicit cwd that seeds gix discovery. The CLI passes std::env::current_dir().ok(); a fixture path pins discovery to a known repo.

Source

pub fn settings(&self) -> Arc<Result<Settings, SettingsError>>

~/.claude/settings.json + overlays.

Source

pub fn claude_json(&self) -> Arc<Result<ClaudeJson, ClaudeJsonError>>

~/.claude.json per-user state.

Source

pub fn jsonl(&self) -> Arc<Result<JsonlAggregate, JsonlError>>

Aggregated JSONL transcript state.

Invokes jsonl::aggregate_jsonl on first call and memoizes the Arc<Result<...>> for the process lifetime. Scans the project-root cascade once per process.

Source

pub fn usage(&self) -> Arc<Result<UsageData, UsageError>>

OAuth usage endpoint data (shared across rate-limit segments).

Runs the full fallback cascade on first call and memoizes the result for the process lifetime. See cascade::resolve_usage for the step order and docs/specs/data-fetching.md §OAuth fallback cascade for rationale. A fresh disk-cache hit short-circuits before any Keychain subprocess or HTTP call.

Source

pub fn credentials(&self) -> Arc<Result<Credentials, CredentialError>>

macOS Keychain / .credentials.json OAuth credentials.

Invokes credentials::resolve_credentials on first call and memoizes the Arc<Result<...>> for the process lifetime per docs/specs/credentials.md §Non-functional. On macOS this may trigger a security subprocess and a one-time Keychain access prompt; on Linux/Windows it’s a file-cascade read.

Source

pub fn preseed_usage( &self, result: Result<UsageData, UsageError>, ) -> Result<(), Arc<Result<UsageData, UsageError>>>

Pre-populate the usage result so Self::usage returns it without running the fallback cascade (which would otherwise touch the real Keychain, network, and JSONL transcripts). Mirrors OnceCell::set’s semantics: returns Err with the already-stored value if the cell was already populated by a prior ctx.usage() read.

Source

pub fn sessions(&self) -> Arc<Result<LiveSessions, SessionError>>

~/.claude/sessions/{pid}.json live process snapshot.

Source

pub fn git(&self) -> Arc<Result<Option<GitContext>, GitError>>

Git repo inspection via gix. Ok(None) means cwd is not inside a git repo; Ok(Some(_)) covers main checkouts, linked worktrees, and bare repos; Err is a gix failure.

Runs git::resolve_repo against Self::cwd on first call and memoizes the result. An unset cwd resolves to Ok(None). On the first Err, writes the cause to stderr with the linesmith: prefix so every consumer inherits the log without having to re-emit — the docs/specs/git-segments.md §Data dependency contract that each segment’s render path relies on.

Source

pub fn preseed_git( &self, result: Result<Option<GitContext>, GitError>, ) -> Result<(), Arc<Result<Option<GitContext>, GitError>>>

Pre-populate the git result so Self::git returns it without running gix::discover (which would otherwise touch the real filesystem). Mirrors OnceCell::set’s semantics: returns Err with the already-stored value if the cell was already populated by a prior ctx.git() read.

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.

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, 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.