/// Automatically defines the `CollectionRef::upcast_item_ref` function using the /// covariance of the `ItemRef<'a>` type with regards to `'a`. /// /// ## Example /// /// ``` /// use cc_traits::{Collection, CollectionRef, covariant_item_ref}; /// /// pub struct MyVec(Vec); /// /// impl Collection for MyVec { /// type Item = T; /// } /// /// impl CollectionRef for MyVec { /// type ItemRef<'a> /// = &'a T where Self: 'a; /// /// covariant_item_ref!(); /// } /// ``` #[macro_export] macro_rules! covariant_item_ref { () => { fn upcast_item_ref<'short, 'long: 'short>(r: Self::ItemRef<'long>) -> Self::ItemRef<'short> where Self: 'long, { r } }; } /// Automatically defines the `CollectionMut::upcast_item_mut` function using the /// covariance of the `ItemMut<'a>` type with regards to `'a`. /// /// ## Example /// /// ``` /// use cc_traits::{Collection, CollectionMut, covariant_item_mut}; /// /// pub struct MyVec(Vec); /// /// impl Collection for MyVec { /// type Item = T; /// } /// /// impl CollectionMut for MyVec { /// type ItemMut<'a> /// = &'a mut T where Self: 'a; /// /// covariant_item_mut!(); /// } /// ``` #[macro_export] macro_rules! covariant_item_mut { () => { fn upcast_item_mut<'short, 'long: 'short>(r: Self::ItemMut<'long>) -> Self::ItemMut<'short> where Self: 'long, { r } }; } /// Automatically defines the `KeyedRef::upcast_item_ref` function using the /// covariance of the `KeyRef<'a>` type with regards to `'a`. /// /// ## Example /// /// ``` /// use cc_traits::{Collection, Keyed, KeyedRef, covariant_key_ref}; /// /// pub struct MyMap(std::collections::HashMap); /// /// impl Collection for MyMap { /// type Item = V; /// } /// /// impl Keyed for MyMap { /// type Key = K; /// } /// /// impl KeyedRef for MyMap { /// type KeyRef<'a> /// = &'a K where Self: 'a; /// /// covariant_key_ref!(); /// } /// ``` #[macro_export] macro_rules! covariant_key_ref { () => { fn upcast_key_ref<'short, 'long: 'short>(r: Self::KeyRef<'long>) -> Self::KeyRef<'short> where Self: 'long, { r } }; } /// Automatically defines the `CollectionMut::upcast_item_mut` function using the /// covariance of the `ItemMut<'a>` type with regards to `'a`. /// /// ## Example /// /// ``` /// use cc_traits::{Collection, CollectionMut, SimpleCollectionMut, covariant_item_mut, simple_collection_mut}; /// /// pub struct MyVec(Vec); /// /// impl Collection for MyVec { /// type Item = T; /// } /// /// impl CollectionMut for MyVec { /// type ItemMut<'a> /// = &'a mut T where Self: 'a; /// /// covariant_item_mut!(); /// } /// /// impl SimpleCollectionMut for MyVec { /// simple_collection_mut!(); /// } /// ``` #[macro_export] macro_rules! simple_collection_mut { () => { fn into_mut<'r>(r: Self::ItemMut<'r>) -> &'r mut Self::Item where Self: 'r, { r } }; } /// Automatically defines the `SimpleCollectionRef::into_ref` function. /// /// ## Example /// /// ``` /// use cc_traits::{Collection, CollectionRef, SimpleCollectionRef, covariant_item_ref, simple_collection_ref}; /// /// pub struct MyVec(Vec); /// /// impl Collection for MyVec { /// type Item = T; /// } /// /// impl CollectionRef for MyVec { /// type ItemRef<'a> /// = &'a T where Self: 'a; /// /// covariant_item_ref!(); /// } /// /// impl SimpleCollectionRef for MyVec { /// simple_collection_ref!(); /// } /// ``` #[macro_export] macro_rules! simple_collection_ref { () => { fn into_ref<'r>(r: Self::ItemRef<'r>) -> &'r Self::Item where Self: 'r, { r } }; } /// Automatically defines the `SimpleKeyedRef::into_ref` function. /// /// ## Example /// /// ``` /// use cc_traits::{Collection, Keyed, KeyedRef, SimpleKeyedRef, covariant_key_ref, simple_keyed_ref}; /// /// pub struct MyMap(std::collections::HashMap); /// /// impl Collection for MyMap { /// type Item = V; /// } /// /// impl Keyed for MyMap { /// type Key = K; /// } /// /// impl KeyedRef for MyMap { /// type KeyRef<'a> /// = &'a K where Self: 'a; /// /// covariant_key_ref!(); /// } /// /// impl SimpleKeyedRef for MyMap { /// simple_keyed_ref!(); /// } /// ``` #[macro_export] macro_rules! simple_keyed_ref { () => { fn into_ref<'r>(r: Self::KeyRef<'r>) -> &'r Self::Key where Self: 'r, { r } }; }