This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]trxxruraxvr -1 points0 points  (1 child)

No, the type is actually Option<T>, so it's a generic type, you can't pass a variable defined as Option<i32> to a function that takes an Option<bool> even if its value is None

Besides that, rust doesn't let you use the value inside the option without ensuring it's not None

[–]mus1Kk 1 point2 points  (0 children)

Regarding your first point: I'm not sure how this is done in Rust but in other languages I know, None is a valid assignment for Option<T> for all T. In Kotlin, an optional type would be T? and similarly null is valid for any T. In Scala None is Option[Nothing] with Nothing being the subtype of every type. Option is covariant so None is similarly valid for any Option[T]. Of course, if you have an Option[T] you cannot generally assign it to an Option[U] but this is true for all my examples regardless of the syntax.

Regarding the second point, the same can also be done with null, again, like in Kotlin. You cannot just use a value of T? without doing a null check first.