Skip to content

Commit

Permalink
wip const generics fun
Browse files Browse the repository at this point in the history
  • Loading branch information
Shella committed May 7, 2021
1 parent 2b152ae commit 4f7130a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions rust/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::{
Message,
};
use digest::Digest;
use heapless::consts::U16;

/// Veriform decoder.
///
Expand All @@ -33,7 +32,7 @@ use heapless::consts::U16;
/// It's intended to be used in conjunction with the [`Message`] trait.
pub struct Decoder<D: Digest> {
/// Stack of message decoders (max nesting depth 16)
stack: heapless::Vec<message::Decoder<D>, U16>,
stack: heapless::Vec<message::Decoder<D>, 16>,

/// Sequence decoder if we're presently decoding a sequence
// TODO(tarcieri): support nested sequences?
Expand Down
9 changes: 3 additions & 6 deletions rust/src/derive_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
field::{self, Tag, WireType},
message::{Element, Message},
};
use digest::Digest;
use heapless::ArrayLength;
use digest::{Digest, generic_array::ArrayLength};


/// Make sure input has been consumed
pub fn check_input_consumed(input: &[u8]) -> Result<(), Error> {
Expand Down Expand Up @@ -99,10 +99,7 @@ pub trait TryExtend<A> {
T: IntoIterator<Item = A>;
}

impl<T, N> TryExtend<T> for heapless::Vec<T, N>
where
N: ArrayLength<T>,
{
impl<T, const N: usize> TryExtend<T> for heapless::Vec<T, N> {
fn try_extend<I: IntoIterator<Item = T>>(&mut self, iter: I) -> Result<(), ()> {
for elem in iter {
self.push(elem).map_err(|_| ())?
Expand Down

0 comments on commit 4f7130a

Please sign in to comment.