relay_server/services/buffer/envelope_stack/
memory.rsuse std::convert::Infallible;
use chrono::{DateTime, Utc};
use crate::Envelope;
use super::EnvelopeStack;
#[derive(Debug)]
pub struct MemoryEnvelopeStack(#[allow(clippy::vec_box)] Vec<Box<Envelope>>);
impl MemoryEnvelopeStack {
pub fn new() -> Self {
Self(vec![])
}
}
impl EnvelopeStack for MemoryEnvelopeStack {
type Error = Infallible;
async fn push(&mut self, envelope: Box<Envelope>) -> Result<(), Self::Error> {
self.0.push(envelope);
Ok(())
}
async fn peek(&mut self) -> Result<Option<DateTime<Utc>>, Self::Error> {
Ok(self.0.last().map(|e| e.received_at()))
}
async fn pop(&mut self) -> Result<Option<Box<Envelope>>, Self::Error> {
Ok(self.0.pop())
}
async fn flush(self) {}
}