Skip to content

Resolve ambiguity issue of stream #748

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

Closed

Conversation

aryan-25
Copy link
Contributor

@aryan-25 aryan-25 commented Jul 2, 2024

Motivation:

Modifications:

  • Removed the default value assignment of nil.
  • Changed the type of the length argument from Int64? to an enum-backed struct Length. This struct uses the existing internal enum RequestBodyLength which has cases .unknown and .known(_ count: Int64).

Result:

  • There are no more ambiguity issues.
  • Specifying an unknown length as an argument to the stream function (as well as the initializer for Body) is now more readable as it has to be spelled out explicitly as .unknown rather than an unclear nil.

aryan-25 added 2 commits July 2, 2024 11:19
… length. Change type for length from `Int64?` to enum-backed type.
Comment on lines +91 to +94
if case .known(let count) = self.contentLength.length {
return Int(count)
}
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: prefer switching exhaustively over enums

}
}

/// Body size. If nil,`Transfer-Encoding` will automatically be set to `chunked`. Otherwise a `Content-Length`
/// header is set with the given `contentLength`.
public var contentLength: Int64?
public var contentLength: Length
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can't make this change, it's an API break. We could work around it by adding a new length property using the new type and have computed getters/setters on contentLength.

However I don't think we should make this change: Length doesn't allow the user to recover the (known) length value. I think if we want to use this type it should only be at the surface level in the stream func. It also makes me wonder whether we should do this at all and just use @_disfavoredOverload. WDYT @FranzBusch?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a new not an API break because we haven't released the API yet afaik but I agree exposing this var is weird. @fabianfett what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

We haven't released this API yet. Therefore this will not be a breaking change. Generally I'm in favor of using @_disfavoredOverload on the Int version of this API as well as the initializers that use trailing closure syntax.

@aryan-25
Copy link
Contributor Author

aryan-25 commented Jul 3, 2024

Closing this PR as it now has too many unneeded changes and creating a new one with the @_disfavoredOverload change

@aryan-25 aryan-25 closed this Jul 3, 2024
@aryan-25 aryan-25 deleted the fix_stream_ambiguity_issue branch July 3, 2024 13:13
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