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 fn expose_tcp(&self, addr: String) -> impl Future<Output = Result<u16, Error>> + Send;16 fn expose_udp(&self, addr: String) -> impl Future<Output = Result<u16, Error>> + Send;17}1819pub struct EditorEndpoints<E>(pub E);2021#[endpoints(ns = 8)]22impl<E: EditorBackend + 'static> EditorEndpoints<E> {23 #[endpoints(id = 1)]24 async fn open_editor(&self, socket_path: String) -> Result<(), Error> {25 self.0.open_editor(socket_path).await26 }2728 #[endpoints(id = 2)]29 async fn expose_tcp(&self, addr: String) -> Result<u16, Error> {30 self.0.expose_tcp(addr).await31 }3233 #[endpoints(id = 3)]34 async fn expose_udp(&self, addr: String) -> Result<u16, Error> {35 self.0.expose_udp(addr).await36 }37}3839pub fn serve_editor<E, C>(rpc: &mut Rpc<C>, editor: E)40where41 E: EditorBackend + Send + Sync + 'static,42 C: Config,43{44 EditorEndpoints(editor).register_endpoints(rpc);45}