Event

Enum Event 

Source
pub enum Event {
    Insert(EventData),
    Remove(EventData),
    Clear,
}
Expand description

Represents different types of cache events.

Events are sent through a channel when cache operations occur, allowing external observers to react to cache changes.

§Examples

use quickleaf::{Event, EventData};
use quickleaf::Cache;
use quickleaf::valu3::traits::ToValueBehavior;
use std::sync::mpsc::channel;

let (tx, rx) = channel();
let mut cache = Cache::with_sender(5, tx);

// Insert an item
cache.insert("user_123", "session_data");

// Receive the insert event
if let Ok(event) = rx.try_recv() {
    match event {
        Event::Insert(data) => {
            println!("Inserted: {} = {}", data.key, data.value);
            assert_eq!(data.key, "user_123");
        },
        Event::Remove(data) => {
            println!("Removed: {} = {}", data.key, data.value);
        },
        Event::Clear => {
            println!("Cache cleared");
        },
    }
}

Variants§

§

Insert(EventData)

An item was inserted into the cache.

§Examples

use quickleaf::{Event, EventData};
use quickleaf::valu3::traits::ToValueBehavior;

let event = Event::insert("key".to_string(), "value".to_value());
match event {
    Event::Insert(data) => {
        assert_eq!(data.key, "key");
        assert_eq!(data.value, "value".to_value());
    },
    _ => panic!("Expected insert event"),
}
§

Remove(EventData)

An item was removed from the cache.

§Examples

use quickleaf::{Event, EventData};
use quickleaf::valu3::traits::ToValueBehavior;

let event = Event::remove("key".to_string(), "value".to_value());
match event {
    Event::Remove(data) => {
        assert_eq!(data.key, "key");
        assert_eq!(data.value, "value".to_value());
    },
    _ => panic!("Expected remove event"),
}
§

Clear

The entire cache was cleared.

§Examples

use quickleaf::Event;

let event = Event::clear();
match event {
    Event::Clear => println!("Cache was cleared"),
    _ => panic!("Expected clear event"),
}

Implementations§

Source§

impl Event

Source

pub fn insert(key: String, value: Value) -> Self

Creates a new insert event.

§Examples
use quickleaf::Event;
use quickleaf::valu3::traits::ToValueBehavior;

let event = Event::insert("user_session".to_string(), "active".to_value());

match event {
    Event::Insert(data) => {
        assert_eq!(data.key, "user_session");
        assert_eq!(data.value, "active".to_value());
    },
    _ => panic!("Expected insert event"),
}
Source

pub fn remove(key: String, value: Value) -> Self

Creates a new remove event.

§Examples
use quickleaf::Event;
use quickleaf::valu3::traits::ToValueBehavior;

let event = Event::remove("expired_key".to_string(), "old_data".to_value());

match event {
    Event::Remove(data) => {
        assert_eq!(data.key, "expired_key");
        assert_eq!(data.value, "old_data".to_value());
    },
    _ => panic!("Expected remove event"),
}
Source

pub fn clear() -> Self

Creates a new clear event.

§Examples
use quickleaf::Event;

let event = Event::clear();

match event {
    Event::Clear => println!("Cache was cleared"),
    _ => panic!("Expected clear event"),
}

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Event

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Event

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.