1use std::future::Future;23use bifrostlink::declarative::endpoints;4use bifrostlink::{Config, Rpc};5use serde::{Deserialize, Serialize};67#[derive(Serialize, Deserialize, Debug, thiserror::Error)]8pub enum Error {9 #[error("editor failed: {0}")]10 Failed(String),11}1213pub trait EditorBackend: Send + Sync {14 fn open_editor(&self, socket_path: String) -> impl Future<Output = Result<(), Error>> + Send;15}1617pub struct EditorEndpoints<E>(pub E);1819#[endpoints(ns = 8)]20impl<E: EditorBackend + 'static> EditorEndpoints<E> {21 #[endpoints(id = 1)]22 async fn open_editor(&self, socket_path: String) -> Result<(), Error> {23 self.0.open_editor(socket_path).await24 }25}2627pub fn serve_editor<E, C>(rpc: &mut Rpc<C>, editor: E)28where29 E: EditorBackend + Send + Sync + 'static,30 C: Config,31{32 EditorEndpoints(editor).register_endpoints(rpc);33}