-
I realized, that providing my a struct with Options in it, e.g. Option, will render to "none", if the Option is set to None, and even the builtin "default" filter will not help, as in that case the variable is not undefined, as "None" is a valid value, and the property is part of my context struct. I started thinking about implementing a custom implementation of default that also works on None values, but I just wanted to ask if anyone else has encountered this, and if this is even possible (given it might go into generics), or if my approach to this problem is wrong in the first place trying to solve this with a filter |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Just found .is_none() on value 😆 so a copy of default() and expanding it like this pub fn none(value: Value, other: Option<Value>) -> Value {
if value.is_undefined() || value.is_none() {
other.unwrap_or_else(|| Value::from(""))
} else {
value
}
} did it. |
Beta Was this translation helpful? Give feedback.
Just found .is_none() on value 😆
so a copy of default() and expanding it like this
did it.