Skip to main content

CommandCapture

Struct CommandCapture 

Source
pub struct CommandCapture;
Expand description

Command capture with durable NDJSON append.

Provides static methods for writing NDJSON lines to session files with fsync after each write for crash safety. Each method opens the file, writes a single NDJSON line, syncs to disk, and closes.

§File Format

{"type":"header","version":2,"id":"...","name":"...","shell":"bash",...}
{"type":"command","index":0,"command":"echo hello","cwd":"/home",...}
{"type":"command","index":1,"command":"ls -la","cwd":"/home",...}
{"type":"footer","ended_at":1234567890.123,"command_count":2,"status":"completed"}

Implementations§

Source§

impl CommandCapture

Source

pub fn write_header(path: &Path, header: &SessionHeader) -> Result<()>

Write the session header as the first line of the NDJSON file.

Creates the file (or truncates if exists) and writes the header line followed by sync_all() for durability. Sets restrictive permissions (0o600) to prevent other users from reading session data.

§Errors

Returns an error if file creation or writing fails.

Source

pub fn append_command(path: &Path, command: &Command) -> Result<()>

Append a command as an NDJSON line to the session file.

Opens the file in append mode and writes a single command line followed by sync_all() for durability.

§Errors

Returns an error if file opening or writing fails.

Write the session footer as the last line of the NDJSON file.

Opens the file in append mode and writes the footer line followed by sync_all() for durability.

§Errors

Returns an error if file opening or writing fails.

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