Re: [PATCH 1/3] rust: add untrusted data abstraction

From: Benno Lossin
Date: Fri Sep 13 2024 - 09:48:06 EST


On 13.09.24 15:41, Finn Behrens wrote:
> On 13 Sep 2024, at 13:26, Benno Lossin wrote:
>> +pub trait Validator {
>> + /// Type of the input data that is untrusted.
>> + type Input: ?Sized;
>
> I would like to explore this trait with being generic over Input, instead of having Input as an associated type. Might be nicer to have Validators for different input types if the valid data is always the same?

I think I have changed my opinion on this from Kangrejos, I like the
idea. Then we would also be able to do something like this:

impl<I> Validator<I> for Foo
where
I: Deref<Target = [u8]>,
{
/* ... */
}

---
Cheers,
Benno

>> + /// Type of the validated data.
>> + type Output;
>> + /// Validation error.
>> + type Err;
>> +
>> + /// Validate the given untrusted data and parse it into the output type.
>> + ///
>> + /// When implementing this function, you can use [`Untrusted::untrusted()`] to get access to
>> + /// the raw untrusted data.
>> + fn validate(untrusted: &Untrusted<Self::Input>) -> Result<Self::Output, Self::Err>;
>> +}
>> --
>> 2.46.0