MaxOhn / rosu-v2

A rust wrapper for the osu!api v2
MIT License
24 stars 9 forks source link

How to serialize output? #8

Closed Listum closed 1 year ago

Listum commented 1 year ago

Im new to Rust. How can i serialize output, let's say through sedre. I already tried substituting my struct, but it doesn't accept other vectors. I can't even convert the output to string. Can you tell me how I can output, let's say, only the recent score pp.

Thank you very much.

MaxOhn commented 1 year ago

The simplest way is to collect all pp values into a new Vec and then serializing that. Assuming you want to serialize as a json string, it would look something like this

let recent_scores: Vec<Score> = ...
let pp: Vec<_> = recent_scores.iter().map(|score| score.pp).collect();
let serialized_pp: String = serde_json::to_string(&pp).unwrap();
Listum commented 1 year ago

Thanks a lot <3