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

Quelle  compat.rs

  Sprache: Rust
 

#![cfg(feature = "compat")]
#![cfg(not(target_os = "wasi"))] // WASI does not support all fs operations
#![warn(rust_2018_idioms)]

use futures_io::SeekFrom;
use futures_util::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
use tempfile::NamedTempFile;
use tokio::fs::OpenOptions;
use tokio_util::compat::TokioAsyncWriteCompatExt;

#[tokio::test]
async fn compat_file_seek() -> futures_util::io::Result<()> {
    let temp_file = NamedTempFile::new()?;
    let mut file = OpenOptions::new()
        .read(true)
        .write(true)
        .create(true)
        .truncate(true)
        .open(temp_file)
        .await?
        .compat_write();

    file.write_all(&[012345]).await?;
    file.write_all(&[67]).await?;

    assert_eq!(file.stream_position().await?, 8);

    // Modify elements at position 2.
    assert_eq!(file.seek(SeekFrom::Start(2)).await?, 2);
    file.write_all(&[89]).await?;

    file.flush().await?;

    // Verify we still have 8 elements.
    assert_eq!(file.seek(SeekFrom::End(0)).await?, 8);
    // Seek back to the start of the file to read and verify contents.
    file.seek(SeekFrom::Start(0)).await?;

    let mut buf = Vec::new();
    let num_bytes = file.read_to_end(&mut buf).await?;
    assert_eq!(&buf[..num_bytes], &[01894567]);

    Ok(())
}

Messung V0.5 in Prozent
C=90 H=97 G=93

¤ 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.