-
Notifications
You must be signed in to change notification settings - Fork 174
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
Change send_json
data
argument
#737
Comments
Yeah I agree, this could be passed by reference. Can you make a bullet in |
Can do! |
Here's a PR #739 |
Danke |
if so
in this case, we can pass a reference to fn main() {
send_json(NotClone {
name: "foo".to_string(),
});
let retries = 3;
let data = NotClone {
name: "foo".to_string(),
};
for _ in 0..retries {
send_json(&data);
}
}
#[derive(serde::Serialize)]
struct NotClone {
name: String,
}
fn send_json(data: impl serde::Serialize) {} if we change it to so I think we can keep the old function signature and be flexible. |
Only if |
Hello,
Request::send_json
has the following signature:However, the implementation only ever uses references to
data
making the API less flexible than it could be. For example, I'm implementing some logic that needs to perform retries and because ownership is passed I need to clone my data, despite the function not needing ownership of it.This would be a breaking change, although one that is trivially fixable, so it would need to be slated for 3.0. I'd also suggest reviewing all API surfaces for similar redundant passing of ownership and relaxing to references where appropriate.
Thanks!
The text was updated successfully, but these errors were encountered: