Move ChannelList, UserStore into client crate

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2021-10-04 17:30:11 -07:00
parent 94209d2b6d
commit bbb27b9654
15 changed files with 83 additions and 76 deletions

View file

@ -1,20 +1,15 @@
use crate::{
assets::Assets,
channel::ChannelList,
http::{HttpClient, Request, Response, ServerResponse},
language,
settings::{self, ThemeRegistry},
user::UserStore,
AppState,
};
use anyhow::Result;
use buffer::LanguageRegistry;
use client::Client;
use futures::{future::BoxFuture, Future};
use client::{http::ServerResponse, test::FakeHttpClient, ChannelList, Client, UserStore};
use gpui::MutableAppContext;
use parking_lot::Mutex;
use project::fs::FakeFs;
use std::{fmt, sync::Arc};
use std::sync::Arc;
#[cfg(test)]
#[ctor::ctor]
@ -41,33 +36,3 @@ pub fn test_app_state(cx: &mut MutableAppContext) -> Arc<AppState> {
fs: Arc::new(FakeFs::new()),
})
}
pub struct FakeHttpClient {
handler:
Box<dyn 'static + Send + Sync + Fn(Request) -> BoxFuture<'static, Result<ServerResponse>>>,
}
impl FakeHttpClient {
pub fn new<Fut, F>(handler: F) -> Arc<dyn HttpClient>
where
Fut: 'static + Send + Future<Output = Result<ServerResponse>>,
F: 'static + Send + Sync + Fn(Request) -> Fut,
{
Arc::new(Self {
handler: Box::new(move |req| Box::pin(handler(req))),
})
}
}
impl fmt::Debug for FakeHttpClient {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FakeHttpClient").finish()
}
}
impl HttpClient for FakeHttpClient {
fn send<'a>(&'a self, req: Request) -> BoxFuture<'a, Result<Response>> {
let future = (self.handler)(req);
Box::pin(async move { future.await.map(Into::into) })
}
}