-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support for Option<T> and Vec<T> with T as a struct/enum #14
Comments
Looking into this |
@romanoji I can add a implementation for Vector, the code generated is different for each data structure, so I don't think we can support this for every generic |
@Daksh14, sounds good to me. 👍 If you could handle it also for |
@misl-smlz, as I mentioned in my initial comment, I dropped |
You can be generic over something like |
Sorry for being inactive, The library uses I would also have to update the syn version because we use 1.x and 2.x is out |
My initial idea was about providing a blanket /// A blanket impl that allows sanitizing values inside of common data structures like [Option] and [Vec].
///
/// ## Example
///
/// ```
/// use sanitizer::Sanitize;
///
/// #[derive(Debug, PartialEq)]
/// struct MyValue(i32);
///
/// impl Sanitize for MyValue {
/// /// If the inner value is `0`, change it to `1`.
/// fn sanitize(&mut self) {
/// if self.0 == 0 {
/// self.0 = 1;
/// }
/// }
/// }
///
/// let mut wrapped_value = Some(MyValue(0));
/// wrapped_value.sanitize();
/// assert_eq!(wrapped_value, Some(MyValue(1)));
/// ```
impl<'a, A, T> Sanitize for T
where
A: 'a,
T: FunctorMut<'a, A>,
T::Inner: Sanitize,
{
fn sanitize(&mut self) {
self.fmap_mut(Sanitize::sanitize)
}
} But I tried making a PR and I get error[E0207]: the type parameter `A` is not constrained by the impl trait, self type, or predicates which I'm not sure how to resolve. If we won't be able to resolve this, then I'd just provide similar generic impls for |
Hello maintainers! 👋 The crate seems to lack of support for
Option<T>
, whereT
is a struct or an enum and forVec<T>
.Currently, it's not possible to
sanitize
a struct as a whole which relies on generic types other thanOption<T>
, withT
as a primitive.Here's an example:
When running such code it fails with the following errors:
I came up with a simple workaround for now, but it's quite bothersome to handle for more complex structs. It also requires to drop
#[sanitize]
proc macro to make it work.Here's a rough idea, based on an example shared above:
Based on my initial research it seems that handling
Option<T>
for structs/enums might be not that hard to implement.However, I'm not so sure about
Vec<T>
(and perhaps other iterables too).Looking forward to hear your thoughts about it. 🙂
The text was updated successfully, but these errors were encountered: