Files
alkane-os/vendor/zerocopy-derive/tests/struct_known_layout.rs
T
x ad31cfbafa Vendor flare-ui v0.2.9 and prove the schema-driven UI in an image
Spike, not the final UI: it answers whether flare-ui can drive Alkane OS's
on-box pages, and what it costs.

What works:

- schema/alkane-bb.json authors the sidebar as data (3 sections, 14 tabs);
- src/bin/ui-spike.rs renders it through flare_ui::nav + flare_ui::shell, so
  the unified sidebar, ordering and surface filtering come from the schema
  rather than from hand-written HTML;
- the render uses the shared bf- design tokens, the same ones the rest of the
  suite uses.

Size, measured rather than assumed (armv7, release, stripped):

  ui-baseline   323 KiB   (maud + serde_json, no flare-ui)
  ui-spike      771 KiB   (flare-ui + wschema + sha2)
  marginal      448 KiB

Vendoring: third-party/flare-ui is the full v0.2.9 tree pinned in
flare-ui/flare-ui.lock (a partial archive does not compile, since the crate
include_str!s assets from dash-editor/). vendor/ is re-generated as a cargo
directory source with the new registry dependencies (maud, sha2, typenum,
digest, generic-array, block-buffer, crypto-common, cfg-if, etc.) so the build
still works offline. third-party/README.md records how to re-pin.
2026-11-04 14:06:25 -06:00

161 lines
4.3 KiB
Rust

// Copyright 2023 The Fuchsia Authors
//
// Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
// <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
// This file may not be copied, modified, or distributed except according to
// those terms.
// See comment in `include.rs` for why we disable the prelude.
#![no_implicit_prelude]
#![allow(warnings)]
extern crate rustversion;
include!("include.rs");
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Zst;
util_assert_impl_all!(Zst: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct One {
a: bool,
}
util_assert_impl_all!(One: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct Two {
a: bool,
b: Zst,
}
util_assert_impl_all!(Two: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
struct TypeParams<'a, T, I: imp::Iterator> {
a: I::Item,
b: u8,
c: imp::PhantomData<&'a [::core::primitive::u8]>,
d: imp::PhantomData<&'static ::core::primitive::str>,
e: imp::PhantomData<imp::String>,
f: T,
}
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::KnownLayout);
util_assert_impl_all!(TypeParams<'static, util::AU16, imp::IntoIter<()>>: imp::KnownLayout);
// Deriving `KnownLayout` should work if the struct has bounded parameters.
//
// N.B. We limit this test to rustc >= 1.62, since earlier versions of rustc ICE
// when `KnownLayout` is derived on a `repr(C)` struct whose trailing field
// contains non-static lifetimes.
#[rustversion::since(1.62)]
const _: () = {
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::KnownLayout, const N: usize>(
[T; N],
imp::PhantomData<&'a &'b ()>,
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::KnownLayout;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::KnownLayout);
};
const _: () = {
// Similar to the previous test, except that the trailing field contains
// only static lifetimes. This is exercisable on all supported toolchains.
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::KnownLayout, const N: usize>(
&'a &'b [T; N],
imp::PhantomData<&'static ()>,
)
where
'a: 'b,
'b: 'a,
T: 'a + 'b + imp::KnownLayout;
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::KnownLayout);
};
// Deriving `KnownLayout` should work if the struct references `Self`. See
// #2116.
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct WithSelfReference {
leading: [u8; Self::N],
trailing: [[u8; Self::N]],
}
impl WithSelfReference {
const N: usize = 42;
}
util_assert_impl_all!(WithSelfReference: imp::KnownLayout);
// Deriving `KnownLayout` should work with generic `repr(packed)` types. See
// #2302.
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C, packed)]
struct Packet<P> {
payload: P,
}
util_assert_impl_all!(Packet<imp::u8>: imp::KnownLayout);
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct RawIdentifier {
r#type: u8,
}
util_assert_impl_all!(RawIdentifier: imp::KnownLayout);
// Regression test for #3621. An inherent method on a concrete trailing field
// must not be selected in place of `KnownLayout::pointer_to_metadata`.
mod issue_3621 {
use super::imp;
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Inner([u8]);
impl Inner {
fn pointer_to_metadata(_ptr: *mut Self) -> usize {
8
}
}
#[derive(imp::KnownLayout)]
#[zerocopy(crate = "zerocopy_renamed")]
#[repr(C)]
struct Outer(Inner);
#[test]
fn pointer_to_metadata_uses_known_layout_impl() {
let mut bytes = [0u8];
let ptr = &mut bytes[..] as *mut [u8] as *mut Inner as *mut Outer;
imp::assert_eq!(<Outer as imp::KnownLayout>::pointer_to_metadata(ptr), 1);
}
}