Skip to content

Commit

Permalink
patch example
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastian Schubert committed Jul 10, 2024
1 parent cf815fd commit e2696ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
3 changes: 3 additions & 0 deletions examples/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ uuid = { version = "1.10.0" }

[build-dependencies]
gin-tonic = { version = "0.4.8", features = ["uuid_bytes"] }

[patch.crates-io]
gin-tonic = { path = "../../gin" }
23 changes: 6 additions & 17 deletions examples/shared/src/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ pub mod example_server {
}
#[derive(Debug)]
pub struct ExampleServer<T: Example> {
inner: _Inner<T>,
inner: Arc<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
struct _Inner<T>(Arc<T>);
impl<T: Example> ExampleServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
pub fn from_arc(inner: Arc<T>) -> Self {
let inner = _Inner(inner);
Self {
inner,
accept_compression_encodings: Default::default(),
Expand Down Expand Up @@ -87,7 +85,6 @@ pub mod example_server {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
let inner = self.inner.clone();
match req.uri().path() {
"/example.Example/echo" => {
#[allow(non_camel_case_types)]
Expand All @@ -110,7 +107,6 @@ pub mod example_server {
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = echoSvc(inner);
let codec = ::gin_tonic::GinCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
Expand All @@ -130,8 +126,11 @@ pub mod example_server {
_ => Box::pin(async move {
Ok(http::Response::builder()
.status(200)
.header("grpc-status", "12")
.header("content-type", "application/grpc")
.header("grpc-status", tonic::Code::Unimplemented as i32)
.header(
http::header::CONTENT_TYPE,
tonic::metadata::GRPC_CONTENT_TYPE,
)
.body(empty_body())
.unwrap())
}),
Expand All @@ -150,16 +149,6 @@ pub mod example_server {
}
}
}
impl<T: Example> Clone for _Inner<T> {
fn clone(&self) -> Self {
Self(Arc::clone(&self.0))
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
}
}
impl<T: Example> tonic::server::NamedService for ExampleServer<T> {
const NAME: &'static str = "example.Example";
}
Expand Down

0 comments on commit e2696ff

Please sign in to comment.