improv(service): Make output parameter a generic futures Sink

This commit is contained in:
Michael Aaron Murphy 2021-08-25 19:23:51 +02:00
parent 4abe6a894a
commit 07b740a12f
3 changed files with 6 additions and 7 deletions

View file

@ -6,7 +6,6 @@ use postage::mpsc::Sender;
use postage::prelude::*; use postage::prelude::*;
use smol::process::{Command, Stdio}; use smol::process::{Command, Stdio};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::os::unix::process::CommandExt;
use std::{ use std::{
io, io,
path::{Path, PathBuf}, path::{Path, PathBuf},

View file

@ -1,10 +1,11 @@
mod plugins; mod plugins;
use crate::plugins::*; use crate::plugins::*;
use futures::SinkExt;
use futures_core::Stream; use futures_core::Stream;
use futures_lite::{future, StreamExt}; use futures_lite::{future, StreamExt};
use pop_launcher::*; use pop_launcher::*;
use postage::{mpsc, prelude::Sink as PostageSink}; use postage::mpsc;
use regex::Regex; use regex::Regex;
use slab::Slab; use slab::Slab;
use std::{ use std::{
@ -55,19 +56,19 @@ pub async fn main() {
futures_lite::future::zip(service, responder).await; futures_lite::future::zip(service, responder).await;
} }
pub struct Service { pub struct Service<O> {
active_search: Vec<(PluginKey, PluginSearchResult)>, active_search: Vec<(PluginKey, PluginSearchResult)>,
associated_list: HashMap<Indice, Indice>, associated_list: HashMap<Indice, Indice>,
awaiting_results: HashSet<PluginKey>, awaiting_results: HashSet<PluginKey>,
last_query: String, last_query: String,
no_sort: bool, no_sort: bool,
output: postage::mpsc::Sender<Response>, output: O,
plugins: Slab<PluginConnector>, plugins: Slab<PluginConnector>,
search_scheduled: bool, search_scheduled: bool,
} }
impl Service { impl<O: futures::Sink<Response> + Unpin> Service<O> {
pub fn new(output: postage::mpsc::Sender<Response>) -> Self { pub fn new(output: O) -> Self {
Self { Self {
active_search: Vec::new(), active_search: Vec::new(),
associated_list: HashMap::new(), associated_list: HashMap::new(),

View file

@ -1,7 +1,6 @@
use crate::*; use crate::*;
use pop_launcher::*; use pop_launcher::*;
use postage::mpsc::Sender; use postage::mpsc::Sender;
use postage::prelude::*;
use slab::Slab; use slab::Slab;
use std::borrow::Cow; use std::borrow::Cow;