Skip to content

Commit

Permalink
Add assert for alkahest::deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarumych committed Nov 8, 2023
1 parent a0e85ba commit d66006d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/deserialize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::{iter::FusedIterator, marker::PhantomData, str::Utf8Error};
use core::{any::type_name, iter::FusedIterator, marker::PhantomData, str::Utf8Error};

use crate::{
formula::{reference_size, unwrap_size, Formula},
Expand Down Expand Up @@ -669,6 +669,23 @@ where
F: Formula + ?Sized,
T: Deserialize<'de, F>,
{
assert!(
F::HEAPLESS || F::MAX_STACK_SIZE.is_some(),
"The value must be either sized or heap-less.
{} is {} {}",
type_name::<F>(),
if F::HEAPLESS {
"heapless but"
} else {
"not heapless and"
},
if F::MAX_STACK_SIZE.is_some() {
"sized"
} else {
"not sized"
}
);

let stack = match F::MAX_STACK_SIZE {
None => input.len(),
Some(max_stack) => max_stack.min(input.len()),
Expand Down

0 comments on commit d66006d

Please sign in to comment.