pub struct Context {
pub variables: HashMap<String, ContextValue>,
pub globals: HashMap<String, ContextValue>,
pub buffer_ids: Vec<i64>,
pub cwd: Option<String>,
pub metadata: ContextMetadata,
}Expand description
Represents the RLM execution context.
This mirrors the Python implementation’s context dict and globals, providing a persistent state across operations.
§Examples
use rlm_rs::core::Context;
let mut ctx = Context::new();
ctx.set_variable("key".to_string(), "value".into());
assert!(ctx.get_variable("key").is_some());Fields§
§variables: HashMap<String, ContextValue>Context variables (key-value pairs for current session).
globals: HashMap<String, ContextValue>Global state dictionary (persisted across sessions).
buffer_ids: Vec<i64>Active buffer IDs in this context.
cwd: Option<String>Current working directory path.
metadata: ContextMetadataContext metadata.
Implementations§
Source§impl Context
impl Context
Sourcepub fn set_variable(&mut self, key: String, value: ContextValue)
pub fn set_variable(&mut self, key: String, value: ContextValue)
Sourcepub fn get_variable(&self, key: &str) -> Option<&ContextValue>
pub fn get_variable(&self, key: &str) -> Option<&ContextValue>
Sourcepub fn remove_variable(&mut self, key: &str) -> Option<ContextValue>
pub fn remove_variable(&mut self, key: &str) -> Option<ContextValue>
Sourcepub fn set_global(&mut self, key: String, value: ContextValue)
pub fn set_global(&mut self, key: String, value: ContextValue)
Sets a global variable (persisted across sessions).
§Arguments
key- Global variable name.value- Global variable value.
Sourcepub fn get_global(&self, key: &str) -> Option<&ContextValue>
pub fn get_global(&self, key: &str) -> Option<&ContextValue>
Sourcepub fn remove_global(&mut self, key: &str) -> Option<ContextValue>
pub fn remove_global(&mut self, key: &str) -> Option<ContextValue>
Sourcepub fn add_buffer(&mut self, buffer_id: i64)
pub fn add_buffer(&mut self, buffer_id: i64)
Sourcepub fn remove_buffer(&mut self, buffer_id: i64) -> bool
pub fn remove_buffer(&mut self, buffer_id: i64) -> bool
Sourcepub fn variable_count(&self) -> usize
pub fn variable_count(&self) -> usize
Returns the number of variables in the context.
Sourcepub fn global_count(&self) -> usize
pub fn global_count(&self) -> usize
Returns the number of globals in the context.
Sourcepub const fn buffer_count(&self) -> usize
pub const fn buffer_count(&self) -> usize
Returns the number of active buffers.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Context
impl<'de> Deserialize<'de> for Context
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Context
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more