Great now I think I have solid base traits in place i.e., TpmCast, TpmCastMut, TpmHasCast and TpmHasCastMut:
I also relaxed the contribution guidelines just a little bit:
//! * `alloc` is disallowed.
//! * Dependencies are disallowed.
//! * Developer dependencies are disallowed.
-//! * Panics are disallowed.
+//! * Panics are allowed disallowed by default, except concrete type casts in
+//! `TpmCast::as_slice` is allowed to use `unwrap` as long as
+//! `TpmCast::from_slice` meets the documented contract.
This starts to “feel right” when it comes to “zerocopy”:
pub trait TpmCast<'a>: Sized {
fn cast(slice: &'a [u8]) -> TpmResult<Self>;
fn as_slice(&self) -> &'a [u8];
}
And pretty analogus to pre-existing TpmBuild and TpmParse i.e., they provide clone semantics and this is like hierarchical pointer.
It’s pretty easy to squeeze in because I only really have to edit macros for the most part. I have already basic types, and buffers and lists will follow the same patterns.
Can you use ident to play a type e.g.,
impl<'a> PartialEq<$ty> for TpmView<'a> {
fn eq(&self, other: &$ty) -> bool {
self.get() == *other
}
}
If “$ty” was ident, would this work?
Another more fun Rust related activity is figuring out how to nail batch file transfer test planning with emulated serial port that throttles the speed to a target BPS (in future also should have also signal noise emulation):
const ADJECTIVES: &[&str] = &["Quiet", "Loud", "Fast", "Slow", "Bright", "Dark"];
const NOUNS: &[&str] = &["One", "Two", "Three", "Four", "Five,", "Six"];
const EXTENSIONS: &[&str] = &["dat", "BIN", "log", "TMP", "txt"];
struct MockPort<R: Read, W: Write> {
r: R,
w: W,
bits_per_second: u32,
next_byte_due: Instant,
}
It generates 10 pseudorandom filenames and 100 KiB payloads.