Enum CilPrimitiveKind
pub enum CilPrimitiveKind {
Show 23 variants
Void,
Boolean,
Char,
I1,
U1,
I2,
U2,
I4,
U4,
I8,
U8,
R4,
R8,
I,
U,
Object,
String,
Null,
TypedReference,
ValueType,
Var,
MVar,
Class,
}Expand description
Classification of all .NET primitive types from ECMA-335.
CilPrimitiveKind provides a complete enumeration of built-in .NET primitive types
as defined in the ECMA-335 specification. Each variant corresponds to a specific
System type and ELEMENT_TYPE constant.
§ECMA-335 Mapping
This enum directly maps to ELEMENT_TYPE constants (§II.23.1.16):
- Numeric types (I1, U1, I2, U2, I4, U4, I8, U8, R4, R8)
- Platform types (I, U for native integers)
- Character and string types (CHAR, STRING)
- Special types (VOID, BOOLEAN, OBJECT)
- Generic parameters (VAR, MVAR)
§Artificial Tokens
Each primitive kind has an associated artificial token (0xF000_XXXX range)
for use in type resolution and metadata table operations.
§Examples
use dotscope::metadata::typesystem::CilPrimitiveKind;
// Common primitive types
let int_type = CilPrimitiveKind::I4; // System.Int32
let bool_type = CilPrimitiveKind::Boolean; // System.Boolean
let str_type = CilPrimitiveKind::String; // System.String
// Get artificial token
let token = int_type.token();
println!("I4 token: 0x{:08X}", token.value());Variants§
Void
System.Void - represents no value or return type (ELEMENT_TYPE_VOID)
Boolean
System.Boolean - true/false value, single byte storage (ELEMENT_TYPE_BOOLEAN)
Char
System.Char - Unicode UTF-16 code unit, 16-bit value (ELEMENT_TYPE_CHAR)
I1
System.SByte - signed 8-bit integer (-128 to 127) (ELEMENT_TYPE_I1)
U1
System.Byte - unsigned 8-bit integer (0 to 255) (ELEMENT_TYPE_U1)
I2
System.Int16 - signed 16-bit integer (-32,768 to 32,767) (ELEMENT_TYPE_I2)
U2
System.UInt16 - unsigned 16-bit integer (0 to 65,535) (ELEMENT_TYPE_U2)
I4
System.Int32 - signed 32-bit integer (-2^31 to 2^31-1) (ELEMENT_TYPE_I4)
U4
System.UInt32 - unsigned 32-bit integer (0 to 2^32-1) (ELEMENT_TYPE_U4)
I8
System.Int64 - signed 64-bit integer (-2^63 to 2^63-1) (ELEMENT_TYPE_I8)
U8
System.UInt64 - unsigned 64-bit integer (0 to 2^64-1) (ELEMENT_TYPE_U8)
R4
System.Single - 32-bit IEEE 754 floating point (ELEMENT_TYPE_R4)
R8
System.Double - 64-bit IEEE 754 floating point (ELEMENT_TYPE_R8)
I
System.IntPtr - platform-specific signed integer (pointer-sized) (ELEMENT_TYPE_I)
U
System.UIntPtr - platform-specific unsigned integer (pointer-sized) (ELEMENT_TYPE_U)
Object
System.Object - root of the .NET type hierarchy, all types derive from this (ELEMENT_TYPE_OBJECT)
String
System.String - immutable sequence of UTF-16 characters (ELEMENT_TYPE_STRING)
Null
Null reference constant - used for null literal values in metadata
TypedReference
System.TypedReference - compiler-generated type for type-safe variable arguments
ValueType
System.ValueType - base class for all value types (structs, enums)
Var
Generic type parameter (T, U, etc.) from type definitions (ELEMENT_TYPE_VAR)
MVar
Generic method parameter (T, U, etc.) from method definitions (ELEMENT_TYPE_MVAR)
Class
General class reference - used for non-primitive reference types (ELEMENT_TYPE_CLASS)
Implementations§
§impl CilPrimitiveKind
impl CilPrimitiveKind
pub fn token(&self) -> Token
pub fn token(&self) -> Token
Get the artificial token for this primitive type.
Returns a unique artificial token in the 0xF000_XXXX range that can be used
to represent this primitive type in metadata operations and type resolution.
These tokens do not correspond to actual metadata table entries but provide
a consistent identifier for primitive types.
§Token Range
All primitive tokens use the artificial range 0xF000_0001 to 0xF000_0017,
which avoids conflicts with actual metadata table tokens.
§Returns
A unique Token for this primitive type
§Examples
use dotscope::metadata::typesystem::CilPrimitiveKind;
let int_token = CilPrimitiveKind::I4.token();
let bool_token = CilPrimitiveKind::Boolean.token();
assert_eq!(int_token.value(), 0xF000_0008);
assert_eq!(bool_token.value(), 0xF000_0002);pub fn typecode(&self) -> Option<i32>
pub fn typecode(&self) -> Option<i32>
Maps this primitive kind to a .NET System.TypeCode integer.
Returns the TypeCode enum value for primitive types that have one.
Non-primitive kinds (Object, Void, IntPtr, UIntPtr, etc.) return None.
pub fn is_value_type(&self) -> bool
pub fn is_value_type(&self) -> bool
Returns whether this primitive kind represents a .NET value type.
All numeric types, Boolean, Char, IntPtr, UIntPtr, and
TypedReference are value types. Void, Object, String, and
structural kinds (Class, ValueType, Var, MVar, Null) are not.
pub fn from_byte(type_byte: u8) -> Result<Self>
pub fn from_byte(type_byte: u8) -> Result<Self>
Parse primitive type from ELEMENT_TYPE byte constant.
Converts an ELEMENT_TYPE constant from ECMA-335 metadata into the corresponding
primitive type. This is used when parsing type signatures and metadata tables
that contain element type specifications.
§Arguments
type_byte-ELEMENT_TYPEconstant from metadata (see ECMA-335 §II.23.1.16)
§Returns
Ok(CilPrimitiveKind)- Successfully parsed primitive typeErr(TypeNotPrimitive)- Byte does not represent a valid primitive type
§Errors
This function will return an error if the provided byte does not correspond to a valid primitive type constant as defined in ECMA-335.
§ELEMENT_TYPE Mapping
Maps standard ELEMENT_TYPE constants to primitive kinds:
ELEMENT_TYPE_BOOLEAN(0x02) →BooleanELEMENT_TYPE_I4(0x08) →I4ELEMENT_TYPE_STRING(0x0E) →String- And so on for all supported primitive types
§Examples
use dotscope::metadata::typesystem::{CilPrimitiveKind, ELEMENT_TYPE};
let bool_kind = CilPrimitiveKind::from_byte(ELEMENT_TYPE::BOOLEAN)?;
assert_eq!(bool_kind, CilPrimitiveKind::Boolean);
let int_kind = CilPrimitiveKind::from_byte(ELEMENT_TYPE::I4)?;
assert_eq!(int_kind, CilPrimitiveKind::I4);pub const fn as_str(&self) -> &'static str
pub const fn as_str(&self) -> &'static str
Returns a stable &'static str identifier for this primitive kind.
The strings follow ILAsm / ECMA-335 §I.8.2.2 conventions and are part
of the stable public API — safe to persist (file, database, log line)
and to parse. Pointer-sized integers and the structural kinds use the
short ILAsm names rather than the C# / System.* aliases:
"void", "bool", "char", "int8", "uint8", "int16",
"uint16", "int32", "uint32", "int64", "uint64",
"float32", "float64", "native int", "native uint",
"object", "string", "null", "typedref", "valuetype",
"var", "mvar", "class".
Trait Implementations§
§impl Clone for CilPrimitiveKind
impl Clone for CilPrimitiveKind
§fn clone(&self) -> CilPrimitiveKind
fn clone(&self) -> CilPrimitiveKind
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CilPrimitiveKind
§impl Debug for CilPrimitiveKind
impl Debug for CilPrimitiveKind
§impl Display for CilPrimitiveKind
impl Display for CilPrimitiveKind
impl Eq for CilPrimitiveKind
§impl From<CilPrimitiveKind> for CilFlavor
impl From<CilPrimitiveKind> for CilFlavor
§fn from(kind: CilPrimitiveKind) -> Self
fn from(kind: CilPrimitiveKind) -> Self
§impl Hash for CilPrimitiveKind
impl Hash for CilPrimitiveKind
§impl PartialEq for CilPrimitiveKind
impl PartialEq for CilPrimitiveKind
impl StructuralPartialEq for CilPrimitiveKind
Auto Trait Implementations§
impl Freeze for CilPrimitiveKind
impl RefUnwindSafe for CilPrimitiveKind
impl Send for CilPrimitiveKind
impl Sync for CilPrimitiveKind
impl Unpin for CilPrimitiveKind
impl UnsafeUnpin for CilPrimitiveKind
impl UnwindSafe for CilPrimitiveKind
Blanket Implementations§
impl<T> Boilerplate for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for T
impl<T> Downcast for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more