Builtin types and their method implementations.
This module holds impl blocks for builtin types all items with #[lang(builtin_X)]
are
treated as X when lowering into IR, so they cannot actually exist as proper structs.
Builtin protocols also cannot be directly implemented by user code, even though they contain no associated functions. They are handled specially by the compiler.
Modules
Builtin types
()
)
!
)
Protocols
i8
, i16
, i32
, ...)
u8
, u16
, u32
, ...)
a..b
, a..=b
, ..b
, ..=b
, ...)
T
T
(regardless of mutability)
T
T
(same size and alignment)
T
Types
-
type unsigned_of<T> = when ...
T: IntegerUnsigned integer type of the same size as the original type.
Example
use std::typing::matches; use std::builtins::unsigned_of; assert!(matches::<unsigned_of<i32>, u32>()); assert!(matches::<unsigned_of<isize>, usize>()); assert!(matches::<unsigned_of<u8>, u8>());
Run this example -
type signed_of<T> = when ...
T: IntegerSigned integer type of the same size as the original type.
Example
use std::typing::matches; use std::builtins::signed_of; assert!(matches::<signed_of<u32>, i32>()); assert!(matches::<signed_of<usize>, isize>()); assert!(matches::<signed_of<i8>, i8>());
Run this example -
type element_of<T> = typeof(...)
T: ArrayElement type of the provided array
Example
use std::typing::matches; use std::builtins::element_of; assert!(matches::<element_of<[i32; 3]>, i32>());
Run this example -
type deref_of<T> = typeof(...)
T: PointerType of the pointed-to value
Example
use std::typing::matches; use std::builtins::deref_of; assert!(matches::<deref_of<&i32>, i32>()); assert!(matches::<deref_of<&mut i32>, i32>());
Run this example -
type tuple_head_of<T>
T: TupleType of the first element of the provided tuple
Example
use std::typing::matches; use std::builtins::tuple_head_of; assert!(matches::<tuple_head_of<(i32, u8, ())>, i32>());
Run this example -
type tuple_tail_of<T>
T: TupleTuple type equivalent to the provided one without the first element.
Passing empty tuple (void) is a compile-time error.
Example
use std::typing::matches; use std::builtins::tuple_tail_of; assert!(matches::<tuple_tail_of<(i32, u8, ())>, (u8, ())>()); assert!(matches::<tuple_tail_of<(i32,)>, ()>());
Run this example -
Return type of the provided function
Example
use std::typing::matches; use std::builtins::return_type_of; fn add(x: i32, y: i32) -> i32 { x + y } assert!(matches::<return_type_of<add>, i32>()); assert!(matches::<return_type_of<fn() -> u8>, u8>());
Run this example -
Tuple of argument types of the provided function
Example
use std::typing::matches; use std::builtins::arguments_of; fn add(x: i32, y: i32) -> i32 { x + y } assert!(matches::<arguments_of<add>, (i32, i32)>()); assert!(matches::<arguments_of<fn() -> u8>, ()>());
Run this example -
Tuple of the generic arguments of a given type
Example
use std::typing::matches; use std::builtins::generic_args_of; fn add<T>(x: T, y: T) -> T { x + y } assert!(matches::<generic_args_of<add<i32>>, (i32,)>()); assert!(matches::<generic_args_of<Result<&[u8], i32>>, (&[u8], i32)>()); assert!(matches::<generic_args_of<std::cmp::Ordering>, ()>());
Run this example -
type pointer_with_mut_of<T, Ptr>
Ptr: PointerPointer to
T
with same constness asPtr
.Example
use std::typing::matches; use std::builtins::pointer_with_mut_of; assert!(matches::<pointer_with_mut_of<void, &i32>, &void>()); assert!(matches::<pointer_with_mut_of<usize, &mut Option<usize>>, &mut usize>());
Run this example -
type array_with_length_of<T, Arr>
Arr: ArrayArray of
T
with same length asArr
.Example
use std::typing::matches; use std::builtins::array_with_length_of; assert!(matches::<array_with_length_of<i32, [(); 42]>, [i32; 42]>()); assert!(matches::<array_with_length_of<Option<bool>, [i64; 1337]>, [Option<bool>; 1337]>());
Run this example -
type enum_type_of<T>
T: EnumBacking type of an
enum
.Example
use std::typing::matches; use std::builtins::enum_type_of; enum Foo { A, B, C } enum Bar { A = 0usize, B, C } assert!(matches::<enum_type_of<Foo>, i32>()); assert!(matches::<enum_type_of<Bar>, usize>());
Run this example