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

Introduce a Standard enum for connections #237

Merged
merged 14 commits into from
Mar 8, 2021
Merged

Introduce a Standard enum for connections #237

merged 14 commits into from
Mar 8, 2021

Conversation

rcoh
Copy link
Collaborator

@rcoh rcoh commented Mar 3, 2021

Issue #, if available: #209
Description of changes: aws_hyper::Client is generic in C, the underlying HTTP connection. This can make it difficult to use in real-world apps because you would need a fairly complex constraint in trait bounds to access client.call. If you wanted to eg. put a client in a struct your practical option was to leave the C param generic. But then, if you actually wanted to use it, you needed this 6 line bound on the inner Http Service so that call would actually be in scope

To address this shortcoming, this diff introduces a Standard connection (perhaps a better name could be found) that has 2 variants:

  1. Https. What you probably want most of the time.
  2. Dyn: An escape hatch for any implementation of the HttpService trait.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@rcoh rcoh requested review from seanmonstar and a team March 4, 2021 14:40
@rcoh rcoh changed the title Enum Conn POC Introduce a Standard enum for connections Mar 4, 2021
Copy link

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

Looks good at a high level. I left a couple of notes inline.

/// When testing code that uses the SDK, the variant enables using a `TestConnection` object
/// in place of a real hyper HTTP client
// Note: this variant may be removed in favor of having `TestConnection` be used via Dyn<Box<...>>
Test(TestConnection<hyper::Body>),

Choose a reason for hiding this comment

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

I would start w/o this and added it later if need be.

/// 3. Any implementation of the `HttpService` trait
///
/// This is designed to be used with [`aws_hyper::Client`](crate::Client) as a connector.
pub enum Standard {

Choose a reason for hiding this comment

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

I would avoid the enumeration in the public API. Keep variants private. I don't think there is a reason to list out the variants?

Choose a reason for hiding this comment

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

For example, you could make pub struct Standard(Strategy) and have a private enum Strategy { .. }.

Comment on lines +17 to +18
#[derive(Clone)]
pub struct Standard(Connector);

Choose a reason for hiding this comment

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

what about StandardConnection or something like that? the name Standard is pretty vague when taken out of the module context (re-exports and the like).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

generally agree, but the other side of the house requested that I follow https://doc.rust-lang.org/1.0.0/style/style/naming/README.html#avoid-redundant-prefixes-[rfc-356] 🤷🏻

I guess we should pick and stick to a convention, but I don't have strong feelings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we could rename the module as connection? or connector?

Choose a reason for hiding this comment

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

ehh, i think conn is fine. i wasn't aware of that style guide suggestion

/// Generally, `https()` should be used instead. This constructor is intended to support
/// using things like [`TestConnection`](crate::test_connection::TestConnection) or alternative
/// http implementations.
pub fn new(connector: Box<dyn HttpService>) -> Self {

Choose a reason for hiding this comment

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

if this is generally only used for tests, can we make it pub(crate) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's used for external users to test their usages of the connection (eg. for integration tests I would swap in a TestConnection/RecordingConnection.

Comment on lines 58 to 65
impl Clone for Connector {
fn clone(&self) -> Self {
match self {
Connector::Https(client) => Connector::Https(client.clone()),
Connector::Dyn(box_conn) => Connector::Dyn(box_conn.clone()),
}
}
}

Choose a reason for hiding this comment

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

i assume you implemented this because it couldn't be derived? i thought it would be able to...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh good catch. I think this was from before I added impl Clone for Box<dyn HttpService>. Removed.

@rcoh rcoh merged commit 9959d9b into main Mar 8, 2021
@rcoh rcoh deleted the enum-conns branch March 8, 2021 23:02
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.

4 participants