feat: gate alloc/std features for no_std/no_alloc support

Gate generated code behind feature flags so consumers can build in
no_std/no_alloc environments:

- Runtime: gate RotoMessage, RotoOwned, BufMutBuilder behind alloc
- Codegen: split DATA_IMPORTS, gate Owned* structs + service code
- Fix RevBuilder::with() to iterate forward without Vec allocation
- Wire up bytes/std via alloc feature (Bytes requires Arc)
- Update consumer Cargo.toml files with proper feature chains
- Add no_std_test example for embedded validation
This commit is contained in:
2026-06-30 01:40:13 -04:00
parent 2ce65496ab
commit 2806772fd1
13 changed files with 304 additions and 955 deletions
+4 -4
View File
@@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2024"
[dependencies]
bytes = { version = "1.7", default-features = false }
bytes = { version = "1.7", default-features = false, optional = true }
[features]
default = ["std", "alloc"]
std = []
alloc = []
default = ["std"]
std = ["alloc"]
alloc = ["bytes/std"]
+7 -1
View File
@@ -6,7 +6,6 @@ extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
use bytes::BufMut;
use core::fmt;
pub struct MapFieldIterator<'a> {
@@ -64,6 +63,7 @@ impl std::error::Error for RotoError {}
pub type Result<T> = core::result::Result<T, RotoError>;
#[cfg(feature = "alloc")]
pub trait RotoOwned {
type Reader<'a>
where
@@ -71,6 +71,7 @@ pub trait RotoOwned {
fn reader(&self) -> Self::Reader<'_>;
}
#[cfg(feature = "alloc")]
pub trait RotoMessage: Sized {
fn decode(buf: bytes::Bytes) -> Result<Self>;
fn bytes(&self) -> bytes::Bytes;
@@ -1035,10 +1036,15 @@ impl<'a> ProtoBuilder<'a> {
}
}
#[cfg(feature = "alloc")]
use bytes::BufMut;
#[cfg(feature = "alloc")]
pub struct BufMutBuilder<'a, B: BufMut> {
buf: &'a mut B,
}
#[cfg(feature = "alloc")]
impl<'a, B: BufMut> BufMutBuilder<'a, B> {
pub fn new(buf: &'a mut B) -> Self {
Self { buf }