Remove alloc guards and update codegen
Remove unnecessary `alloc` feature guards in `roto-tonic`. Add `roto-runtime` dependency to `codegen`, fix test data paths, and include `async-trait` in the hello world build test.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
#[allow(unused_imports)]
|
||||
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};
|
||||
use core::str;
|
||||
#[cfg(feature = "alloc")]
|
||||
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
||||
|
||||
pub struct UnaryRequest<'a> {
|
||||
@@ -81,12 +80,10 @@ impl<'b> UnaryRequestBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedUnaryRequest {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedUnaryRequest {
|
||||
type Reader<'a> = UnaryRequest<'a>;
|
||||
fn reader(&self) -> UnaryRequest<'_> {
|
||||
@@ -94,7 +91,6 @@ impl roto_runtime::RotoOwned for OwnedUnaryRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedUnaryRequest {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedUnaryRequest { data: buf })
|
||||
@@ -181,12 +177,10 @@ impl<'b> UnaryResponseBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedUnaryResponse {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedUnaryResponse {
|
||||
type Reader<'a> = UnaryResponse<'a>;
|
||||
fn reader(&self) -> UnaryResponse<'_> {
|
||||
@@ -194,7 +188,6 @@ impl roto_runtime::RotoOwned for OwnedUnaryResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedUnaryResponse {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedUnaryResponse { data: buf })
|
||||
@@ -281,12 +274,10 @@ impl<'b> StreamingRequestBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedStreamingRequest {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedStreamingRequest {
|
||||
type Reader<'a> = StreamingRequest<'a>;
|
||||
fn reader(&self) -> StreamingRequest<'_> {
|
||||
@@ -294,7 +285,6 @@ impl roto_runtime::RotoOwned for OwnedStreamingRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedStreamingRequest {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedStreamingRequest { data: buf })
|
||||
@@ -381,12 +371,10 @@ impl<'b> StreamingResponseBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedStreamingResponse {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedStreamingResponse {
|
||||
type Reader<'a> = StreamingResponse<'a>;
|
||||
fn reader(&self) -> StreamingResponse<'_> {
|
||||
@@ -394,7 +382,6 @@ impl roto_runtime::RotoOwned for OwnedStreamingResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedStreamingResponse {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedStreamingResponse { data: buf })
|
||||
@@ -407,58 +394,41 @@ impl roto_runtime::RotoMessage for OwnedStreamingResponse {
|
||||
|
||||
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use tonic::{Request, Response, Status};
|
||||
#[cfg(feature = "alloc")]
|
||||
use tokio_stream::Stream;
|
||||
#[cfg(feature = "alloc")]
|
||||
use std::pin::Pin;
|
||||
#[cfg(feature = "alloc")]
|
||||
use std::sync::Arc;
|
||||
#[cfg(feature = "alloc")]
|
||||
use std::task::{Context, Poll};
|
||||
#[cfg(feature = "alloc")]
|
||||
use std::future::Future;
|
||||
#[cfg(feature = "alloc")]
|
||||
use tonic::body::BoxBody;
|
||||
#[cfg(feature = "alloc")]
|
||||
use tower::Service;
|
||||
#[cfg(feature = "alloc")]
|
||||
use futures_util::StreamExt;
|
||||
#[cfg(feature = "alloc")]
|
||||
use http_body_util::BodyExt;
|
||||
#[cfg(feature = "alloc")]
|
||||
use http_body::Body;
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::{BufferPool, StatusBody};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[async_trait::async_trait]
|
||||
pub trait InteropService: Send + Sync + 'static {
|
||||
async fn unary_call(&self, request: Request<OwnedUnaryRequest>) -> std::result::Result<Response<OwnedUnaryResponse>, Status>;
|
||||
async fn streaming_call(&self, request: Request<OwnedStreamingRequest>) -> std::result::Result<Response<Pin<Box<dyn Stream<Item = std::result::Result<OwnedStreamingResponse, Status>> + Send>>>, Status>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[derive(Clone)]
|
||||
pub struct InteropServiceServer {
|
||||
inner: Arc<dyn InteropService>,
|
||||
pool: Arc<BufferPool>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl InteropServiceServer {
|
||||
pub fn new(inner: Arc<dyn InteropService>, pool: Arc<BufferPool>) -> Self {
|
||||
Self { inner, pool }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl tonic::server::NamedService for InteropServiceServer {
|
||||
const NAME: &'static str = "interop.InteropService";
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl Service<http::Request<BoxBody>> for InteropServiceServer {
|
||||
type Response = http::Response<BoxBody>;
|
||||
type Error = std::convert::Infallible;
|
||||
|
||||
Reference in New Issue
Block a user