nvim_rs/create/
mod.rs

1//! Functions to spawn a [`neovim`](crate::neovim::Neovim) session.
2//!
3//! This implements various possibilities to connect to neovim, including
4//! spawning an own child process. Available capabilities might depend on your
5//! OS and choice of features.
6//!
7//! Supported features: `use_tokio` and `use_async-std`.
8//!
9//! **IMPORTANT**: Due to incompatibilities of the rust async ecosystem,  you
10//! might not be able to use types from one lib with the runtime of another lib.
11//! E.g. when using the features `use_tokio`, you will need to run all the
12//! API functions from inside the tokio runtime.
13#[cfg(feature = "use_tokio")]
14pub mod tokio;
15
16#[cfg(feature = "use_async-std")]
17pub mod async_std;
18
19use core::future::Future;
20use std::{fs::File, io};
21
22use crate::rpc::handler::Handler;
23
24/// A task to generalize spawning a future that returns `()`.
25///
26/// If you use one of the features `use_tokio` or `use_async-std`, this will
27/// automatically be implemented on you
28/// [`Handler`](crate::rpc::handler::Handler) using the appropriate runtime.
29///
30/// If you have a runtime that brings appropriate types, you can implement this
31/// on your [`Handler`](crate::rpc::handler::Handler) and use
32/// [`Neovim::new`](crate::neovim::Neovim::new) to connect to neovim.
33pub trait Spawner: Handler {
34  type Handle;
35
36  fn spawn<Fut>(&self, future: Fut) -> Self::Handle
37  where
38    Fut: Future<Output = ()> + Send + 'static;
39}
40
41/// Create a std::io::File for stdout, which is not line-buffered, as
42/// opposed to std::io::Stdout.
43#[cfg(unix)]
44pub fn unbuffered_stdout() -> io::Result<File> {
45  use std::{io::stdout, os::fd::AsFd};
46
47  let owned_sout_fd = stdout().as_fd().try_clone_to_owned()?;
48  Ok(File::from(owned_sout_fd))
49}
50#[cfg(windows)]
51pub fn unbuffered_stdout() -> io::Result<File> {
52  use std::{io::stdout, os::windows::io::AsHandle};
53
54  let owned_sout_handle = stdout().as_handle().try_clone_to_owned()?;
55  Ok(File::from(owned_sout_handle))
56}