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 web::ReqData<T> extractor #1748

Merged
merged 7 commits into from Oct 24, 2020
Merged

Add web::ReqData<T> extractor #1748

merged 7 commits into from Oct 24, 2020

Conversation

robjtede
Copy link
Member

@robjtede robjtede commented Oct 20, 2020

PR Type

Feature

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made for the appropriate packages.
  • Format code with the latest stable rustfmt

Overview

Superceeds #1729 but includes original commits by @jplatte.

Adds a ReqData extractor for request data / request extensions, analogous to web::Data.

Changes from original:

  • remove DerefMut impl
    • i see this as a footgun, devs may infer that data is mutated in place (in the extensions map)
  • make inner field private
    • matches Data
    • can always be make pub but not the other way without breaking change
  • prints a failed extraction's type name (inspired by Print unconfigured Data<T> type when attempting extraction #1743)
  • provide an into_inner
  • improve docs
    • adding an example
    • clarify that data is cloned
  • couple words changed on app data extractor to distingush from req data
    • plus formatting tweaks

Future work:

  • support unsized
  • mention possibility of Rc<RefCell<T>> in docs for in-place mutation (theres a test demonstrating this)

@robjtede robjtede added B-semver-minor A-web project: actix-web labels Oct 20, 2020
@robjtede robjtede requested review from a team October 20, 2020 22:36
@robjtede robjtede mentioned this pull request Oct 20, 2020
4 tasks
@robjtede robjtede linked an issue Oct 20, 2020 that may be closed by this pull request
@robjtede robjtede changed the title Add web::ReqData extractor Add web::ReqData extractor Oct 20, 2020
@robjtede robjtede changed the title Add web::ReqData extractor Add web::ReqData<T> extractor Oct 20, 2020
@codecov-io
Copy link

codecov-io commented Oct 20, 2020

Codecov Report

Merging #1748 into master will increase coverage by 0.22%.
The diff coverage is 90.74%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1748      +/-   ##
==========================================
+ Coverage   53.60%   53.83%   +0.22%     
==========================================
  Files         126      127       +1     
  Lines       11996    12050      +54     
==========================================
+ Hits         6431     6487      +56     
+ Misses       5565     5563       -2     
Impacted Files Coverage Δ
src/data.rs 93.51% <ø> (ø)
src/lib.rs 68.42% <ø> (ø)
src/web.rs 85.71% <ø> (ø)
src/request_data.rs 90.74% <90.74%> (ø)
src/service.rs 81.01% <0.00%> (+1.38%) ⬆️
src/request.rs 95.25% <0.00%> (+1.58%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98243db...aa726ba. Read the comment docs.

@jplatte
Copy link
Contributor

jplatte commented Oct 21, 2020

can always be make pub but not the other way without breaking change

This isn't true due to Deref behavior, as we have seen with making the Path extractors inner value public. That said, I'm fine with this.

@robjtede robjtede merged commit d45a1aa into master Oct 24, 2020
@robjtede robjtede deleted the req-data branch October 24, 2020 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-web project: actix-web B-semver-minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

request data extractor similar to web::Data
3 participants