Struct Session

Source
pub struct Session { /* private fields */ }
Expand description

The current Neovim session

Used to send and receive messages to the Neovim session

Implementations§

Source§

impl Session

Source

pub fn from_tcp(addr: &str) -> Result<Session, Error>

Create a session using a TCP socket

This allows RPC communication with a Neovim instance started with

nvim --listen 127.0.0.1:6666

The current Neovim server can be found using

:echo v:servername
§Example
use rsnvim::session::Session;

let mut session = match Session::from_tcp("127.0.0.1:6666") {
    Ok(session) => session,
    Err(error) => panic!("Couldn't open TCP socket: {}", error)
};
Source

pub fn from_parent() -> Result<Session, Error>

Create a Neovim connection using stdin/stdout

This allows RPC communication with the Neovim instance that spawned this process.

§Example
use rsnvim::api::Nvim;

let mut nvim = match Nvim::from_parent() {
    Ok(nvim) => nvim,
    Err(error) => panic!("Couldn't connect to parent session: {}", error)
};
Source

pub fn from_unix(path: &str) -> Result<Session, Error>

Create a session using a Unix socket

This allows RPC communication with any Neovim instance as it creates a default RPC socket on startup.

The current Neovim server can be found using

:echo v:servername
§Example
use rsnvim::session::Session;

let mut session = match Session::from_unix("/run/user/1000/nvim.XXXXX.X") {
    Ok(session) => session,
    Err(error) => panic!("Couldn't open UNIX socket: {}", error)
};
Source

pub fn start_event_loop( &mut self, request_handler: Option<Box<dyn RequestHandler + Send>>, notification_handler: Option<Box<dyn NotificationHandler + Send>>, )

Begin the RPC event loop

This function must be called before RPC messages can be sent as it handles the return values, though it is also exposed though the Nvim struct.

This function allows for up to two custom handlers:

§request_handler

The request_handler struct must implement the RequestHandler trait which then allows it to process incoming RPC requests from Neovim. If None is passed the DefaultHandler will be used which responds with a NotImplemented error.

§notification_handler

The notification_handler struct must implement the ‘NotificationHandler’ trait which then allows it to process incoming RPC notifications from Neovim. If ‘None’ is passed the DefaultHandler will be used which ignores all RPC notifications.

Source

pub fn call(&mut self, method: &str, args: Vec<Value>) -> Result<Value, Error>

Call a RPC function

This function allows for arbitrary Neovim function calls

Auto Trait Implementations§

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> 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, 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.