Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Emil Ernerfeldt <[email protected]>
  • Loading branch information
optozorax and emilk authored Mar 28, 2021
1 parent 6e287ff commit 7a5eecb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion egui/src/any/any_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use crate::any::element::{AnyMapElement, AnyMapTrait};
use std::any::TypeId;
use std::collections::HashMap;

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

Expand Down
1 change: 1 addition & 0 deletions egui/src/any/element.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::any::{Any, TypeId};
use std::fmt;

/// Like [`std::any::Any`], but also implements `Clone`.
pub(crate) struct AnyMapElement {
value: Box<dyn Any + 'static>,
clone_fn: fn(&Box<dyn Any + 'static>) -> Box<dyn Any + 'static>,
Expand Down
4 changes: 2 additions & 2 deletions egui/src/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//!
//! 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.
//!
//! # `AnyMap`
//! # [`AnyMap`]
//!
//! 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.
//!
Expand All @@ -17,7 +17,7 @@
//! struct MyEditBool(pub bool);
//! ```
//!
//! # `AnyMapId`
//! # [`AnyMapId`]
//!
//! [`AnyMap`] and [`AnyMapId`] has a quite similar interface, except for [`AnyMapId`] you should pass [`Id`] to get and insert things.
//!
Expand Down
6 changes: 5 additions & 1 deletion egui/src/any/serializable/any_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ use {
std::any::TypeId,
};

/// Stores object of any type and can be de/serialized.
/// Maps types to a single instance of that type.
///
/// Used to store state per widget type. In effect a sort of singleton storage.
/// Similar to [the `typemap` crate](https://docs.rs/typemap/0.3.3/typemap/) but allows serialization
/// (if compiled with the `persistence` feature).
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct AnyMap(HashMap<TypeId, AnyMapElement>);
Expand Down
2 changes: 1 addition & 1 deletion egui/src/any/serializable/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'de> Deserialize<'de> for AnyMapElement {
type Value = String;

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

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

0 comments on commit 7a5eecb

Please sign in to comment.