Skip to content

serde for Stores #5784

Description

@ImprovingRigmarole

Feature Request

Signals do support serde for T: serde
but I couldn't find any equivalent for Stores

Implement Suggestion

here is Signal's current implementation :

#[cfg(feature = "serialize")]
impl<T: serde::Serialize + 'static, Store: Storage<SignalData<T>> + 'static> serde::Serialize
for Signal<T, Store>
{
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.read().serialize(serializer)
}
}
#[cfg(feature = "serialize")]
impl<'de, T: serde::Deserialize<'de> + 'static, Store: Storage<SignalData<T>> + 'static>
serde::Deserialize<'de> for Signal<T, Store>
{
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(Self::new_maybe_sync(T::deserialize(deserializer)?))
}
}

I assume it would go the same way for Stores,
as it's pretty much literally a like Signal from the read/new api pov.

I can send a PR with it, if there aren't other subtleties arising from this change, please let me know.

slightly unrelated, but that's what brought me here

might be some kind of XY problem,

I realized serde was missing from Stores when I wanted to use dioxus_sdk's use_storage with a Store<T>.
I know that use_storage gives a Signal<T>, but I needed a Store<T> to access my Type's Lenses...
I'm pretty sure there might be a way to convert the use_storage's Signal into a Store without having nested Signal<Store<T>>, while keeping the Store reactively updating the storage, but I couldn't figure it out...

Thanks forward

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions