pub struct SessionContext { /* private fields */ }Expand description
Execution context for a shell session.
This tracks the current working directory, environment variables, and other runtime state information for a session.
Implementations§
Source§impl SessionContext
impl SessionContext
Sourcepub fn with_cwd(cwd: impl Into<PathBuf>) -> Self
pub fn with_cwd(cwd: impl Into<PathBuf>) -> Self
Create a session context with initial working directory.
Sourcepub fn set_env(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn set_env(&mut self, key: impl Into<String>, value: impl Into<String>)
Set an environment variable.
Sourcepub fn remove_env(&mut self, key: &str) -> Option<String>
pub fn remove_env(&mut self, key: &str) -> Option<String>
Remove an environment variable.
Sourcepub fn merge_env(&mut self, vars: HashMap<String, String>)
pub fn merge_env(&mut self, vars: HashMap<String, String>)
Merge environment variables from another map.
Sourcepub fn last_command(&self) -> Option<&str>
pub fn last_command(&self) -> Option<&str>
Get the last command executed.
Sourcepub fn last_exit_code(&self) -> Option<i32>
pub fn last_exit_code(&self) -> Option<i32>
Get the exit code of the last command.
Sourcepub fn execution_count(&self) -> u64
pub fn execution_count(&self) -> u64
Get the number of commands executed.
Sourcepub fn record_execution(
&mut self,
command: impl Into<String>,
exit_code: Option<i32>,
)
pub fn record_execution( &mut self, command: impl Into<String>, exit_code: Option<i32>, )
Record a command execution result.
Sourcepub fn last_succeeded(&self) -> bool
pub fn last_succeeded(&self) -> bool
Check if the last command succeeded.
Sourcepub fn last_failed(&self) -> bool
pub fn last_failed(&self) -> bool
Check if the last command failed.
Trait Implementations§
Source§impl Clone for SessionContext
impl Clone for SessionContext
Source§fn clone(&self) -> SessionContext
fn clone(&self) -> SessionContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SessionContext
impl Debug for SessionContext
Source§impl Default for SessionContext
impl Default for SessionContext
Source§fn default() -> SessionContext
fn default() -> SessionContext
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SessionContext
impl RefUnwindSafe for SessionContext
impl Send for SessionContext
impl Sync for SessionContext
impl Unpin for SessionContext
impl UnsafeUnpin for SessionContext
impl UnwindSafe for SessionContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.