---
source: crates/ridl-backend-rust/src/tests.rs
expression: rust_for(decls)
---
/// Vehicle speed over ground
///
/// Quantization (`step`) is not checked by `new`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[deprecated(note = "use Velocity")]
#[repr(transparent)]
pub struct Speed(f64);
#[allow(deprecated)]
impl Speed {
/// Constructs the value, enforcing its typl constraints.
pub fn new(
value: f64,
) -> ::core::result::Result<Self, ::ridl_rt::payload::Violation> {
Self::check(&value)?;
::core::result::Result::Ok(Self::new_unchecked(value))
}
/// Checks `value` against this type's typl constraints, without
/// constructing it. `pub(crate)` rather than `pub`: a caller
/// outside `new` is a function generated into this crate — since
/// driftsys/ridl#467 that includes the codec of *another* package
/// of the same build, which reaches this type through the module
/// tree and so cannot see a private item here. The emitted crate
/// is one crate per build, so `pub(crate)` reaches every such
/// caller while adding nothing to the crate's public surface.
/// Whether this becomes `pub` is Epic 10's call, still open.
/// `new` is the composition of this and `new_unchecked`.
pub(crate) fn check(
value: &f64,
) -> ::core::result::Result<(), ::ridl_rt::payload::Violation> {
let value = *value;
if value < 0.0 {
return ::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "Speed",
rule: ::ridl_rt::payload::Rule::Range,
});
}
if value > 250.0 {
return ::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "Speed",
rule: ::ridl_rt::payload::Rule::Range,
});
}
::core::result::Result::Ok(())
}
/// Constructs the value without checking its constraints.
///
/// Safe: nothing here relies on the invariant for memory
/// soundness. Use it only for a value already known to satisfy
/// the contract.
pub const fn new_unchecked(value: f64) -> Self {
Self(value)
}
pub const fn get(self) -> f64 {
self.0
}
}
#[allow(deprecated)]
impl ::core::convert::TryFrom<f64> for Speed {
type Error = ::ridl_rt::payload::Violation;
fn try_from(value: f64) -> ::core::result::Result<Self, Self::Error> {
Self::new(value)
}
}
#[allow(deprecated)]
impl ::core::convert::From<Speed> for f64 {
fn from(value: Speed) -> Self {
value.0
}
}
impl Default for Speed {
fn default() -> Self {
Speed::new_unchecked(0.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[deprecated]
#[repr(transparent)]
pub struct OldFlag(bool);
#[allow(deprecated)]
impl OldFlag {
/// Constructs the value. This type declares no constraint, so
/// construction cannot fail.
pub const fn new(value: bool) -> Self {
Self(value)
}
pub const fn get(self) -> bool {
self.0
}
}
#[allow(deprecated)]
impl ::core::convert::From<bool> for OldFlag {
fn from(value: bool) -> Self {
Self(value)
}
}
#[allow(deprecated)]
impl ::core::convert::From<OldFlag> for bool {
fn from(value: OldFlag) -> Self {
value.0
}
}
impl Default for OldFlag {
fn default() -> Self {
OldFlag::new(false)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(transparent)]
pub(crate) struct RawTicks(i64);
impl RawTicks {
/// Constructs the value. This type declares no constraint, so
/// construction cannot fail.
pub(crate) const fn new(value: i64) -> Self {
Self(value)
}
pub(crate) const fn get(self) -> i64 {
self.0
}
}
impl ::core::convert::From<i64> for RawTicks {
fn from(value: i64) -> Self {
Self(value)
}
}
impl ::core::convert::From<RawTicks> for i64 {
fn from(value: RawTicks) -> Self {
value.0
}
}
impl Default for RawTicks {
fn default() -> Self {
RawTicks::new(0)
}
}
/// An accessor over FlatBuffers bytes `Speed`'s `verify` accepted.
///
/// The buffer's root is the box table ADR-0019 decision 8
/// gives this declaration: one required `value` field. A
/// buffer carrying no slot for it is `MissingRequired`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(deprecated)]
pub struct SpeedFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> SpeedFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `Speed` is one value, so this decodes it rather than borrowing it, which costs one read.
pub fn value(&self) -> Speed {
__ridl_fb_decode_speed(self.buf, self.table)
}
}
/// Writes `Speed` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_speed(
value: &Speed,
builder: &mut ::ridl_rt::flatbuffers::Builder<'_>,
) -> ::core::result::Result<
::ridl_rt::flatbuffers::Pos,
::ridl_rt::payload::EncodeError,
> {
::core::result::Result::Ok({
let __box = [
::ridl_rt::flatbuffers::TableField {
slot: 0u16,
offset: 4u16,
value: {
let __s = *value;
::ridl_rt::flatbuffers::Field::F32(__s.get() as f32)
},
},
];
builder.push_table(8usize, 4usize, 1u16, &__box)?
})
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_speed(
buf: &[u8],
table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
.map_err(::ridl_rt::payload::VerifyError::Structure)?
{
::core::option::Option::Some(__p) => {
let __raw = ::ridl_rt::flatbuffers::read_f32(buf, __p)
.map_err(::ridl_rt::payload::VerifyError::Structure)?;
Speed::check(&(f64::from(__raw)))
.map_err(::ridl_rt::payload::VerifyError::Contract)?;
}
::core::option::Option::None => {
return ::core::result::Result::Err(
::ridl_rt::payload::VerifyError::Structure(
::ridl_rt::payload::Malformed::MissingRequired,
),
);
}
}
::core::result::Result::Ok(())
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_decode_speed(buf: &[u8], table: usize) -> Speed {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
Speed::new_unchecked(
f64::from(::ridl_rt::flatbuffers::read_f32(buf, __p).unwrap_or(0.0f32)),
)
}
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for Speed {
/// The largest FlatBuffers buffer any legal `Speed` encodes to: 46 bytes.
///
/// `ridl_ir::projection::flatbuffers::max_size` computed it,
/// which is the one implementation of the bound (design note
/// D-6): each table is charged its `soffset`, its inline
/// fields, its vtable and one alignment event per slot; a
/// string four bytes per declared character plus a
/// terminator; a collection its declared maximum. It is a
/// literal rather than an expression over the field types
/// because that slack is not expressible in Rust's type
/// system.
const MAX_SIZE: usize = 46usize;
type View<'a> = SpeedFbView<'a>;
fn encode<'o>(
&self,
out: &'o mut [u8],
) -> ::core::result::Result<
::ridl_rt::payload::Encoded<'o, Self::View<'o>>,
::ridl_rt::payload::EncodeError,
> {
let mut builder = ::ridl_rt::flatbuffers::Builder::new(out);
let __root = __ridl_fb_encode_speed(self, &mut builder)?;
let bytes = builder.finish(__root, 8usize)?;
let table = ::ridl_rt::flatbuffers::root(bytes).unwrap_or(0usize);
::core::result::Result::Ok(::ridl_rt::payload::Encoded {
bytes,
view: SpeedFbView { buf: bytes, table },
})
}
fn verify(
buf: &[u8],
) -> ::core::result::Result<Self::View<'_>, ::ridl_rt::payload::VerifyError> {
if buf.len()
> <Self as ::ridl_rt::payload::Payload<
::ridl_rt::encoding::FlatBuffers,
>>::MAX_SIZE
{
return ::core::result::Result::Err(
::ridl_rt::payload::VerifyError::Structure(
::ridl_rt::payload::Malformed::TooLarge,
),
);
}
let table = ::ridl_rt::flatbuffers::root(buf)
.map_err(::ridl_rt::payload::VerifyError::Structure)?;
__ridl_fb_verify_speed(buf, table)?;
::core::result::Result::Ok(SpeedFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_speed(__view.buf, __view.table)
}
}
/// An accessor over FlatBuffers bytes `OldFlag`'s `verify` accepted.
///
/// The buffer's root is the box table ADR-0019 decision 8
/// gives this declaration: one required `value` field. A
/// buffer carrying no slot for it is `MissingRequired`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(deprecated)]
pub struct OldFlagFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> OldFlagFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `OldFlag` is one value, so this decodes it rather than borrowing it, which costs one read.
pub fn value(&self) -> OldFlag {
__ridl_fb_decode_old_flag(self.buf, self.table)
}
}
/// Writes `OldFlag` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_old_flag(
value: &OldFlag,
builder: &mut ::ridl_rt::flatbuffers::Builder<'_>,
) -> ::core::result::Result<
::ridl_rt::flatbuffers::Pos,
::ridl_rt::payload::EncodeError,
> {
::core::result::Result::Ok({
let __box = [
::ridl_rt::flatbuffers::TableField {
slot: 0u16,
offset: 4u16,
value: {
let __s = *value;
::ridl_rt::flatbuffers::Field::Bool(__s.get())
},
},
];
builder.push_table(5usize, 4usize, 1u16, &__box)?
})
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_old_flag(
buf: &[u8],
table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 1usize)
.map_err(::ridl_rt::payload::VerifyError::Structure)?
{
::core::option::Option::Some(__p) => {
::ridl_rt::flatbuffers::read_bool(buf, __p)
.map_err(::ridl_rt::payload::VerifyError::Structure)?;
}
::core::option::Option::None => {
return ::core::result::Result::Err(
::ridl_rt::payload::VerifyError::Structure(
::ridl_rt::payload::Malformed::MissingRequired,
),
);
}
}
::core::result::Result::Ok(())
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_decode_old_flag(buf: &[u8], table: usize) -> OldFlag {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 1usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
OldFlag::new(::ridl_rt::flatbuffers::read_bool(buf, __p).unwrap_or(false))
}
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for OldFlag {
/// The largest FlatBuffers buffer any legal `OldFlag` encodes to: 43 bytes.
///
/// `ridl_ir::projection::flatbuffers::max_size` computed it,
/// which is the one implementation of the bound (design note
/// D-6): each table is charged its `soffset`, its inline
/// fields, its vtable and one alignment event per slot; a
/// string four bytes per declared character plus a
/// terminator; a collection its declared maximum. It is a
/// literal rather than an expression over the field types
/// because that slack is not expressible in Rust's type
/// system.
const MAX_SIZE: usize = 43usize;
type View<'a> = OldFlagFbView<'a>;
fn encode<'o>(
&self,
out: &'o mut [u8],
) -> ::core::result::Result<
::ridl_rt::payload::Encoded<'o, Self::View<'o>>,
::ridl_rt::payload::EncodeError,
> {
let mut builder = ::ridl_rt::flatbuffers::Builder::new(out);
let __root = __ridl_fb_encode_old_flag(self, &mut builder)?;
let bytes = builder.finish(__root, 8usize)?;
let table = ::ridl_rt::flatbuffers::root(bytes).unwrap_or(0usize);
::core::result::Result::Ok(::ridl_rt::payload::Encoded {
bytes,
view: OldFlagFbView { buf: bytes, table },
})
}
fn verify(
buf: &[u8],
) -> ::core::result::Result<Self::View<'_>, ::ridl_rt::payload::VerifyError> {
if buf.len()
> <Self as ::ridl_rt::payload::Payload<
::ridl_rt::encoding::FlatBuffers,
>>::MAX_SIZE
{
return ::core::result::Result::Err(
::ridl_rt::payload::VerifyError::Structure(
::ridl_rt::payload::Malformed::TooLarge,
),
);
}
let table = ::ridl_rt::flatbuffers::root(buf)
.map_err(::ridl_rt::payload::VerifyError::Structure)?;
__ridl_fb_verify_old_flag(buf, table)?;
::core::result::Result::Ok(OldFlagFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_old_flag(__view.buf, __view.table)
}
}
/// An accessor over FlatBuffers bytes `RawTicks`'s `verify` accepted.
///
/// The buffer's root is the box table ADR-0019 decision 8
/// gives this declaration: one required `value` field. A
/// buffer carrying no slot for it is `MissingRequired`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(deprecated)]
pub(crate) struct RawTicksFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> RawTicksFbView<'a> {
/// The verified bytes this view reads.
pub(crate) fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `RawTicks` is one value, so this decodes it rather than borrowing it, which costs one read.
pub(crate) fn value(&self) -> RawTicks {
__ridl_fb_decode_raw_ticks(self.buf, self.table)
}
}
/// Writes `RawTicks` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_raw_ticks(
value: &RawTicks,
builder: &mut ::ridl_rt::flatbuffers::Builder<'_>,
) -> ::core::result::Result<
::ridl_rt::flatbuffers::Pos,
::ridl_rt::payload::EncodeError,
> {
::core::result::Result::Ok({
let __box = [
::ridl_rt::flatbuffers::TableField {
slot: 0u16,
offset: 4u16,
value: {
let __s = *value;
::ridl_rt::flatbuffers::Field::U32(__s.get() as u32)
},
},
];
builder.push_table(8usize, 4usize, 1u16, &__box)?
})
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_raw_ticks(
buf: &[u8],
table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
.map_err(::ridl_rt::payload::VerifyError::Structure)?
{
::core::option::Option::Some(__p) => {
::ridl_rt::flatbuffers::read_u32(buf, __p)
.map_err(::ridl_rt::payload::VerifyError::Structure)?;
}
::core::option::Option::None => {
return ::core::result::Result::Err(
::ridl_rt::payload::VerifyError::Structure(
::ridl_rt::payload::Malformed::MissingRequired,
),
);
}
}
::core::result::Result::Ok(())
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_decode_raw_ticks(buf: &[u8], table: usize) -> RawTicks {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
RawTicks::new(
i64::from(::ridl_rt::flatbuffers::read_u32(buf, __p).unwrap_or(0u32)),
)
}
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for RawTicks {
/// The largest FlatBuffers buffer any legal `RawTicks` encodes to: 46 bytes.
///
/// `ridl_ir::projection::flatbuffers::max_size` computed it,
/// which is the one implementation of the bound (design note
/// D-6): each table is charged its `soffset`, its inline
/// fields, its vtable and one alignment event per slot; a
/// string four bytes per declared character plus a
/// terminator; a collection its declared maximum. It is a
/// literal rather than an expression over the field types
/// because that slack is not expressible in Rust's type
/// system.
const MAX_SIZE: usize = 46usize;
type View<'a> = RawTicksFbView<'a>;
fn encode<'o>(
&self,
out: &'o mut [u8],
) -> ::core::result::Result<
::ridl_rt::payload::Encoded<'o, Self::View<'o>>,
::ridl_rt::payload::EncodeError,
> {
let mut builder = ::ridl_rt::flatbuffers::Builder::new(out);
let __root = __ridl_fb_encode_raw_ticks(self, &mut builder)?;
let bytes = builder.finish(__root, 8usize)?;
let table = ::ridl_rt::flatbuffers::root(bytes).unwrap_or(0usize);
::core::result::Result::Ok(::ridl_rt::payload::Encoded {
bytes,
view: RawTicksFbView {
buf: bytes,
table,
},
})
}
fn verify(
buf: &[u8],
) -> ::core::result::Result<Self::View<'_>, ::ridl_rt::payload::VerifyError> {
if buf.len()
> <Self as ::ridl_rt::payload::Payload<
::ridl_rt::encoding::FlatBuffers,
>>::MAX_SIZE
{
return ::core::result::Result::Err(
::ridl_rt::payload::VerifyError::Structure(
::ridl_rt::payload::Malformed::TooLarge,
),
);
}
let table = ::ridl_rt::flatbuffers::root(buf)
.map_err(::ridl_rt::payload::VerifyError::Structure)?;
__ridl_fb_verify_raw_ticks(buf, table)?;
::core::result::Result::Ok(RawTicksFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_raw_ticks(__view.buf, __view.table)
}
}