Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  bodyt.rs

  Sprache: Rust
 

use std::pin::Pin;
use std::task::{Context, Poll};

use bytes::Buf;
use bytes::Bytes;
use futures_util::StreamExt;
use http_body::Frame;
use http_body_util::{combinators::BoxBody, BodyExt};

#[derive(Debug)]
pub struct Body(BoxBody<Bytes, crate::Error>);

impl Default for Body {
    fn default() -> Self {
        Body::empty()
    }
}

impl http_body::Body for Body {
    type Data = Bytes;
    type Error = crate::Error;

    fn poll_frame(
        mut self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
        Pin::new(&mut self.0).poll_frame(cx)
    }

    fn is_end_stream(&self) -> bool {
        self.0.is_end_stream()
    }

    fn size_hint(&self) -> http_body::SizeHint {
        self.0.size_hint()
    }
}

impl Body {
    pub(cratefn empty() -> Self {
        Body(
            http_body_util::Empty::<Bytes>::new()
                .map_err(crate::Error::new)
                .boxed(),
        )
    }

    pub(cratefn wrap<B>(body: B) -> Self
    where
        B: http_body::Body + Send + Sync + 'static,
        B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
    {
        let body = body
            .map_frame(|f| f.map_data(|mut buf| buf.copy_to_bytes(buf.remaining())))
            .map_err(crate::Error::new);
        Body(http_body_util::BodyExt::boxed(body))
    }

    pub(cratefn wrap_stream<S, B, E>(stream: S) -> Self
    where
        S: futures_util::Stream<Item = Result<B, E>> + Send + Sync + 'static,
        B: Into<Bytes>,
        E: Into<Box<dyn std::error::Error + Send + Sync>> + Send + 'static,
    {
        let body = http_body_util::StreamBody::new(stream.map(|item| {
            item.map(|buf| Frame::data(buf.into()))
                .map_err(crate::Error::new)
        }));
        Body(http_body_util::BodyExt::boxed(body))
    }
}

impl From<Bytes> for Body {
    fn from(b: Bytes) -> Self {
        Body(
            http_body_util::Full::new(b)
                .map_err(crate::Error::new)
                .boxed(),
        )
    }
}

impl From<&'static str> for Body {
    fn from(s: &'static str) -> Self {
        Bytes::from(s).into()
    }
}

impl From<String> for Body {
    fn from(s: String) -> Self {
        Bytes::from(s).into()
    }
}

impl From<Vec<u8>> for Body {
    fn from(v: Vec<u8>) -> Self {
        Bytes::from(v).into()
    }
}

impl From<Option<Bytes>> for Body {
    fn from(opt: Option<Bytes>) -> Self {
        match opt {
            Some(b) => b.into(),
            None => Body::empty(),
        }
    }
}

Messung V0.5 in Prozent
C=87 H=97 G=91

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=141584
#Domains=752002