X-Git-Url: https://git.chrismorgan.info/anymap/blobdiff_plain/764038fe6e3f5a28270a874bce2561924a316a20..0d9f2cfe4629fd5d38de9a0a82cf04139c4740ed:/src/lib.rs?ds=sidebyside diff --git a/src/lib.rs b/src/lib.rs index a53a2d8..1ad840b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,6 @@ -//! This crate provides the `AnyMap` type, a safe and convenient store for one value of each type. +//! This crate provides a safe and convenient store for one value of each type. +//! +//! Your starting point is [`Map`]. It has an example. #![warn(missing_docs, unused_results)] @@ -95,12 +97,27 @@ pub mod raw; /// The type parameter `A` allows you to use a different value type; normally you will want it to /// be `std::any::Any`, but there are other choices: /// -/// - If you want the entire map to be cloneable, use `CloneAny` instead of `Any`. -/// - You can add on `+ Send` or `+ Send + Sync` (e.g. `Map`) to add those bounds. +/// - If you want the entire map to be cloneable, use `CloneAny` instead of `Any`; with that, you +/// can only add types that implement `Clone` to the map. +/// - You can add on `+ Send` or `+ Send + Sync` (e.g. `Map`) to add those auto +/// traits. +/// +/// Cumulatively, there are thus six forms of map: +/// +/// - [Map]<dyn [std::any::Any]>, also spelled [`AnyMap`] for convenience. +/// - [Map]<dyn [std::any::Any] + Send> +/// - [Map]<dyn [std::any::Any] + Send + Sync> +/// - [Map]<dyn [CloneAny]> +/// - [Map]<dyn [CloneAny] + Send> +/// - [Map]<dyn [CloneAny] + Send + Sync> +/// +/// ## Example +/// +/// (Here using the [`AnyMap`] convenience alias; the first line could use +/// [anymap::Map][Map]::<[std::any::Any]>::new() instead if desired.) /// /// ```rust -/// # use anymap::AnyMap; -/// let mut data = AnyMap::new(); +/// let mut data = anymap::AnyMap::new(); /// assert_eq!(data.get(), None::<&i32>); /// data.insert(42i32); /// assert_eq!(data.get(), Some(&42i32)); @@ -135,7 +152,7 @@ impl Clone for Map where Box: Clone { } } -/// The most common type of `Map`: just using `Any`. +/// The most common type of `Map`: just using `Any`; [Map]<dyn [Any]>. /// /// Why is this a separate type alias rather than a default value for `Map`? `Map::new()` /// doesn’t seem to be happy to infer that it should go with the default value. @@ -219,10 +236,10 @@ impl AsMut> for Map { } } -impl Into> for Map { +impl From> for RawMap { #[inline] - fn into(self) -> RawMap { - self.raw + fn from(map: Map) -> RawMap { + map.raw } }