refactor: rename structs

This commit is contained in:
appflowy
2022-02-25 22:27:44 +08:00
parent 441627783b
commit 6078e46d3d
50 changed files with 707 additions and 699 deletions

View File

@ -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>());

View File

@ -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
}