Skip to content

Still support Arc #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Still support Arc
  • Loading branch information
jorendorff committed Aug 20, 2024
commit fcf5a5753be3c7585179f5fd2a9e9292fb9ca5d0
17 changes: 17 additions & 0 deletions crates/twirp-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ impl prost_build::ServiceGenerator for ServiceGenerator {
}
writeln!(buf, "}}").unwrap();

writeln!(buf, "#[twirp::async_trait::async_trait]").unwrap();
writeln!(buf, "impl<T> {service_name} for std::sync::Arc<T>").unwrap();
writeln!(buf, "where").unwrap();
writeln!(buf, " T: {service_name} + Sync + Send").unwrap();
writeln!(buf, "{{").unwrap();
for m in &service.methods {
writeln!(
buf,
" async fn {}(&self, ctx: twirp::Context, req: {}) -> Result<{}, twirp::TwirpErrorResponse> {{",
m.name, m.input_type, m.output_type,
)
.unwrap();
writeln!(buf, " (*self).{}(ctx, req).await", m.name).unwrap();
writeln!(buf, " }}").unwrap();
}
writeln!(buf, "}}").unwrap();

// add_service
writeln!(
buf,
Expand Down
1 change: 1 addition & 0 deletions example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub async fn main() {
}
}

// Note: If your server type can't be Clone, consider wrapping it in `std::sync::Arc`.
#[derive(Clone)]
struct HaberdasherApiServer;

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy