mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: rename structs
This commit is contained in:
@ -5,14 +5,14 @@ use crate::{
|
||||
};
|
||||
use std::{any::type_name, ops::Deref, sync::Arc};
|
||||
|
||||
pub struct Unit<T: ?Sized + Send + Sync>(Arc<T>);
|
||||
pub struct AppData<T: ?Sized + Send + Sync>(Arc<T>);
|
||||
|
||||
impl<T> Unit<T>
|
||||
impl<T> AppData<T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
pub fn new(data: T) -> Self {
|
||||
Unit(Arc::new(data))
|
||||
AppData(Arc::new(data))
|
||||
}
|
||||
|
||||
pub fn get_ref(&self) -> &T {
|
||||
@ -20,7 +20,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for Unit<T>
|
||||
impl<T> Deref for AppData<T>
|
||||
where
|
||||
T: ?Sized + Send + Sync,
|
||||
{
|
||||
@ -31,25 +31,25 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for Unit<T>
|
||||
impl<T> Clone for AppData<T>
|
||||
where
|
||||
T: ?Sized + Send + Sync,
|
||||
{
|
||||
fn clone(&self) -> Unit<T> {
|
||||
Unit(self.0.clone())
|
||||
fn clone(&self) -> AppData<T> {
|
||||
AppData(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Arc<T>> for Unit<T>
|
||||
impl<T> From<Arc<T>> for AppData<T>
|
||||
where
|
||||
T: ?Sized + Send + Sync,
|
||||
{
|
||||
fn from(arc: Arc<T>) -> Self {
|
||||
Unit(arc)
|
||||
AppData(arc)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> FromRequest for Unit<T>
|
||||
impl<T> FromRequest for AppData<T>
|
||||
where
|
||||
T: ?Sized + Send + Sync + 'static,
|
||||
{
|
||||
@ -58,7 +58,7 @@ where
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &EventRequest, _: &mut Payload) -> Self::Future {
|
||||
if let Some(data) = req.module_data::<Unit<T>>() {
|
||||
if let Some(data) = req.module_data::<AppData<T>>() {
|
||||
ready(Ok(data.clone()))
|
||||
} else {
|
||||
let msg = format!("Failed to get the module data of type: {}", type_name::<T>());
|
||||
|
@ -13,7 +13,7 @@ use pin_project::pin_project;
|
||||
|
||||
use crate::{
|
||||
errors::{DispatchError, InternalError},
|
||||
module::{container::ModuleDataMap, Unit},
|
||||
module::{container::ModuleDataMap, AppData},
|
||||
request::{payload::Payload, EventRequest, FromRequest},
|
||||
response::{EventResponse, Responder},
|
||||
service::{
|
||||
@ -75,7 +75,7 @@ impl Module {
|
||||
}
|
||||
|
||||
pub fn data<D: 'static + Send + Sync>(mut self, data: D) -> Self {
|
||||
Arc::get_mut(&mut self.module_data).unwrap().insert(Unit::new(data));
|
||||
Arc::get_mut(&mut self.module_data).unwrap().insert(AppData::new(data));
|
||||
|
||||
self
|
||||
}
|
||||
|
Reference in New Issue
Block a user