diff --git a/src/values/enums.rs b/src/values/enums.rs index 969b499e73d..3def22ca143 100644 --- a/src/values/enums.rs +++ b/src/values/enums.rs @@ -73,7 +73,12 @@ enum_value_set! {BasicValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, enum_value_set! {BasicMetadataValueEnum: ArrayValue, IntValue, FloatValue, PointerValue, StructValue, VectorValue, MetadataValue} impl<'ctx> AnyValueEnum<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of supported enum type options ([LLVMTypeKind]). + pub unsafe fn new(value: LLVMValueRef) -> Self { match LLVMGetTypeKind(LLVMTypeOf(value)) { LLVMTypeKind::LLVMFloatTypeKind | LLVMTypeKind::LLVMFP128TypeKind @@ -215,7 +220,12 @@ impl<'ctx> AnyValueEnum<'ctx> { } impl<'ctx> BasicValueEnum<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of supported enum type options ([LLVMTypeKind]). + pub unsafe fn new(value: LLVMValueRef) -> Self { match LLVMGetTypeKind(LLVMTypeOf(value)) { LLVMTypeKind::LLVMFloatTypeKind | LLVMTypeKind::LLVMFP128TypeKind @@ -334,7 +344,12 @@ impl<'ctx> BasicValueEnum<'ctx> { } impl<'ctx> AggregateValueEnum<'ctx> { - pub(crate) unsafe fn new(value: LLVMValueRef) -> Self { + /// Get a value from an [LLVMValueRef]. + /// + /// # Safety + /// + /// The ref must be valid and of supported aggregate type enum options ([LLVMTypeKind]). + pub unsafe fn new(value: LLVMValueRef) -> Self { match LLVMGetTypeKind(LLVMTypeOf(value)) { LLVMTypeKind::LLVMArrayTypeKind => AggregateValueEnum::ArrayValue(ArrayValue::new(value)), LLVMTypeKind::LLVMStructTypeKind => AggregateValueEnum::StructValue(StructValue::new(value)),