Skip to main content

InMemoryGarrison

Struct InMemoryGarrison 

Source
pub struct InMemoryGarrison { /* private fields */ }
Expand description

Thread-safe in-memory Garrison implementation.

Stores all entries in memory using a VecDeque protected by an RwLock for concurrent access. All data is lost when the process terminates; use SqliteGarrison (feature sqlite) when persistence is required.

§Examples

use paladin_memory::garrison::InMemoryGarrison;
use paladin_core::platform::container::garrison::GarrisonConfig;
use paladin_ports::output::garrison_port::GarrisonPort;
use paladin_core::platform::container::garrison::{GarrisonEntry, ConversationRole};

#[tokio::main]
async fn main() {
    let config = GarrisonConfig::default();
    let garrison = InMemoryGarrison::new(config);

    // Store an entry
    let entry = GarrisonEntry::new(
        ConversationRole::User,
        "Hello!".to_string()
    );
    garrison.remember(entry).await.unwrap();

    // Retrieve it
    let recent = garrison.recall_recent(10).await.unwrap();
    assert_eq!(recent.len(), 1);
}

Implementations§

Source§

impl InMemoryGarrison

Source

pub fn new(config: GarrisonConfig) -> Self

Creates a new in-memory Garrison with the given configuration.

§Arguments
  • config - Configuration for windowing and eviction behavior
§Examples
use paladin_memory::garrison::InMemoryGarrison;
use paladin_core::platform::container::garrison::GarrisonConfig;

let config = GarrisonConfig::new(100, Some(4000));
let garrison = InMemoryGarrison::new(config);

Trait Implementations§

Source§

impl GarrisonPort for InMemoryGarrison

Source§

fn remember<'life0, 'async_trait>( &'life0 self, entry: GarrisonEntry, ) -> Pin<Box<dyn Future<Output = Result<(), GarrisonError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores a new entry in the Garrison Read more
Source§

fn recall_recent<'life0, 'async_trait>( &'life0 self, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<GarrisonEntry>, GarrisonError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieves the N most recent entries Read more
Source§

fn search<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<GarrisonEntry>, GarrisonError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Searches for entries matching a text query Read more
Source§

fn forget_all<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), GarrisonError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clears all entries from the Garrison Read more
Source§

fn stats<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<GarrisonStats, GarrisonError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns statistics about the current state of the Garrison Read more

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.