web-wt-sys 0.3.1

Hand-crafted low-level Rust bindndings to WebTransport Web API for WebAssembly.
Documentation
//! [`WebTransportWriter`]
//!
//! <https://w3c.github.io/webtransport/#web-transport-writer-interface>

use js_sys::{Object, Promise};
use wasm_bindgen::prelude::*;
use web_sys::WritableStreamDefaultWriter;

#[wasm_bindgen]
extern "C" {
    ///The `WebTransportWriter` interface.
    ///
    /// <https://w3c.github.io/webtransport/#webtransportwriter>
    #[wasm_bindgen(extends = WritableStreamDefaultWriter, extends = Object)]
    #[derive(Debug, Clone, PartialEq, Eq)]
    pub type WebTransportWriter;

    /// ```webidl
    /// Promise<undefined> atomicWrite(optional any chunk);
    /// ```
    ///
    /// <https://w3c.github.io/webtransport/#dom-webtransportwriter-atomicwrite>
    ///
    /// The atomicWrite method will reject if the chunk given to it could
    /// not be sent in its entirety within the flow control window that is
    /// current at the time of sending.
    /// This behavior is designed to satisfy niche transactional applications
    /// sensitive to flow control deadlocks ([RFC9308] Section 4.4).
    ///
    /// NOTE: atomicWrite can still reject after sending some data.
    /// Though it provides atomicity with respect to flow control,
    /// other errors may occur.
    /// atomicWrite does not prevent data from being split between packets or
    /// being interleaved with other data.
    /// Only the sender learns if atomicWrite fails due to lack of available
    /// flow control credit.
    ///
    /// NOTE: Atomic writes can still block if queued behind non-atomic writes.
    /// If the atomic write is rejected, everything queued behind it at that
    /// moment will be rejected as well.
    /// Any non-atomic writes rejected in this way will error the stream.
    /// Applications are therefore encouraged to always await atomic writes.
    #[wasm_bindgen(method, js_name = atomicWrite)]
    pub fn atomic_write(this: &WebTransportWriter) -> Promise;

    /// ```webidl
    /// Promise<undefined> atomicWrite(optional any chunk);
    /// ```
    ///
    /// <https://w3c.github.io/webtransport/#dom-webtransportwriter-atomicwrite>
    ///
    /// The atomicWrite method will reject if the chunk given to it could
    /// not be sent in its entirety within the flow control window that is
    /// current at the time of sending.
    /// This behavior is designed to satisfy niche transactional applications
    /// sensitive to flow control deadlocks ([RFC9308] Section 4.4).
    ///
    /// NOTE: atomicWrite can still reject after sending some data.
    /// Though it provides atomicity with respect to flow control,
    /// other errors may occur.
    /// atomicWrite does not prevent data from being split between packets or
    /// being interleaved with other data.
    /// Only the sender learns if atomicWrite fails due to lack of available
    /// flow control credit.
    ///
    /// NOTE: Atomic writes can still block if queued behind non-atomic writes.
    /// If the atomic write is rejected, everything queued behind it at that
    /// moment will be rejected as well.
    /// Any non-atomic writes rejected in this way will error the stream.
    /// Applications are therefore encouraged to always await atomic writes.
    #[wasm_bindgen(method, js_name = atomicWrite)]
    pub fn atomic_write_with_chunk(this: &WebTransportWriter, chunk: &JsValue) -> Promise;

    /// ```webidl
    /// undefined commit();
    /// ```
    ///
    /// <https://w3c.github.io/webtransport/#dom-webtransportwriter-commit>
    ///
    /// Updates the `[[CommittedOffset]]` of a stream to match the number of
    /// bytes written to that stream (`[[BytesWritten]]`).
    /// This ensures that those bytes will be delivered to a peer reliably,
    /// even after writing is aborted, causing the stream to abort sending.
    /// This uses the mechanism described in [RELIABLE-RESET].
    ///
    /// NOTE: This does not guarantee delivery in the event that a connection
    /// fails, only when a stream has aborted sending.
    #[wasm_bindgen(method)]
    pub fn commit(this: &WebTransportWriter);
}