SCOPE.md

Tripwire declarations generate a fixed area, named getters and a borrowed client builder. Integers and inline byte arrays read directly from the admitted fixed area. Generated opening validates the complete cumulative-end directory without fetching payloads. Boolean getters validate their representation; variable fields validate their byte limits when selected and read payload bytes only on request.

use cdk_rsx_tripwire::{message, Error, SliceSource};
#[message]
pub struct Submit { user_id: u64, body: Bytes<1024> }
let bytes = SubmitArgs { user_id: 7, body: b"payload" }.encode()?;
let source = SliceSource::new(&bytes);
let id = Submit::with_source(&source, 2048, |request| request.user_id())?;
assert_eq!(id, 7);
# Ok::<(), Error>(())

Typed children and bounded lists return child views borrowing the original source. Client Args borrow only the supplied text, bytes and child-Args slices; children encode directly into the final destination without temporary frames:

use cdk_rsx_tripwire::{message, Error};
mod contacts {
    use cdk_rsx_tripwire::message;
    #[message]
    pub struct Address { city: Text<64> }
}
#[message]
pub struct Item { sku: u64, quantity: u32 }
#[message]
pub struct Order { address: Nested<contacts::Address>, items: List<Item, 128> }
let items = [ItemArgs { sku: 7, quantity: 2 }];
let bytes = OrderArgs {
    address: contacts::AddressArgs { city: "Oslo" },
    items: &items,
}.encode()?;
Order::with_slice(&bytes, 4096, |order| {
    let address = order.address()?;
    let mut city = [0; 64];
    assert_eq!(address.city()?.read_into(&mut city)?, "Oslo");
    let items = order.items()?;
    assert_eq!(items.len(), 1);
    let item = { let temporary_list = items; temporary_list.get(0)?.unwrap() };
    assert_eq!(item.quantity(), 2);
    for item in items.iter() { assert_eq!(item?.sku(), 7); }
    Ok::<_, Error>(())
})??;
# Ok::<(), Error>(())

Nested<Child> and List<Child, MAX_COUNT> accept generated record paths, including module-qualified paths, without lifetime or type arguments. Plain child fields, primitive type aliases, Option, enums and arbitrary containers are not automatically inferred. All declared scalar fields remain present. List admission checks count, exact geometry, the cumulative directory and child byte caps using bounded scratch; child headers open only when selected. Child boolean, field-limit and UTF-8 checks remain lazy.

Nested<Child, MAX_BYTES> narrows a child's byte cap to the smaller of its compiled maximum and the explicit literal. The cap is checked before child fixed-area copies or output writes. A fixed child wider than the cap is rejected during compilation:

use cdk_rsx_tripwire::message;
#[message]
struct Child { value: u64 }
#[message]
struct Parent { child: Nested<Child, 7> }

Results independent of the request lifetime may leave the callback. A request cannot escape:

use cdk_rsx_tripwire::{message, SliceSource};
#[message]
struct Submit { user_id: u64, body: Bytes<1024> }
let bytes = SubmitArgs { user_id: 7, body: b"payload" }.encode().unwrap();
let source = SliceSource::new(&bytes);
let escaped = Submit::with_source(&source, 2048, |request| request).unwrap();
assert_eq!(escaped.user_id(), 7);

Neither can a field handle, even though it has not copied its payload:

use cdk_rsx_tripwire::{message, SliceSource};
#[message]
struct Submit { body: Bytes<1024> }
let bytes = SubmitArgs { body: b"payload" }.encode().unwrap();
let source = SliceSource::new(&bytes);
let escaped = Submit::with_source(&source, 2048, |request| request.body().unwrap()).unwrap();
assert_eq!(escaped.len(), 7);

A future cannot carry a request beyond the callback or across an await:

use cdk_rsx_tripwire::{message, SliceSource};
#[message]
struct Submit { user_id: u64 }
let bytes = SubmitArgs { user_id: 7 }.encode().unwrap();
let source = SliceSource::new(&bytes);
let future = Submit::with_source(&source, 2048, |request| async move {
    std::future::ready(()).await;
    request.user_id()
}).unwrap();
drop(future);

The same rule applies to a future capturing only a field handle:

use cdk_rsx_tripwire::{message, SliceSource};
#[message]
struct Submit { body: Bytes<1024> }
let bytes = SubmitArgs { body: b"payload" }.encode().unwrap();
let source = SliceSource::new(&bytes);
let future = Submit::with_source(&source, 2048, |request| {
    let body = request.body().unwrap();
    async move {
        std::future::ready(()).await;
        body.len()
    }
}).unwrap();
drop(future);

Use caller-owned buffers for selected payload copies that must survive this scope. Generated NameArgs borrows text and bytes, checks declared bounds before writing, and provides encoded_len, encode_into, and fallible encode.

encode_stack::<CAPACITY>() owns completed bytes in a fixed inline buffer. Its StackEncoded<CAPACITY> implements AsRef<[u8]>, so synchronous Tripwire endpoints can return it directly. It uses the same checked encode_into without allocating heap output. Only the successful prefix is exposed; unused capacity is private. The output can outlive the borrowed Args:

use cdk_rsx_tripwire::{message, Error, StackEncoded};
#[message]
struct Reply { accepted: bool, receipt: Bytes<8> }
let reply: StackEncoded<10> = {
    let receipt = [7];
    ReplyArgs { accepted: true, receipt: &receipt }.encode_stack::<10>()?
};
assert_eq!(reply.as_ref(), [1, 7]);
# Ok::<(), Error>(())

The capacity must fit the compiled fixed area. A smaller capacity is rejected during compilation; a dynamic payload exceeding the chosen capacity returns Error::BufferTooSmall:

use cdk_rsx_tripwire::message;
#[message]
struct Reply { request: u64 }
let _ = ReplyArgs { request: 7 }.encode_stack::<7>();

BytesView::read_in selects the allocator of an owned field buffer. This copies the selected bytes into their final allocation and lets that allocation leave the request scope. IC and slice sources initialize the destination directly, without a preceding zeroing pass. The returned initialized slice must match the exact destination pointer and length before the Vec is published. Custom sources can use the zero-initializing default. No intermediate payload buffer is created.

# #![feature(allocator_ext)]
use cdk_rsx_tripwire::{message, Error, SliceSource};
use std::alloc::Global;
#[message]
struct Submit { body: Bytes<1024> }
let bytes = SubmitArgs { body: b"owned bytes" }.encode()?;
let owned = Submit::with_source(&SliceSource::new(&bytes), 2048, |request| {
    request.body()?.read_in(Global)
})??;
drop(bytes);
assert_eq!(owned, b"owned bytes");
# Ok::<(), Error>(())

Applications may instead select their retained allocator and move the resulting buffer into its storage carrier. Tripwire does not depend on storage engines. Text owners validate UTF-8 separately when adopting bytes; read_in itself is only a byte-field operation.

Name::SCHEMA is the first 128 bits of SHA-256 over the domain cdk-rsx-tripwire-compact-message-v1\0 followed by Name::DESCRIPTOR's exact UTF-8 JSON. The proc macro computes that identity at build time. The native-only identity, descriptor and named-field table serve build/client tools; none is transmitted or available in Wasm. Producers and consumers must share the same compiled positional contract. Root persistence admission is independent of that message contract.

Borrowed payload bytes from the explicit slice path also stay inside the scope:

use cdk_rsx_tripwire::message;
#[message]
struct Submit { body: Bytes<1024> }
let bytes = SubmitArgs { body: b"payload" }.encode().unwrap();
let escaped = Submit::with_slice(&bytes, 2048, |request| {
    request.body().unwrap().as_slice().unwrap()
}).unwrap();
println!("{escaped:?}");

Compiled fixed getters reject invalid layouts during compilation, including when used through the low-level request API:

use cdk_rsx_tripwire::{Request, SliceSource};
let source = SliceSource::new(&[]);
let request = Request::<0>::open(&source, 0).unwrap();
let _ = request.fixed::<u64, 0>();

A child opened from a selected window keeps the original source lifetime, so it can outlive the temporary byte-field handle inside the call. It still cannot escape the enclosing higher-ranked entry callback:

use cdk_rsx_tripwire::message;
#[message]
struct Child { value: u64 }
#[message]
struct Parent { child: Nested<Child> }
let bytes = ParentArgs { child: ChildArgs { value: 7 } }.encode().unwrap();
let escaped = Parent::with_slice(&bytes, 64, |parent| {
    parent.child().unwrap()
}).unwrap();
assert_eq!(escaped.value(), 7);

Nor can a returned future carry that source-backed child across an await:

use cdk_rsx_tripwire::message;
#[message]
struct Child { value: u64 }
#[message]
struct Parent { child: Nested<Child> }
let bytes = ParentArgs { child: ChildArgs { value: 7 } }.encode().unwrap();
let future = Parent::with_slice(&bytes, 64, |parent| {
    let child = parent.child().unwrap();
    async move {
        std::future::ready(()).await;
        child.value()
    }
}).unwrap();
drop(future);

An item selected from a list also cannot escape that callback:

use cdk_rsx_tripwire::message;
#[message]
struct Item { value: u64 }
#[message]
struct Parent { items: List<Item, 4> }
let items = [ItemArgs { value: 7 }];
let bytes = ParentArgs { items: &items }.encode().unwrap();
let escaped = Parent::with_slice(&bytes, 64, |parent| {
    parent.items().unwrap().get(0).unwrap().unwrap()
}).unwrap();
assert_eq!(escaped.value(), 7);

Nor can a returned future retain a list item across an await:

use cdk_rsx_tripwire::message;
#[message]
struct Item { value: u64 }
#[message]
struct Parent { items: List<Item, 4> }
let items = [ItemArgs { value: 7 }];
let bytes = ParentArgs { items: &items }.encode().unwrap();
let future = Parent::with_slice(&bytes, 64, |parent| {
    let item = parent.items().unwrap().get(0).unwrap().unwrap();
    async move {
        std::future::ready(()).await;
        item.value()
    }
}).unwrap();
drop(future);

Unbounded recursive layouts have no finite compiled maximum and are rejected:

use cdk_rsx_tripwire::message;
#[message]
struct Recursive { children: List<Recursive, 4> }

Message fields come from a closed set, so caller bytes cannot name an arbitrary Rust type, including a stable storage identity. This declaration compiles, and the next differs only in naming a type outside that set:

use cdk_rsx_tripwire::message;
#[message]
struct Accepted { handle: u64 }
use cdk_rsx_tripwire::message;
#[derive(Clone, Copy)]
struct StorageIdentity { offset: u64, generation: u64 }
#[message]
struct Refused { handle: StorageIdentity }