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

feat(util): add const constructor for empty Full #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions http-body-util/src/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ impl<D> Full<D>
where
D: Buf,
{
/// Create a new empty `Full`.
pub const fn empty() -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

This is what the Empty type is for, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If client use the Empty type for the case to describe empty body where the functionality provided by Full is sufficient and do not need to prepare the own Body type, client will need to either box it and erase the type or define the own wrapping type, since Empty is a different type from Full. Being able to use an empty Full type in a const context is useful, as it allows client to define fixed responses that are often used for fallbacks.

Full { data: None }
}

/// Create a new `Full`.
pub fn new(data: D) -> Self {
let data = if data.has_remaining() {
Expand Down
Loading