# future.rs - source
Source of the Rust file `crates/tlsn/src/prover/future.rs`.

Skip to main content

#
tlsn/prover/
future.rs

    1//! This module collects futures which are used by the [Prover].
    2
    3use futures::{AsyncRead, AsyncWrite, Future, FutureExt, future::FusedFuture};
    4use std::{pin::Pin, task::Poll};
    5
    6use crate::{
    7    Error,
    8    prover::{Prover, ProverControl, state},
    9};
    10
    11/// Prover future which must be polled for the TLS connection to make progress.
    12pub struct ProverFuture<S> {
    13    pub(crate) prover: Option<Prover<state::Connected<S>>>,
    14}
    15
    16impl<S> ProverFuture<S> {
    17    /// Returns a controller for the prover for advanced functionality.
    18    pub fn control(&self) -> ProverControl {
    19        let decrypt_state = self
    20            .prover
    21            .as_ref()
    22            .expect("prover should be available")
    23            .state
    24            .tls_client
    25            .decrypt();
    26
    27        ProverControl { decrypt_state }
    28    }
    29}
    30
    31impl<S> Future for ProverFuture<S>
    32where
    33    S: AsyncRead + AsyncWrite + Send + Unpin + 'static,
    34{
    35    type Output = Result<Prover<state::Committed>, Error>;
    36
    37    fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
    38        if let Some(prover) = self.prover.as_mut() {
    39            let poll = prover.poll_unpin(cx)?;
    40
    41            if poll.is_ready() {
    42                let prover = self.prover.take().expect("prover should be available");
    43                return Poll::Ready(prover.finish());
    44            }
    45        }
    46        Poll::Pending
    47    }
    48}
    49
    50impl<S> FusedFuture for ProverFuture<S>
    51where
    52    S: AsyncRead + AsyncWrite + Send + Unpin + 'static,
    53{
    54    fn is_terminated(&self) -> bool {
    55        self.prover.is_none()
    56    }
    57}