Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/tokio-util/tests/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  io_sync_bridge.rs

  Sprache: Rust
 

#![cfg(feature = "io-util")]

use std::error::Error;
use std::io::{Cursor, Read, Result as IoResult};
use tokio::io::AsyncRead;
use tokio_util::io::SyncIoBridge;

async fn test_reader_len(
    r: impl AsyncRead + Unpin + Send + 'static,
    expected_len: usize,
) -> IoResult<()> {
    let mut r = SyncIoBridge::new(r);
    let res = tokio::task::spawn_blocking(move || {
        let mut buf = Vec::new();
        r.read_to_end(&mut buf)?;
        Ok::<_, std::io::Error>(buf)
    })
    .await?;
    assert_eq!(res?.len(), expected_len);
    Ok(())
}

#[tokio::test]
async fn test_async_read_to_sync() -> Result<(), Box<dyn Error>> {
    test_reader_len(tokio::io::empty(), 0).await?;
    let buf = b"hello world";
    test_reader_len(Cursor::new(buf), buf.len()).await?;
    Ok(())
}

#[tokio::test]
async fn test_async_write_to_sync() -> Result<(), Box<dyn Error>> {
    let mut dest = Vec::new();
    let src = b"hello world";
    let dest = tokio::task::spawn_blocking(move || -> Result<_, String> {
        let mut w = SyncIoBridge::new(Cursor::new(&mut dest));
        std::io::copy(&mut Cursor::new(src), &mut w).map_err(|e| e.to_string())?;
        Ok(dest)
    })
    .await??;
    assert_eq!(dest.as_slice(), src);
    Ok(())
}

Messung V0.5 in Prozent
C=71 H=98 G=85

¤ Dauer der Verarbeitung: 0.10 Sekunden  (vorverarbeitet am  2026-06-22) ¤

*© 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.