You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.
I will be working on a pull request for this soon, but decided to ask here for any comments first.
This issue involves adding an impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> and impl<T: FromJSValConvertible> FromJSValConvertible for Option<T>.
Reason
This will be helpful for creating methods with optional parameters, such as console.assert, and more closely allow for the reproduction of javascript function calls, which can accept any number of parameters, regardless of the number specified in the definition.
FromJSValConvertible
When the Value is undefined, the method will return None and will return Some(x) otherwise.
ToJSValConvertible
When the value is None, the method will return undefined as a Value and the regular value otherwise.
The text was updated successfully, but these errors were encountered:
I am looking through the code currently, and it seems that both of these are already implemented. However, it also seems that ToJSValConvertible for None returns null, instead of undefined. This behaviour may need to be reconsidered.
Oh, that's a good point. Changing that would almost certainly imapact web-visible code in Servo, and I think the current behaviour makes sense. You could try creating a struct Undefinable<T>(Option<T>) and implement ToJSValConvertible for Undefinable in your own crate.
I think I shall leave the behaviour as it stands currently, and add Nullable<T> and Undefinable<T> if I require, later.
Null is something that does not exist and is returned explicitly (generally), while undefined is something that does not exist and is returned implicitly (e.g. function with no return statement). It makes sense that explicitly returning a Option<T> from rust, would result in null instead of undefined.
I will be working on a pull request for this soon, but decided to ask here for any comments first.
This issue involves adding an
impl<T: ToJSValConvertible> ToJSValConvertible for Option<T>
andimpl<T: FromJSValConvertible> FromJSValConvertible for Option<T>
.Reason
This will be helpful for creating methods with optional parameters, such as
console.assert
, and more closely allow for the reproduction of javascript function calls, which can accept any number of parameters, regardless of the number specified in the definition.FromJSValConvertible
When the Value is
undefined
, the method will returnNone
and will returnSome(x)
otherwise.ToJSValConvertible
When the value is
None
, the method will returnundefined
as a Value and the regular value otherwise.The text was updated successfully, but these errors were encountered: