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.
141 lines
3.8 KiB
Rust
141 lines
3.8 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)]
|
|
|
|
include!("include.rs");
|
|
|
|
// A struct is `imp::TryFromBytes` if:
|
|
// - any of its fields are `imp::TryFromBytes`
|
|
|
|
#[derive(imp::Immutable, imp::TryFromBytes)]
|
|
#[zerocopy(crate = "zerocopy_renamed")]
|
|
union One {
|
|
a: u8,
|
|
}
|
|
|
|
util_assert_impl_all!(One: imp::TryFromBytes);
|
|
|
|
#[test]
|
|
fn one() {
|
|
crate::util::test_is_safe::<One, _>([42u8], true);
|
|
crate::util::test_is_safe::<One, _>([43u8], true);
|
|
}
|
|
|
|
#[derive(imp::Immutable, imp::TryFromBytes, imp::IntoBytes)]
|
|
#[zerocopy(crate = "zerocopy_renamed")]
|
|
#[repr(C)]
|
|
union Two {
|
|
a: bool,
|
|
b: bool,
|
|
}
|
|
|
|
util_assert_impl_all!(Two: imp::TryFromBytes);
|
|
|
|
#[test]
|
|
fn two() {
|
|
crate::util::test_is_safe::<Two, _>(Two { a: false }, true);
|
|
crate::util::test_is_safe::<Two, _>(Two { b: true }, true);
|
|
crate::util::test_is_safe::<Two, _>([2u8], false);
|
|
}
|
|
|
|
#[derive(imp::Immutable, imp::TryFromBytes)]
|
|
#[zerocopy(crate = "zerocopy_renamed")]
|
|
#[repr(C)]
|
|
union BoolAndZst {
|
|
a: bool,
|
|
b: (),
|
|
}
|
|
|
|
#[test]
|
|
fn bool_and_zst() {
|
|
crate::util::test_is_safe::<BoolAndZst, _>([0u8], true);
|
|
crate::util::test_is_safe::<BoolAndZst, _>([1u8], true);
|
|
crate::util::test_is_safe::<BoolAndZst, _>([2u8], true);
|
|
}
|
|
|
|
#[derive(imp::FromBytes)]
|
|
#[zerocopy(crate = "zerocopy_renamed")]
|
|
#[repr(C)]
|
|
union MaybeFromBytes<T: imp::Copy> {
|
|
t: T,
|
|
}
|
|
|
|
#[test]
|
|
fn test_maybe_from_bytes() {
|
|
// When deriving `FromBytes` on a type with no generic parameters, we emit a
|
|
// trivial `is_safe` impl that always returns true. This test confirms that
|
|
// we *don't* spuriously do that when generic parameters are present.
|
|
|
|
crate::util::test_is_safe::<MaybeFromBytes<bool>, _>([2u8], false);
|
|
}
|
|
|
|
#[derive(imp::Immutable, imp::TryFromBytes)]
|
|
#[zerocopy(crate = "zerocopy_renamed")]
|
|
#[repr(C)]
|
|
union TypeParams<'a, T: imp::Copy, I: imp::Iterator>
|
|
where
|
|
I::Item: imp::Copy,
|
|
{
|
|
a: I::Item,
|
|
b: u8,
|
|
c: imp::PhantomData<&'a [u8]>,
|
|
d: imp::PhantomData<&'static str>,
|
|
e: imp::PhantomData<imp::String>,
|
|
f: T,
|
|
}
|
|
|
|
util_assert_impl_all!(TypeParams<'static, (), imp::IntoIter<()>>: imp::TryFromBytes);
|
|
util_assert_impl_all!(TypeParams<'static, util::AU16, imp::IntoIter<()>>: imp::TryFromBytes);
|
|
util_assert_impl_all!(TypeParams<'static, [util::AU16; 2], imp::IntoIter<()>>: imp::TryFromBytes);
|
|
|
|
// Deriving `imp::TryFromBytes` should work if the union has bounded parameters.
|
|
|
|
#[derive(imp::Immutable, imp::TryFromBytes)]
|
|
#[zerocopy(crate = "zerocopy_renamed")]
|
|
#[repr(C)]
|
|
union WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::TryFromBytes, const N: usize>
|
|
where
|
|
'a: 'b,
|
|
'b: 'a,
|
|
T: 'a + 'b + imp::TryFromBytes + imp::Copy,
|
|
{
|
|
a: imp::PhantomData<&'a &'b ()>,
|
|
b: T,
|
|
}
|
|
|
|
util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::TryFromBytes);
|
|
|
|
#[derive(Clone, Copy, imp::TryFromBytes, imp::Immutable)]
|
|
#[zerocopy(crate = "zerocopy_renamed")]
|
|
struct A;
|
|
|
|
#[derive(imp::TryFromBytes)]
|
|
#[zerocopy(crate = "zerocopy_renamed")]
|
|
union B {
|
|
a: A,
|
|
}
|
|
|
|
#[derive(imp::TryFromBytes)]
|
|
#[zerocopy(crate = "zerocopy_renamed")]
|
|
#[repr(C)]
|
|
union UnsafeCellUnion {
|
|
a: imp::ManuallyDrop<imp::UnsafeCell<bool>>,
|
|
}
|
|
|
|
util_assert_impl_all!(UnsafeCellUnion: imp::TryFromBytes);
|
|
|
|
#[test]
|
|
fn unsafe_cell_union() {
|
|
crate::util::test_is_safe::<UnsafeCellUnion, _>([0u8], true);
|
|
crate::util::test_is_safe::<UnsafeCellUnion, _>([1u8], true);
|
|
crate::util::test_is_safe::<UnsafeCellUnion, _>([2u8], false);
|
|
}
|