Got it. First things first, you should listen to what the compiler says. It's correct like 99.999% of the time and it will help you to speed up your learning of Rust.
That being said, the compiler is telling you that you can't create an instance of a struct without a path (like an anonymous struct), this is how you create new instances of a struct:
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64,
}
let user1 = User {
email: String::from("someone@example.com"),
username: String::from("someusername123"),
active: true,
sign_in_count: 1,
};
After fixing that, take notice on the push_str
method that you are passing w
to. Here's the documentation for it.
In the signature, you can see that it receives a string slice (&str
), but you are not giving it a string slice. You are giving it a SomeStruct
. Rust is a strongly typed language, and you will need to type this intermediate struct type as well. After doing that, you will need to make it possible to get a string representation of your struct.
Only you know your domain but, from what I can see in your code, you want a json-like string representation of w:
{ auditid: r.audit_id, title: r.title}
So you could do something like this:
format!("{{ auditid: {}, title: {}}}", r.audit_id, r.title);
But manually building json strings is not how things are usually done. You need to understand how serialization works, and that's usually done using the Serde
crate in Rust.
For the record, this is not valid json:
// maak json van de data uit de database
let mut str = String::from("\"Customer\": \"<CUSTOMER>\",\"token\": \"<TOKEN>\",\"Audit\": [")