remoc 0.19.1

🦑 Remote multiplexed objects, channels, observable collections and RPC making remote interactions seamless. Provides multiple remote channels and RPC over TCP, TLS or any other transport.
Documentation
//! Utility functions.

use bytes::{Buf, Bytes};
use std::fmt;

/// Debug formatter for [Bytes].
pub fn dbg_bytes(bytes: &Bytes, f: &mut fmt::Formatter) -> fmt::Result {
    const LIMIT: usize = 16;

    if bytes.len() > LIMIT {
        let tmp = bytes.clone().copy_to_bytes(LIMIT);
        write!(f, "{tmp:?}...[{} bytes]", bytes.len())
    } else {
        write!(f, "{bytes:?}")
    }
}

/// Debug formatter for `Option<Bytes>`.
pub fn dbg_option_bytes(bytes: &Option<Bytes>, f: &mut fmt::Formatter) -> fmt::Result {
    match bytes {
        Some(bytes) => {
            write!(f, "Some(")?;
            dbg_bytes(bytes, f)?;
            write!(f, ")")?;
        }
        None => write!(f, "None")?,
    }
    Ok(())
}