rustybook-messenger 0.2.1

Messenger client for Rustybook
Documentation
use super::{
    Cache,
    update::CacheUpdate,
};
use crate::client::models::Message;
use crate::gateway::events::{
    Event,
    EventError,
    MessageEvent,
    PresenceEvent,
    TypingEvent,
};

impl CacheUpdate for MessageEvent {
    type Output = Message;

    fn update(&mut self, cache: &Cache) -> Option<Self::Output> {
        let mapped = Message::from(&*self);
        cache.push_message(mapped.clone());
        Some(mapped)
    }
}

impl CacheUpdate for TypingEvent {
    type Output = ();

    fn update(&mut self, _cache: &Cache) -> Option<Self::Output> {
        None
    }
}

impl CacheUpdate for PresenceEvent {
    type Output = ();

    fn update(&mut self, _cache: &Cache) -> Option<Self::Output> {
        None
    }
}

impl CacheUpdate for EventError {
    type Output = ();

    fn update(&mut self, _cache: &Cache) -> Option<Self::Output> {
        None
    }
}

impl CacheUpdate for Event {
    type Output = ();

    fn update(&mut self, cache: &Cache) -> Option<Self::Output> {
        match self {
            Event::Message(event) => {
                event.update(cache);
                Some(())
            }
            _ => None,
        }
    }
}