|
1 |
| -//! Any type storages for [`crate::Memory`]. |
| 1 | +//! Any-type storages for [`Memory`]. |
2 | 2 | //!
|
3 |
| -//! This module contains structs to store arbitrary type using [`std::any::Any`] trait. Also, they can be cloned, and structs in [`serializable`] can be de/serialized. |
| 3 | +//! This module contains structs to store arbitrary types using [`Any`] trait. Also, they can be cloned, and structs in [`serializable`] can be de/serialized. |
4 | 4 | //!
|
5 |
| -//! Basically, all this is just `HashMap<TypeId, Box<dyn Any + static>>` and `HashMap<Id, Box<dyn Any + static>>`, but with helper functions and hacks for cloning and de/serialization. |
| 5 | +//! All this is just `HashMap<TypeId, Box<dyn Any + static>>` and `HashMap<Id, Box<dyn Any + static>>`, but with helper functions and hacks for cloning and de/serialization. |
6 | 6 | //!
|
7 | 7 | //! # Trait requirements
|
8 | 8 | //!
|
9 |
| -//! If you want to store your type here, it must implement `Clone` and `Any` and be `'static`, which means it must not contain references. If you want to store your data in serializable storage, it must implement `serde::Serialize` and `serde::Deserialize` under `persistent` feature. |
| 9 | +//! If you want to store your type here, it must implement `Clone` and `Any` and be `'static`, which means it must not contain references. If you want to store your data in serializable storage, it must implement `serde::Serialize` and `serde::Deserialize` under the `persistent` feature. |
10 | 10 | //!
|
11 | 11 | //! # `AnyMap`
|
12 | 12 | //!
|
13 |
| -//! It stores everything by just type. You should use this map for your widget, when all instances of your widgets can have only one state. E.g. for popup windows, for color picker. |
| 13 | +//! It stores everything by just type. You should use this map for your widget when all instances of your widgets can have only one state. E.g. for popup windows, for color picker. |
14 | 14 | //!
|
15 |
| -//! In order to not have intersections, you should create newtype for anything you try to store here, like: |
| 15 | +//! To not have intersections, you should create newtype for anything you try to store here, like: |
16 | 16 | //! ```rust
|
17 | 17 | //! struct MyEditBool(pub bool);
|
18 | 18 | //! ```
|
19 | 19 | //!
|
20 | 20 | //! # `AnyMapId`
|
21 | 21 | //!
|
22 |
| -//! [`AnyMap`] and [`AnyMapId`] has quite similar interface, except for [`AnyMapId`] you should pass [`crate::Id`] to get and insert things. |
| 22 | +//! [`AnyMap`] and [`AnyMapId`] has a quite similar interface, except for [`AnyMapId`] you should pass [`Id`] to get and insert things. |
23 | 23 | //!
|
24 |
| -//! It stores everything by [`crate::Id`], this should be used when your widget can have different data for different instances of the widget. |
| 24 | +//! It stores everything by [`Id`], this should be used when your widget can have different data for different instances of the widget. |
25 | 25 | //!
|
26 | 26 | //! # `serializable`
|
27 | 27 | //!
|
28 | 28 | //! [`AnyMap`] and [`serializable::AnyMap`] has exactly the same interface, but [`serializable::AnyMap`] only requires serde traits for stored object under `persistent` feature. Same thing for [`AnyMapId`] and [`serializable::AnyMapId`].
|
29 | 29 | //!
|
30 |
| -//! # What could broke |
| 30 | +//! # What could break |
31 | 31 | //!
|
32 |
| -//! Things here could broke only when you trying to load this from file. |
| 32 | +//! Things here could break only when you trying to load this from file. |
33 | 33 | //!
|
34 |
| -//! First, serialized `TypeId` in [`serializable::AnyMap`] could broke, if you updated version of Rust compiler between runs. |
| 34 | +//! First, serialized `TypeId` in [`serializable::AnyMap`] could broke if you updated the version of the Rust compiler between runs. |
35 | 35 | //!
|
36 |
| -//! Second, count and reset all instances of type in [`serializable::AnyMapId`] could return incorrect value for the same reason. |
| 36 | +//! Second, count and reset all instances of a type in [`serializable::AnyMapId`] could return an incorrect value for the same reason. |
37 | 37 | //!
|
38 |
| -//! Deserialization errors of loaded elements of these storages can be determined only when you call `get_...` functions, they not logged and not provided to user, on this errors value is just replaced with `or_insert()`/default value. |
| 38 | +//! Deserialization errors of loaded elements of these storages can be determined only when you call `get_...` functions, they not logged and not provided to a user, on this errors value is just replaced with `or_insert()`/default value. |
39 | 39 | //!
|
40 | 40 | //! # When not to use this
|
41 | 41 | //!
|
42 |
| -//! Basically, this is not for important widget data. Some errors just ignored and correct value of type is inserted when you call. This is done in order to simple interface. |
| 42 | +//! This is not for important widget data. Some errors are just ignored and the correct value of type is inserted when you call. This is done to more simple interface. |
43 | 43 | //!
|
44 |
| -//! You shouldn't use any map here when you need very reliable state storage with rich error-handling. For this purposes you should create your own `Memory` struct and pass it everywhere you need it. Then, you should de/serialize it by yourself, handling all serialization or other errors as you wish. |
| 44 | +//! You shouldn't use any map here when you need very reliable state storage with rich error-handling. For this purpose you should create your own `Memory` struct and pass it everywhere you need it. Then, you should de/serialize it by yourself, handling all serialization or other errors as you wish. |
| 45 | +//! |
| 46 | +//! [`Id`]: crate::Id |
| 47 | +//! [`Memory`]: crate::Memory |
| 48 | +//! [`Any`]: std::any::Any |
45 | 49 |
|
46 | 50 | mod any_map;
|
47 | 51 | mod element;
|
|
0 commit comments