Optional Chaining
The ?. operator (question mark operator) automatically handles the None case when accessing members of an optional value. If the receiver is Some(v), it accesses v's member and wraps it as Some; if it's None, it directly returns None without crashing.
Optional chaining supports multi-level access, such as user?.profile.address?.city. If any link in the chain is None, the entire expression returns None and subsequent accesses are not executed. This avoids multiple layers of if or match nesting.
Combined with the ?? operator, you can safely traverse multiple layers of optional values and provide defaults: user?.profile.address?.city ?? "Unknown city". Such chained calls are concise and safe.
?. can also be used for method calls obj?.method(), subscript access obj?[index], and trailing lambda calls.
Option type, which needs further handling or a default value via ??.