Vendor asic-rs 0.8.1 (280 crates, offline builds) + wxWidgets 3.3.3 (pristine + patch queue); UI spec + ADR-0003; M1 on asic-rs
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
use std::{error, fmt};
|
||||
|
||||
/// Error returned if the inner [`Service`] has not been set.
|
||||
///
|
||||
/// [`Service`]: crate::Service
|
||||
#[derive(Debug)]
|
||||
pub struct None(());
|
||||
|
||||
impl None {
|
||||
pub(crate) fn new() -> None {
|
||||
None(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for None {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "None")
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for None {}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
use super::error;
|
||||
use pin_project_lite::pin_project;
|
||||
use std::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
pin_project! {
|
||||
/// Response future returned by [`Optional`].
|
||||
///
|
||||
/// [`Optional`]: crate::util::Optional
|
||||
#[derive(Debug)]
|
||||
pub struct ResponseFuture<T> {
|
||||
#[pin]
|
||||
inner: Option<T>,
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ResponseFuture<T> {
|
||||
pub(crate) fn new(inner: Option<T>) -> ResponseFuture<T> {
|
||||
ResponseFuture { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, T, E> Future for ResponseFuture<F>
|
||||
where
|
||||
F: Future<Output = Result<T, E>>,
|
||||
E: Into<crate::BoxError>,
|
||||
{
|
||||
type Output = Result<T, crate::BoxError>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
match self.project().inner.as_pin_mut() {
|
||||
Some(inner) => inner.poll(cx).map_err(Into::into),
|
||||
None => Poll::Ready(Err(error::None::new().into())),
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
//! Contains [`Optional`] and related types and functions.
|
||||
//!
|
||||
//! See [`Optional`] documentation for more details.
|
||||
|
||||
/// Error types for [`Optional`].
|
||||
pub mod error;
|
||||
/// Future types for [`Optional`].
|
||||
pub mod future;
|
||||
|
||||
use self::future::ResponseFuture;
|
||||
use std::task::{Context, Poll};
|
||||
use tower_service::Service;
|
||||
|
||||
/// Optionally forwards requests to an inner service.
|
||||
///
|
||||
/// If the inner service is [`None`], [`optional::None`] is returned as the response.
|
||||
///
|
||||
/// [`optional::None`]: crate::util::error::optional::None
|
||||
#[derive(Debug)]
|
||||
pub struct Optional<T> {
|
||||
inner: Option<T>,
|
||||
}
|
||||
|
||||
impl<T> Optional<T> {
|
||||
/// Create a new [`Optional`].
|
||||
pub const fn new<Request>(inner: Option<T>) -> Optional<T>
|
||||
where
|
||||
T: Service<Request>,
|
||||
T::Error: Into<crate::BoxError>,
|
||||
{
|
||||
Optional { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, Request> Service<Request> for Optional<T>
|
||||
where
|
||||
T: Service<Request>,
|
||||
T::Error: Into<crate::BoxError>,
|
||||
{
|
||||
type Response = T::Response;
|
||||
type Error = crate::BoxError;
|
||||
type Future = ResponseFuture<T::Future>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
match self.inner {
|
||||
Some(ref mut inner) => match inner.poll_ready(cx) {
|
||||
Poll::Ready(r) => Poll::Ready(r.map_err(Into::into)),
|
||||
Poll::Pending => Poll::Pending,
|
||||
},
|
||||
// None services are always ready
|
||||
None => Poll::Ready(Ok(())),
|
||||
}
|
||||
}
|
||||
|
||||
fn call(&mut self, request: Request) -> Self::Future {
|
||||
let inner = self.inner.as_mut().map(|i| i.call(request));
|
||||
ResponseFuture::new(inner)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user