Skip to main content

buffer_fits

Function buffer_fits 

Source
pub const fn buffer_fits<M: Message>(
    rx_buf: usize,
    version: EncodingVersion,
) -> bool
Expand description

Phase 380 W4 — does a receive buffer of rx_buf bytes fit every message of this type?

true when the type is bounded and the bound fits. false when the type is UNBOUNDED, deliberately: no finite buffer fits a String, so the honest answer to “is this guaranteed to fit” is no. A caller that wants “fits unless proven otherwise” is asking a different question and should look at serialized_size per message.

Const, so a call site can put it in a const { assert!(...) } and turn a runtime drop into a build error:

const { assert!(buffer_fits::<Odometry>(RX_BUF, EncodingVersion::Xcdr1)) };

§Why this is not simply a bound on Subscription

Subscription<M, RX_BUF> bounds M: RosMessage, which is a DIFFERENT trait from crate::schema::Message — and measured 2026-08-26, hand-written RosMessage types with no schema DO exist (nros-core/src/service.rs, the component-runtime tests). Tightening that bound would break them, so the assertion is opt-in at sites where the schema is known rather than universal at a site where it is not. See the phase doc for what closing that gap needs.