Skip to content
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

Minimal support for downcasting to a custom transport type #451

Merged
merged 2 commits into from
Dec 20, 2023

Conversation

joshtriplett
Copy link
Collaborator

This PR is an alternative to the approach in
#432 , based on the comment at
#432 (comment) .

I added methods on trillium_http::Conn to get a &Transport or &mut Transport.

I then added methods on BoxedTransport to downcast to a specific type
implementing Transport. I went with downcast methods on BoxedTransport
rather than exposing as_any() and as_mut_any() directly, because the latter
would have been the same amount of code and with a more complex interface.

With both of these changes, given a trillium::Conn, you can call
conn.inner().transport().downcast_ref() or
conn.inner().transport_mut().downcast_mut() to get your custom transport
type.

I think this is the minimal amount of support needed to make this possible.

Copy link

codecov bot commented Dec 12, 2023

Codecov Report

Attention: 12 lines in your changes are missing coverage. Please review.

Comparison is base (6368476) 48.03% compared to head (2549594) 47.94%.

Files Patch % Lines
http/src/transport/boxed_transport.rs 0.00% 8 Missing ⚠️
http/src/conn.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #451      +/-   ##
==========================================
- Coverage   48.03%   47.94%   -0.09%     
==========================================
  Files         169      169              
  Lines        6581     6593      +12     
==========================================
  Hits         3161     3161              
- Misses       3420     3432      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jbr
Copy link
Contributor

jbr commented Dec 20, 2023

This looks great, thanks!

… reference

These functions are useful for getting access to an application-specific
custom transport type that has additional methods.
These functions are useful for getting access to an application-specific
custom transport type that has additional methods.
@joshtriplett joshtriplett force-pushed the downcast-transport-minimal branch from b245bd3 to 2549594 Compare December 20, 2023 19:17
@joshtriplett
Copy link
Collaborator Author

@jbr CI is no longer failing. (Failure looked spurious, I rebased which also re-ran CI and it passes now.)

@jbr
Copy link
Contributor

jbr commented Dec 20, 2023

Unfortunately the failure wasn't spurious, but it is fixed!

@jbr jbr merged commit 1bdd4d6 into trillium-rs:main Dec 20, 2023
19 checks passed
@joshtriplett joshtriplett deleted the downcast-transport-minimal branch December 24, 2023 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants