#![doc(html_root_url = "https://docs.rs/finchers-ext/0.11.0")]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![deny(warnings)]
extern crate either;
#[macro_use]
extern crate finchers_core;
pub mod option;
pub mod result;
mod abort;
mod all;
mod and;
mod inspect;
mod just;
mod lazy;
mod left;
mod lift;
mod map;
mod map_async;
mod maybe_done;
mod or;
mod right;
pub use abort::{abort, Abort};
pub use all::{all, All};
pub use and::And;
pub use inspect::Inspect;
pub use just::{just, Just};
pub use lazy::{lazy, Lazy};
pub use left::Left;
pub use lift::Lift;
pub use map::Map;
pub use map_async::MapAsync;
pub use or::Or;
pub use right::Right;
#[doc(inline)]
pub use option::EndpointOptionExt;
#[doc(inline)]
pub use result::EndpointResultExt;
use finchers_core::endpoint::{assert_output, Endpoint, IntoEndpoint};
use finchers_core::task::IntoTask;
pub trait EndpointExt: Endpoint + Sized {
#[inline(always)]
fn as_t<T>(self) -> Self
where
Self: Endpoint<Output = T>,
{
self
}
fn and<E>(self, e: E) -> And<Self, E::Endpoint>
where
E: IntoEndpoint,
Self::Output: Send,
E::Output: Send,
{
assert_output::<_, (Self::Output, <E::Endpoint as Endpoint>::Output)>(self::and::new(self, e))
}
fn left<E>(self, e: E) -> Left<Self, E::Endpoint>
where
E: IntoEndpoint,
{
assert_output::<_, Self::Output>(self::left::new(self, e))
}
fn right<E>(self, e: E) -> Right<Self, E::Endpoint>
where
E: IntoEndpoint,
{
assert_output::<_, E::Output>(self::right::new(self, e))
}
fn or<E>(self, e: E) -> Or<Self, E::Endpoint>
where
E: IntoEndpoint<Output = Self::Output>,
{
assert_output::<_, Self::Output>(self::or::new(self, e))
}
fn lift(self) -> Lift<Self> {
assert_output::<_, Option<Self::Output>>(self::lift::new(self))
}
fn map<F, U>(self, f: F) -> Map<Self, F>
where
F: FnOnce(Self::Output) -> U + Clone + Send + Sync,
{
assert_output::<_, F::Output>(self::map::new(self, f))
}
fn inspect<F>(self, f: F) -> Inspect<Self, F>
where
F: FnOnce(&Self::Output) + Clone + Send + Sync,
{
assert_output::<_, Self::Output>(self::inspect::new(self, f))
}
fn map_async<F, T>(self, f: F) -> MapAsync<Self, F>
where
F: FnOnce(Self::Output) -> T + Clone + Send + Sync,
T: IntoTask,
T::Task: Send,
{
assert_output::<_, T::Output>(self::map_async::new(self, f))
}
}
impl<E: Endpoint> EndpointExt for E {}