Hello everyone,
I’m currently learning Rust and I’m working on a small project where I consume data from the GitHub API and generate a PDF report.
I’m getting an error in this part of the code and I can’t figure out what I’m doing wrong:
use reqwest::blocking::Client;
use crate::{
core::api::get_data,
infra::pdf::generate_pdf,
model::github_events::Events,
};
fn response_vec_string(client: &Client, name_user: String) {
let vec_receive = get_data(client, name_user).unwrap();
let response = search_name_respository(&vec_receive);
match generate_pdf(&response, &vec_receive) {
Ok(message) => {
println!("{message:?}");
}
Err(err) => panic!("{:?}", err),
}
}
fn search_name_respository(
vector_repository: &Vec<Events>,
) -> Vec<String> {
let mut vec_response: Vec<String> = Vec::new();
for value in vector_repository {
if verification_not_exits(
&value.repo.name,
&vec_response,
) != true {
vec_response.push(
&value.repo.name.to_string(),
);
}
}
vec_response
}
fn verification_not_exits(
name_repository: &String,
vec_name_repository: &Vec<String>,
) -> bool {
let mut auxiliary: bool = false;
for value in vec_name_repository {
if value == name_repository {
auxiliary = true;
}
}
auxiliary
}
The error appears in this line:
vec_response.push(&value.repo.name.to_string());
Could someone explain why this happens and what would be the correct way to handle it in Rust?
```bash id="a9q7dr"
Compiling github-user-activity v0.1.0
(/home/karurosu/Documents/programming/rust/projects/cli/github-user-activity)
error[E0308]: mismatched types
--> src/infra/names_respositorys.rs:20:31
|
20 | vec_response.push(&value.repo.name.to_string());
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected `String`, found `&String`
| arguments to this method are incorrect
|
note: method defined here
--> /home/karurosu/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/
lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:993:12
|
993 | pub fn push(&mut self, value: T) {
| ^^^^
help: consider removing the borrow
20 - vec_response.push(&value.repo.name.to_string());
20 + vec_response.push(value.repo.name.to_string());
For more information about this error, try `rustc --explain E0308`.
error: could not compile `github-user-activity` (lib)
due to 1 previous error
```
Thanks in advance.