navy-nvim-rs 0.0.20

A library for writing neovim rpc clients
//! Handling redraw notifications received from neovim
//!
//! The core of a UI client is defining and implementing the
//! [`Handler`].
use std::io;

use crate::rpc::redraw::RedrawNotification;

/// The central functionality of a UI client.
pub trait Handler: Send + Sync + Clone + 'static {
    /// Handling a `redraw` notification on the handler loop without allocating
    /// an owned `String` or `Vec<Value>` for the notification payload.
    fn handle_redraw(&self, _redraw: RedrawNotification<'_>) -> io::Result<()> {
        Ok(())
    }

    fn handle_unknown_notify(_name: &str) {}

    fn handle_unknown_request(_msgid: u32, _name: &str) {}
}

/// The dummy handler ignores redraw notifications.
///
/// It can be used if a client only wants to send requests to Neovim and get
/// responses.
#[derive(Clone)]
pub struct Dummy;

impl Handler for Dummy {}