@@ -1807,6 +1807,28 @@ impl core::fmt::Debug for AllStoragesMemoryUsage<'_> {
18071807#[ cfg( feature = "serde1" ) ]
18081808impl AllStorages {
18091809 /// Serializes the view using the provided serializer.
1810+ ///
1811+ /// ### Example
1812+ ///
1813+ /// ```
1814+ /// use shipyard::{AllStoragesViewMut, Component, View, World};
1815+ ///
1816+ /// #[derive(Component, serde::Serialize)]
1817+ /// struct Name(String);
1818+ ///
1819+ /// let world = World::new();
1820+ /// let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
1821+ ///
1822+ /// let eid1 = all_storages.add_entity(Name("Alice".to_string()));
1823+ ///
1824+ /// let mut serialized = Vec::new();
1825+ /// all_storages
1826+ /// .serialize::<_, View<Name>>(&mut serde_json::ser::Serializer::new(&mut serialized))
1827+ /// .unwrap_or_else(|_| panic!());
1828+ ///
1829+ /// let serialized_str = String::from_utf8(serialized).unwrap();
1830+ /// assert_eq!(serialized_str, r#"[[{"index":0,"gen":0},"Alice"]]"#);
1831+ /// ```
18101832 pub fn serialize < ' a , S : serde:: Serializer , V : Borrow > (
18111833 & ' a self ,
18121834 serializer : S ,
@@ -1826,6 +1848,37 @@ impl AllStorages {
18261848 }
18271849
18281850 /// Deserializes the view using the provided deserializer.
1851+ ///
1852+ /// ### Example
1853+ ///
1854+ /// ```
1855+ /// use shipyard::{AllStoragesViewMut, Component, EntityId, ViewMut, World};
1856+ ///
1857+ /// #[derive(Component, serde::Deserialize)]
1858+ /// struct Name(String);
1859+ ///
1860+ /// let world = World::new();
1861+ /// let mut all_storages = world.borrow::<AllStoragesViewMut>().unwrap();
1862+ ///
1863+ /// let mut serialized = r#"[[{"index":0,"gen":0},"Alice"]]"#;
1864+ /// all_storages
1865+ /// .deserialize::<_, ViewMut<Name>>(&mut serde_json::de::Deserializer::from_str(serialized))
1866+ /// .unwrap_or_else(|_| panic!());
1867+ ///
1868+ /// let alice_eid = EntityId::new_from_index_and_gen(0, 0);
1869+ /// assert_eq!(all_storages.get::<&Name>(alice_eid).unwrap().0, "Alice");
1870+ ///
1871+ /// // Careful here, the World is not in a stable state
1872+ ///
1873+ /// assert_eq!(all_storages.is_entity_alive(alice_eid), false);
1874+ ///
1875+ /// // We can use World::spawn for example to fix the problem
1876+ /// // another solution would be to serialize EntitiesViewMut
1877+ ///
1878+ /// all_storages.spawn(alice_eid);
1879+ ///
1880+ /// assert_eq!(all_storages.is_entity_alive(alice_eid), true);
1881+ /// ```
18291882 pub fn deserialize < ' a , ' de , D : serde:: Deserializer < ' de > , V : Borrow > (
18301883 & ' a self ,
18311884 deserializer : D ,
0 commit comments