Skip to content

Commit

Permalink
Make LayerFn type private
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn committed Dec 28, 2020
1 parent 3ab3fd1 commit d86e41e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
16 changes: 9 additions & 7 deletions tower-layer/src/layer_fn.rs
@@ -1,21 +1,23 @@
use super::Layer;

/// Returns a new `LayerFn` with the given closure.
pub fn layer_fn<T>(f: T) -> LayerFn<T> {
/// Returns a new `impl Layer` with the given closure.
pub fn layer_fn<F, S, T>(f: F) -> impl Layer<S, Service = T> + Clone
where
F: Fn(S) -> T + Clone,
{
LayerFn { f }
}

/// A `Layer` implemented by a closure.
#[derive(Clone, Copy, Debug)]
pub struct LayerFn<F> {
struct LayerFn<F> {
f: F,
}

impl<F, S, Out> Layer<S> for LayerFn<F>
impl<F, S, T> Layer<S> for LayerFn<F>
where
F: Fn(S) -> Out,
F: Fn(S) -> T,
{
type Service = Out;
type Service = T;

fn layer(&self, inner: S) -> Self::Service {
(self.f)(inner)
Expand Down
6 changes: 1 addition & 5 deletions tower-layer/src/lib.rs
Expand Up @@ -17,11 +17,7 @@ mod identity;
mod layer_fn;
mod stack;

pub use self::{
identity::Identity,
layer_fn::{layer_fn, LayerFn},
stack::Stack,
};
pub use self::{identity::Identity, layer_fn::layer_fn, stack::Stack};

/// Decorates a `Service`, transforming either the request or the response.
///
Expand Down

0 comments on commit d86e41e

Please sign in to comment.