-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feedback on collectable #253
Comments
I'd really like to have this as well. Have you checked out the |
yup, comparing der and x509 with my own stuff is where this originates |
Composite types don't actually have to implement The API is callback-based to allow construction of intermediate field encoder types if necessary. Otherwise composite types only need to construct a slice of trait objects which represent their fields. |
I'm coming at this from the perspective of having need for an allocation-free X509 certificate generator, or more generally, the "DER encoder to end the plethora of semi-done DER encoders" :)
The feedback is that
collectable
(or a related trait for random insert e.ginsertable
orspliceable
) should should have some kind of "(overlapping) memmove" trait (and not just anVec::insert
-style operation that is called repeatedly).std::Vec
hassplice
, which is (maybe still?) slow: https://internals.rust-lang.org/t/add-vec-insert-slice-at-to-insert-the-content-of-a-slice-at-an-arbitrary-index/11008. Inheapless-bytes
, I implemented aninsert_slice_at
by hand: https://docs.rs/heapless-bytes/0.1.1/src/heapless_bytes/lib.rs.html#141-156.A need arises in allocation-free TLV encoding (to know L, need to encode V or somehow know its encoding's length first - both in the same pre-allocated buffer). I think
der::Encodable
solves this kind-of at compile time, by requiring theencoded_length
method in the trait, which someone has to implement on composite types (at least I think that's what happens - do correct me if I'm wrong). So you could easily do ato_heapless_vec
implementation there; I assume part of the motivation forcollectable
is to abstract over this and get ato_collectable
method.Whereas
derp::Der::nested
(which I think is an extraction fromring
) andx509::der::der_tlv
both do an allocation. I fix this for my current use cases inasn1derpy::Der::nested
(a temporary fork ofderp
) exactly by doing aninsert_slice_at
.But I'd really like a shared combinator-style approach (like
x509
) without the allocations. Ideally thender
would grow to cover both fixed types and dynamic encoding. Given both these libraries have prestigiously short names :)The goal for me is an API where the generic
n: usize
capacity parameter (orN: ArrayLength<u8>
en attendantmin_const_generics
) only needs to be specified once in the return type. Saying this from brute-forcing a heapless implementation ofx509.rs
in https://github.com/nickray/x509.rs/blob/heapless/src/der.rs#L107-L116, which has multiple issues:collectable
could avoid)N
everywherex509
'sder_tlv
implementation (which could be replaced byasn1derpy
's mem-move, usingcollectable
, if this had some kind ofinsert_iterator_at
/ efficientsplice
.What do you think? :)
The text was updated successfully, but these errors were encountered: