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

Add functions to downcast the transport as a reference or mutable reference #432

Closed

Conversation

joshtriplett
Copy link
Collaborator

These functions are useful for getting access to an application-specific
custom transport type that has additional methods.

…erence

These functions are useful for getting access to an application-specific
custom transport type that has additional methods.
@codecov
Copy link

codecov bot commented Oct 30, 2023

Codecov Report

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

Comparison is base (b6ecd94) 46.38% compared to head (3f6eb20) 46.26%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #432      +/-   ##
==========================================
- Coverage   46.38%   46.26%   -0.12%     
==========================================
  Files         164      164              
  Lines        6401     6417      +16     
==========================================
  Hits         2969     2969              
- Misses       3432     3448      +16     
Files Coverage Δ
http/src/conn.rs 71.55% <0.00%> (-0.89%) ⬇️
trillium/src/conn.rs 72.44% <0.00%> (-3.09%) ⬇️
http/src/transport/boxed_transport.rs 16.66% <0.00%> (-6.07%) ⬇️

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

/// Attempt to get a reference to the trait object as a specific transport type T.
///
/// If the type does not match the original transport type, this will return `None`.
pub fn downcast_transport_ref<T: Transport>(&self) -> Option<&T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the fence about introducing these to the trillium::Conn instead of requiring folks who need this advanced interface drop down to trillium_http::Conn. On one hand, it would be nice to do away with inner and inner_mut, on the other, that might be the right way to indicate to someone that what they're doing is advanced, and eventually gate inner and inner_mut on a trillium feature flag with the semantics of #[cfg(feature = "i-acknowledge-that-i-am-leaving-the-well-trod-path")]

Copy link
Contributor

@jbr jbr Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also on the fence about the interface on trillium_http::Conn<BoxedTransport>. Maybe this usage requires trillium_conn.inner().transport().as_any().downcast_ref() / trillium_conn.inner_mut().transport_mut().as_any_mut().downcast_mut() to make it harder to stumble into?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the currently documented premise that nothing should require dropping down to the trillium_http::Conn. If you want the top-level methods removed I can do that, but I think going from "if you need to do .inner() that's always a bug" to "do .inner() for various less-common methods" seems less ideal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also on the fence about the interface on trillium_http::Conn<BoxedTransport>. Maybe this usage requires trillium_conn.inner().transport().as_any().downcast_ref() / trillium_conn.inner_mut().transport_mut().as_any_mut().downcast_mut() to make it harder to stumble into?

Thinking about this: this would still require exposing some new methods, namely transport()/transport_mut() and as_any()/as_any_mut(). However, if you'd prefer this, I can implement it.

@joshtriplett
Copy link
Collaborator Author

Checking back in on this: whatever you end up deciding about trillium_http vs trillium, would you consider merging this in a new release?

@joshtriplett
Copy link
Collaborator Author

I posted #451, which I hope might be more what you're looking for. Let me know if that works for you.

@joshtriplett
Copy link
Collaborator Author

Closing this in favor of the merged #451.

@joshtriplett joshtriplett deleted the downcast-transport branch December 24, 2023 03:22
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