[Rust] question regarding appData

I am facing a little issue here, when i try to use the app_data, when creating a producer, i have made a struct for returning params for the signal, i get an error for use the AppData type i am getting a Serialize` is not satisfied,

any help would be awesome,.

thanks advance

mediasoup::data_structures
pub struct AppData
Container for arbitrary data attached to mediasoup entities.

6 implementations

the trait bound `mediasoup::data_structures::AppData: Serialize` is not satisfied
the trait `Serialize` is not implemented for `mediasoup::data_structures::AppData`rustcE0277
mod.rs(1899, 12): required by a bound in `utils::codec::_::_serde::ser::SerializeStruct::serialize_field`
the trait bound `mediasoup::data_structures::AppData: Deserialize<'_>` is not satisfied
the trait `Deserialize<'_>` is not implemented for `mediasoup::data_structures::AppData`rustcE0277
mod.rs(1719, 12): required by a bound in `next_element`
1 Like

here is what i am tryihng to do returning the producer info back

data: ProduceMediaData {
                                        id: producer.id().clone(),
                                        kind: producer.kind().clone(),
                                        appData: producer.app_data(),
                                    },

i did use the type of AppData but the error above rise, or is there a special way to extra the data out of the AppData

cheers

what seems to work for now, is downcast the AppData struct into your app_data structure, hope that help others who has this issue

2 Likes

I hope it’s not a problem to bump a thread like this, but I wanted to add some more info that may help others in the future.

If you want to preserve app_data in a generic way, I found that using serde_json::Value is a good way to preserve json formatted data without locking it to a specific structure. You can set the type to this for any place that needs to handle serialize/deserialize. You can then switch between the types cleanly by using .downcast_ref::<serde_json::Value>() to go from AppData β†’ serde_json::Value and AppData::new(app_data) to go back.

1 Like