use std::task::{Context, Poll};
use bytes::Bytes;
use futures::future;
use tower::Service;
use super::{
RpcStatus,
body::Body,
message::{Request, Response},
server::RpcServerError,
};
use crate::protocol::ProtocolId;
#[derive(Clone)]
pub struct ProtocolServiceNotFound;
impl Service<ProtocolId> for ProtocolServiceNotFound {
type Error = RpcServerError;
type Future = future::Ready<Result<Self::Response, Self::Error>>;
type Response = NeverService;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, protocol: ProtocolId) -> Self::Future {
future::ready(Err(RpcServerError::ProtocolServiceNotFound(
String::from_utf8_lossy(&protocol).to_string(),
)))
}
}
pub struct NeverService;
impl Service<Request<Bytes>> for NeverService {
type Error = RpcStatus;
type Future = future::Ready<Result<Self::Response, Self::Error>>;
type Response = Response<Body>;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
unimplemented!()
}
fn call(&mut self, _: Request<Bytes>) -> Self::Future {
unimplemented!()
}
}