mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-23 21:51:06 +01:00
inline simple future functions
This commit is contained in:
parent
705b31230f
commit
6a9f13c8b4
@ -22,16 +22,19 @@ impl Counter {
|
||||
}
|
||||
|
||||
/// Create new counter guard, incrementing the counter.
|
||||
#[inline]
|
||||
pub fn get(&self) -> CounterGuard {
|
||||
CounterGuard::new(self.0.clone())
|
||||
}
|
||||
|
||||
/// Returns true if counter is below capacity. Otherwise, register to wake task when it is.
|
||||
#[inline]
|
||||
pub fn available(&self, cx: &mut task::Context<'_>) -> bool {
|
||||
self.0.available(cx)
|
||||
}
|
||||
|
||||
/// Get total number of acquired guards.
|
||||
#[inline]
|
||||
pub fn total(&self) -> usize {
|
||||
self.0.count.get()
|
||||
}
|
||||
|
@ -40,11 +40,13 @@ pin_project! {
|
||||
|
||||
impl<L, R> Either<L, R> {
|
||||
/// Creates new `Either` using left variant.
|
||||
#[inline]
|
||||
pub fn left(value: L) -> Either<L, R> {
|
||||
Either::Left { value }
|
||||
}
|
||||
|
||||
/// Creates new `Either` using right variant.
|
||||
#[inline]
|
||||
pub fn right(value: R) -> Either<L, R> {
|
||||
Either::Right { value }
|
||||
}
|
||||
@ -52,6 +54,7 @@ impl<L, R> Either<L, R> {
|
||||
|
||||
impl<T> Either<T, T> {
|
||||
/// Unwraps into inner value when left and right have a common type.
|
||||
#[inline]
|
||||
pub fn into_inner(self) -> T {
|
||||
match self {
|
||||
Either::Left { value } => value,
|
||||
@ -67,6 +70,7 @@ where
|
||||
{
|
||||
type Output = L::Output;
|
||||
|
||||
#[inline]
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
match self.project() {
|
||||
EitherProj::Left { value } => value.poll(cx),
|
||||
|
@ -8,6 +8,7 @@ use core::{
|
||||
};
|
||||
|
||||
/// Creates a future driven by the provided function that receives a task context.
|
||||
#[inline]
|
||||
pub fn poll_fn<F, T>(f: F) -> PollFn<F>
|
||||
where
|
||||
F: FnMut(&mut Context<'_>) -> Poll<T>,
|
||||
@ -34,6 +35,7 @@ where
|
||||
{
|
||||
type Output = T;
|
||||
|
||||
#[inline]
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
(self.f)(cx)
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ impl<T> Future for Ready<T> {
|
||||
/// let a = ready(1);
|
||||
/// assert_eq!(a.into_inner(), 1);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn ready<T>(val: T) -> Ready<T> {
|
||||
Ready { val: Some(val) }
|
||||
}
|
||||
@ -80,6 +81,7 @@ pub fn ready<T>(val: T) -> Ready<T> {
|
||||
/// assert_eq!(a.await, Ok(1));
|
||||
/// # }
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn ok<T, E>(val: T) -> Ready<Result<T, E>> {
|
||||
Ready { val: Some(Ok(val)) }
|
||||
}
|
||||
@ -95,6 +97,7 @@ pub fn ok<T, E>(val: T) -> Ready<Result<T, E>> {
|
||||
/// assert_eq!(a.await, Err(1));
|
||||
/// # }
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn err<T, E>(err: E) -> Ready<Result<T, E>> {
|
||||
Ready {
|
||||
val: Some(Err(err)),
|
||||
|
Loading…
Reference in New Issue
Block a user