mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-20 01:08:55 +00:00
Prelude: do away with GetCloned
This commit is contained in:
parent
2e718c3e60
commit
0fefb455ea
1 changed files with 2 additions and 31 deletions
|
@ -13,42 +13,13 @@ pub use pagination::Pagination;
|
||||||
pub use reaction_watch::{ReactionHandler, ReactionWatcher};
|
pub use reaction_watch::{ReactionHandler, ReactionWatcher};
|
||||||
|
|
||||||
/// The global app data.
|
/// The global app data.
|
||||||
pub type AppData = Arc<RwLock<ShareMap>>;
|
pub type AppData = Arc<RwLock<TypeMap>>;
|
||||||
|
|
||||||
/// The HTTP client.
|
/// The HTTP client.
|
||||||
pub struct HTTPClient;
|
pub struct HTTPClient;
|
||||||
|
|
||||||
impl TypeMapKey for HTTPClient {
|
impl TypeMapKey for HTTPClient {
|
||||||
type Value = reqwest::blocking::Client;
|
type Value = reqwest::Client;
|
||||||
}
|
|
||||||
|
|
||||||
/// The TypeMap trait that allows TypeMaps to quickly get a clonable item.
|
|
||||||
pub trait GetCloned {
|
|
||||||
/// Gets an item from the store, cloned.
|
|
||||||
fn get_cloned<T>(&self) -> T::Value
|
|
||||||
where
|
|
||||||
T: TypeMapKey,
|
|
||||||
T::Value: Clone + Send + Sync;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetCloned for ShareMap {
|
|
||||||
fn get_cloned<T>(&self) -> T::Value
|
|
||||||
where
|
|
||||||
T: TypeMapKey,
|
|
||||||
T::Value: Clone + Send + Sync,
|
|
||||||
{
|
|
||||||
self.get::<T>().cloned().expect("Should be there")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GetCloned for AppData {
|
|
||||||
fn get_cloned<T>(&self) -> T::Value
|
|
||||||
where
|
|
||||||
T: TypeMapKey,
|
|
||||||
T::Value: Clone + Send + Sync,
|
|
||||||
{
|
|
||||||
self.read().get::<T>().cloned().expect("Should be there")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod prelude_commands {
|
pub mod prelude_commands {
|
||||||
|
|
Loading…
Add table
Reference in a new issue