pub struct TypeHint { /* private fields */ }Expand description
A type hint.
This struct aims at being used in const contexts like in FromPyObject::INPUT_TYPE and IntoPyObject::OUTPUT_TYPE.
use pyo3::inspect::TypeHint;
const T: TypeHint = TypeHint::union(&[TypeHint::builtin("int"), TypeHint::module_attr("b", "B")]);
assert_eq!(T.to_string(), "int | b.B");Implementations§
Source§impl TypeHint
impl TypeHint
Sourcepub const fn builtin(name: &'static str) -> Self
pub const fn builtin(name: &'static str) -> Self
A builtin like int or list
use pyo3::inspect::TypeHint;
const T: TypeHint = TypeHint::builtin("int");
assert_eq!(T.to_string(), "int");Sourcepub const fn module_attr(module: &'static str, attr: &'static str) -> Self
pub const fn module_attr(module: &'static str, attr: &'static str) -> Self
A type contained in a module like datetime.time
use pyo3::inspect::TypeHint;
const T: TypeHint = TypeHint::module_attr("datetime", "time");
assert_eq!(T.to_string(), "datetime.time");Sourcepub const fn union(elts: &'static [TypeHint]) -> Self
pub const fn union(elts: &'static [TypeHint]) -> Self
The union of multiple types
use pyo3::inspect::TypeHint;
const T: TypeHint = TypeHint::union(&[TypeHint::builtin("int"), TypeHint::builtin("float")]);
assert_eq!(T.to_string(), "int | float");Sourcepub const fn subscript(value: &'static Self, slice: &'static [Self]) -> Self
pub const fn subscript(value: &'static Self, slice: &'static [Self]) -> Self
A subscribed type, often a container
use pyo3::inspect::TypeHint;
const T: TypeHint = TypeHint::subscript(&TypeHint::builtin("dict"), &[TypeHint::builtin("int"), TypeHint::builtin("str")]);
assert_eq!(T.to_string(), "dict[int, str]");Trait Implementations§
Auto Trait Implementations§
impl Freeze for TypeHint
impl RefUnwindSafe for TypeHint
impl Send for TypeHint
impl Sync for TypeHint
impl Unpin for TypeHint
impl UnwindSafe for TypeHint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more