-
Notifications
You must be signed in to change notification settings - Fork 257
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
Naming Bikeshed: Response::into_{json,xml}_body
#1957
Comments
Hmm, hadn't considered The 4th bullet are good ideas as well, but I'm currently leaning toward brevity above e.g.,
Though, writing that out, prefaces are all over the place. Maybe your fourth bullet is better. @JeffreyRichter @RickWinter what are your thoughts? |
Does Rust not use "from" as in "from_json" or "from_xml"? |
It's a question of consistency. |
#1954 introduces two new methods on
Response
:Response::<T>::into_json_body<U: DeserializeOwned>(self) -> crate::Result<U>
Response::<T>::into_xml_body<U: DeserializeOwned>(self) -> crate::Result<U>
The purpose of these methods is to consume the
Response
, stream the entire body, and deserialize it to the provided model typeU
, using either JSON or XML serde deserialization.The method name isn't ideal,
into
properly implies consuming theResponse
to produce a new type, but the{json,xml}_body
implies that it's "returning" JSON or XML somehow, when actually it's using JSON/XML deserialization to produce a model type.However, we also have methods
into_raw_body
andinto_body
for returning a rawResponseBody
and aT: Model
, which make more sense. Both are consuming theResponse
to produce a (potentially "raw") representation of the body. Theinto_{json,xml}_body
methods align with the convention established by those methods.We decided to move forward without resolving this naming conflict, so this issue exists to have a place to revisit it prior to a GA release, after which name changes would be much more costly.
Some potential ideas for discussion:
into_body_from_{json,xml}
is more accurate, but verbosebody_from_{json,xml}
loses theinto_
prefix, which has meaning in Rustparse_{json,xml}
is more accurate, relatively terse, but does still lose theinto_
prefixinto_{json,xml}_model
may be clearer, since it indicates the model is defined by JSON or XML rather than implying it returns the "body". We could similarly renameinto_body
tointo_model
🤔cc @heaths
The text was updated successfully, but these errors were encountered: