I think I fixup lookup tables for escaping #zmodem traffic by intercepting traffic from lrzsz with “defacto” parameters, i.e. send large chunk of uniform distributed random data. That way I can be sure that I have all the cases, including those not in the specification form 1988.
Later on I can use that as a CI test for my crate. Sort of fuzzing approach. I just need to record all bytes that follow ASCII 24 and that builds my table.
I’ve been using Rust professionally way or another for about 2 years now and at least this and also lack of e.g. BufRead
abstraction (sorry trait) has been something that I’ve been cursing to this day because it enforces you to do totally unproductive boilerplate and glue for everything you do with Rust. So definitely a huge improvement is this… Doing some RidiculousError
type for every no_std
thing is just terrible IMHO. For 95% of stuff I’d rather use just predefined error codes. It also improves productivity by factors when all your crates communicate with same error codes.
Abstraction only ever make sense if they have some meaningful functional use. Otherwise, they are just code bloat.
embedded-io
and embedded-io-async
seem to be something i would want to use also for crates meant to be used with std just to future-proof portability. great that there is solution for std::io
issue finally. for me the disability to e.g. not being able to use std::io::Error
in no_std
code has been a huge turndown.
and since these are provided by the Rust HAL team there’s some trust for long-term lifespan. 3rd party solutions in the basic error types and BufRead
is a maintenance risk imho.
this is good enough as far as i’m concerned
So I did a pull request to the hex
crate:
https://github.com/KokaKiwi/rust-hex/pull/83
This sort of scenario is not too uncommon in data flows especially when you want to squeeze everything bit out. E.g. for something like #ZMODEM you’d prefer the implementation to scale from microcontroller to Intel Xeon.
Usage example in my crate:
if encoding == Encoding::ZHEX {
hex::decode_in_slice(&mut out).or::<io::Error>(Err(ErrorKind::InvalidData.into()))?;
out.truncate(out.len() / 2);
}
One thing that I had to dig up from previous #Enarx work was core::marker::PhantomData
. It is not so well known but pretty important concept inside Rust.
PhantomData
is a zero-sized struct that merely acts as a life-time indicator for the other parameter, which are usually pointers on where it is applied. It is used to implement many of the core structs such as Rc
to name one instance.
It is pretty good lesson on how lifetime parameters interact with the Rust compiler.
I’d even say that if you understand PhantomData
, then you have the basic understanding of Rust, and if not, you still have to learn a bit. It is the block that the whole core library is based on after all.
I’d actually recommend to do few exercises with just from_raw_parts
and lifetime parameters before using zerocopy
because that sort of gives you full tutorial on what that particular crate does internally :-) I sort of enjoy thinking of those scenarios so it also takes some fun away :-)