Skip to content

Comments

Remove request pub fields#1121

Closed
benalleng wants to merge 1 commit intopayjoin:masterfrom
benalleng:remove-request-pub-fields
Closed

Remove request pub fields#1121
benalleng wants to merge 1 commit intopayjoin:masterfrom
benalleng:remove-request-pub-fields

Conversation

@benalleng
Copy link
Collaborator

@benalleng benalleng commented Sep 29, 2025

These three commits reduce the visibility of the Request Struct's internal fields and replaces their external access with a few getter methods.

I opted for url() instead of url_as_str() as we are not exposing a url to the public API anywhere so there does not need to be a distinction as all Urls in our public API are just strings

Closes #513

Pull Request Checklist

Please confirm the following before requesting review:

@coveralls
Copy link
Collaborator

coveralls commented Sep 29, 2025

Pull Request Test Coverage Report for Build 18113147319

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 84.634%

Totals Coverage Status
Change from base Build 18110655925: 0.005%
Covered Lines: 8592
Relevant Lines: 10152

💛 - Coveralls

///
/// This is full URL with scheme etc - you can pass it right to `reqwest` or a similar library.
pub url: Arc<Url>,
pub url: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a feeling this shouldn't be pub any longer either. I also wonder what use it has as a Record if it's now really an Object where we just need those functions as getters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I had run up against the wall at first but didn;t consider that any other ffi records would need to call this as an Arc for that to work, fixed

Comment on lines 44 to 49

pub fn url(&self) -> String { self.url.to_string() }

pub fn content_type(&self) -> String { self.content_type.to_string() }

pub fn body(&self) -> Vec<u8> { self.body.clone() }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we typically default to borrowing with getters. Did you choose to clone for convenience?

@nothingmuch
Copy link
Collaborator

what is the motivation for this? isn't it simpler to just change the field types themselves instead of adding accessors? all of the fields must be read for a valid request to be constructed, returning them all at once allows for destructuring in match, so afaict accessors only take away ergonomics, and any logic that is done in the accessors could be done before constructing this

@benalleng benalleng force-pushed the remove-request-pub-fields branch from 7ad1160 to e0a3565 Compare September 29, 2025 22:44
@benalleng
Copy link
Collaborator Author

benalleng commented Sep 29, 2025

what is the motivation for this? isn't it simpler to just change the field types themselves instead of adding accessors? all of the fields must be read for a valid request to be constructed, returning them all at once allows for destructuring in match, so afaict accessors only take away ergonomics, and any logic that is done in the accessors could be done before constructing this

The url field being the critical one here, by not changing the type of the field and instead using accessors the intention was to prevent having to do any logic transforming the field to and from a String and a Url. Keeping the Url out of the public API with minimal logic changes in the Request parsing

@benalleng benalleng force-pushed the remove-request-pub-fields branch 2 times, most recently from 9bf44c0 to 761a1c1 Compare September 29, 2025 22:56
This commit reduces the visibility of all the Request fields to private
and replaces the access with public getter methods that returns the fields
as refs.
@benalleng benalleng force-pushed the remove-request-pub-fields branch from 761a1c1 to bf1874d Compare September 29, 2025 23:02
@DanGould
Copy link
Contributor

what is the motivation for this?

To make the fields read only and keep the type safety of Request.

@DanGould
Copy link
Contributor

That said making Request url String is strictly simpler and lets us delete a bunch. @benalleng could you give it a try in another PR so we can see what that looks like?

@benalleng
Copy link
Collaborator Author

benalleng commented Sep 30, 2025

Closed as uneeded following #1122

@benalleng benalleng closed this Sep 30, 2025
@benalleng benalleng deleted the remove-request-pub-fields branch October 6, 2025 18:39
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.

Remove url::Url types from public API

4 participants