Skip to main content

Module extract_option

Module extract_option 

Source
Expand description

Functions to extract a type T from a type declaration Option<T>.

These functions return Result rather than Option so they can be used with the ? operator

§Heuristics

Since proc-macros don’t have access to type information, we have no way of telling if some Type is really an Option. We can only guess.

ⓘ
use Vec as Option;

#[derive(Serialize)]
struct Evil {
    // oh no
    evil: Vec<String>
}

These functions will return Ok if the given Type is a Type::Path, with a single generic argument, and the last path segment is "Option"

Functions§

from_mut
Extracts a &mut Type T from an Option<T>
from_owned
Extracts T from Option<T>
from_ref
Extracts a &Type T from an Option<T>