use derive_deftly::Deftly;
use futures::FutureExt as _;
use std::sync::Arc;
use tor_rpcbase::{self as rpc, templates::*};
#[derive(Debug, serde::Deserialize, Deftly)]
#[derive_deftly(DynMethod)]
#[deftly(rpc(method_name = "rpc:release", bypass_method_dispatch))]
struct RpcRelease {}
impl rpc::RpcMethod for RpcRelease {
type Output = rpc::Nil;
type Update = rpc::NoUpdates;
}
impl rpc::DynMethod for RpcRelease {
fn invoke_without_dispatch(
&self,
ctx: Arc<dyn rpc::Context>,
obj_id: &rpc::ObjectId,
) -> Result<tor_rpcbase::dispatch::RpcResultFuture, tor_rpcbase::InvokeError> {
let result = match ctx.release_owned(obj_id) {
Ok(()) => Ok(Box::new(rpc::NIL) as _),
Err(e) => Err(rpc::RpcError::from(e)),
};
Ok(futures::future::ready(result).boxed())
}
}