use crate::context::pressure::PressureAction;
use serde::{Deserialize, Serialize};
pub mod handle;
pub mod memory;
pub use handle::{
plan_eviction, plan_spool, EvictionOp, EvictionPlan, Handle, HandleId, HandleKind, HandleTable,
Residency, SpoolDecision,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MemoryTierHint {
Durable,
Semantic,
}
impl MemoryTierHint {
pub fn label(self) -> &'static str {
match self {
Self::Durable => "durable",
Self::Semantic => "semantic",
}
}
}
pub fn tier_hint_for_compress(action: PressureAction) -> MemoryTierHint {
match action {
PressureAction::ContextCollapse | PressureAction::AutoCompact => MemoryTierHint::Semantic,
_ => MemoryTierHint::Durable,
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PageInEntry {
pub content: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tokens: Option<u32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub key: Option<String>,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub pinned: bool,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tier_hint_maps_auto_compact_to_semantic() {
assert_eq!(
tier_hint_for_compress(PressureAction::AutoCompact),
MemoryTierHint::Semantic
);
assert_eq!(
tier_hint_for_compress(PressureAction::SnipCompact),
MemoryTierHint::Durable
);
}
}