Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
TTWNO committed Jun 17, 2024
1 parent e4b7e8d commit 82479f2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 49 deletions.
8 changes: 3 additions & 5 deletions cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,9 @@ pub struct Cache {
}

impl std::fmt::Debug for Cache {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(
&format!("Cache {{ by_id: ...{} items..., .. }}", self.by_id.len() )
)
}
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&format!("Cache {{ by_id: ...{} items..., .. }}", self.by_id.len()))
}
}

// N.B.: we are using std RwLockes internally here, within the cache hashmap
Expand Down
2 changes: 1 addition & 1 deletion odilia/src/tower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pub mod async_try;
pub mod from_state;
pub mod handler;
pub mod iter_svc;
pub mod service_set;
pub mod state_svc;
pub mod sync_try;
pub mod service_set;
pub use handler::Handler;

pub mod handlers;
Expand Down
84 changes: 41 additions & 43 deletions odilia/src/tower/service_set.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::collections::BTreeMap;
use odilia_common::command::{OdiliaCommandDiscriminants, OdiliaCommand};
use futures::future::err;
use odilia_common::command::CommandTypeDynamic;
use odilia_common::command::{OdiliaCommand, OdiliaCommandDiscriminants};
use odilia_common::errors::OdiliaError;
use tower::Service;
use tower::util::BoxCloneService;
use tower::service_fn;
use futures::future::err;
use std::collections::BTreeMap;
use std::future::Future;
use std::task::{Context, Poll};
use tower::service_fn;
use tower::util::BoxCloneService;
use tower::Service;

/// A series of services which are executed in the order they are placed in the [`ServiceSet::new`]
/// initializer.
Expand All @@ -18,47 +18,45 @@ use std::task::{Context, Poll};
/// returned and can safely be unwrapped _from the caller function_.
#[derive(Clone)]
pub struct ServiceSet<S> {
services: Vec<S>,
services: Vec<S>,
}
impl<S> Default for ServiceSet<S> {
fn default() -> Self {
ServiceSet {
services: vec![],
}
}
fn default() -> Self {
ServiceSet { services: vec![] }
}
}
impl<S> ServiceSet<S> {
pub fn new<I: IntoIterator<Item = S>>(services: I) -> Self {
ServiceSet {
services: services.into_iter().collect(),
}
}
pub fn push(&mut self, svc: S) {
self.services.push(svc);
}
pub fn new<I: IntoIterator<Item = S>>(services: I) -> Self {
ServiceSet { services: services.into_iter().collect() }
}
pub fn push(&mut self, svc: S) {
self.services.push(svc);
}
}

impl<S, Req> Service<Req> for ServiceSet<S>
where S: Service<Req> + Clone,
Req: Clone {
type Response = Vec<Result<S::Response, S::Error>>;
type Error = S::Error;
type Future = impl Future<Output = Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
for mut svc in &mut self.services {
let _ = svc.poll_ready(cx)?;
}
Poll::Ready(Ok(()))
}
fn call(&mut self, req: Req) -> Self::Future {
let services = self.services.clone();
async move {
let mut results = vec![];
for mut svc in services {
let result = svc.call(req.clone()).await;
results.push(result);
}
Ok(results)
}
}
impl<S, Req> Service<Req> for ServiceSet<S>
where
S: Service<Req> + Clone,
Req: Clone,
{
type Response = Vec<Result<S::Response, S::Error>>;
type Error = S::Error;
type Future = impl Future<Output = Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
for mut svc in &mut self.services {
let _ = svc.poll_ready(cx)?;
}
Poll::Ready(Ok(()))
}
fn call(&mut self, req: Req) -> Self::Future {
let services = self.services.clone();
async move {
let mut results = vec![];
for mut svc in services {
let result = svc.call(req.clone()).await;
results.push(result);
}
Ok(results)
}
}
}

0 comments on commit 82479f2

Please sign in to comment.