Skip to content

Commit 7a5eecb

Browse files
optozoraxemilk
andauthored
Apply suggestions from code review
Co-authored-by: Emil Ernerfeldt <[email protected]>
1 parent 6e287ff commit 7a5eecb

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

egui/src/any/any_map.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ use crate::any::element::{AnyMapElement, AnyMapTrait};
22
use std::any::TypeId;
33
use std::collections::HashMap;
44

5-
/// Stores object of any type.
5+
/// Maps types to a single instance of that type.
6+
///
7+
/// Used to store state per widget type. In effect a sort of singleton storage.
8+
/// Similar to [the `typemap` crate](https://docs.rs/typemap/0.3.3/typemap/) but allows serialization
9+
/// (if compiled with the `persistence` feature).
610
#[derive(Clone, Debug, Default)]
711
pub struct AnyMap(HashMap<TypeId, AnyMapElement>);
812

egui/src/any/element.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::any::{Any, TypeId};
22
use std::fmt;
33

4+
/// Like [`std::any::Any`], but also implements `Clone`.
45
pub(crate) struct AnyMapElement {
56
value: Box<dyn Any + 'static>,
67
clone_fn: fn(&Box<dyn Any + 'static>) -> Box<dyn Any + 'static>,

egui/src/any/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//!
99
//! 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.
1010
//!
11-
//! # `AnyMap`
11+
//! # [`AnyMap`]
1212
//!
1313
//! 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.
1414
//!
@@ -17,7 +17,7 @@
1717
//! struct MyEditBool(pub bool);
1818
//! ```
1919
//!
20-
//! # `AnyMapId`
20+
//! # [`AnyMapId`]
2121
//!
2222
//! [`AnyMap`] and [`AnyMapId`] has a quite similar interface, except for [`AnyMapId`] you should pass [`Id`] to get and insert things.
2323
//!

egui/src/any/serializable/any_map.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ use {
1212
std::any::TypeId,
1313
};
1414

15-
/// Stores object of any type and can be de/serialized.
15+
/// Maps types to a single instance of that type.
16+
///
17+
/// Used to store state per widget type. In effect a sort of singleton storage.
18+
/// Similar to [the `typemap` crate](https://docs.rs/typemap/0.3.3/typemap/) but allows serialization
19+
/// (if compiled with the `persistence` feature).
1620
#[derive(Clone, Debug, Default)]
1721
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
1822
pub struct AnyMap(HashMap<TypeId, AnyMapElement>);

egui/src/any/serializable/element.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'de> Deserialize<'de> for AnyMapElement {
4545
type Value = String;
4646

4747
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
48-
formatter.write_str("string that contains data json")
48+
formatter.write_str("string that contains RON (Rust Object Notation)")
4949
}
5050

5151
fn visit_str<E: serde::de::Error>(self, value: &str) -> Result<Self::Value, E> {

0 commit comments

Comments
 (0)