use std::{ffi::CStr, marker::PhantomData, ptr::NonNull};
use jl_sys::{
jl_abstractstring_type, jl_any_type, jl_anytuple_type, jl_argumenterror_type,
jl_atomicerror_type, jl_bool_type, jl_boundserror_type, jl_char_type, jl_const_type,
jl_datatype_t, jl_datatype_type, jl_emptytuple_type, jl_errorexception_type, jl_expr_type,
jl_field_index, jl_float16_type, jl_float32_type, jl_float64_type, jl_floatingpoint_type,
jl_function_type, jl_has_free_typevars, jl_initerror_type, jl_int8_type, jl_int16_type,
jl_int32_type, jl_int64_type, jl_loaderror_type, jl_methoderror_type, jl_module_type,
jl_new_structv, jl_nothing_type, jl_number_type, jl_signed_type, jl_simplevector_type,
jl_string_type, jl_symbol_type, jl_task_type, jl_tvar_type, jl_typeerror_type, jl_typename_str,
jl_typename_type, jl_typeofbottom_type, jl_uint8_type, jl_uint16_type, jl_uint32_type,
jl_uint64_type, jl_undefvarerror_type, jl_unionall_type, jl_uniontype_type, jl_vararg_type,
jl_voidpointer_type,
};
use jlrs_macros::julia_version;
use jlrs_sys::{
jlrs_datatype_abstract, jlrs_datatype_align, jlrs_datatype_first_ptr, jlrs_datatype_has_layout,
jlrs_datatype_instance, jlrs_datatype_isinlinealloc, jlrs_datatype_layout,
jlrs_datatype_mutable, jlrs_datatype_nfields, jlrs_datatype_parameters, jlrs_datatype_size,
jlrs_datatype_super, jlrs_datatype_typename, jlrs_datatype_zeroinit, jlrs_field_isptr,
jlrs_field_offset, jlrs_field_size, jlrs_get_fieldtypes, jlrs_is_concrete_type,
jlrs_is_primitivetype, jlrs_isbits, jlrs_nparams,
};
use super::{Weak, type_name::TypeName, value::ValueData};
use crate::{
convert::to_symbol::ToSymbol,
data::{
managed::{
Managed, private::ManagedPriv, simple_vector::SimpleVector, symbol::Symbol,
type_var::TypeVar, union_all::UnionAll, value::Value,
},
types::{construct_type::TypeVarEnv, typecheck::Typecheck},
},
impl_julia_typecheck,
memory::{
scope::LocalScopeExt,
target::{Target, TargetResult, unrooted::Unrooted},
},
private::Private,
};
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct DataType<'scope>(NonNull<jl_datatype_t>, PhantomData<&'scope ()>);
impl<'scope> DataType<'scope> {
#[inline]
pub fn type_name(self) -> TypeName<'scope> {
unsafe {
let name = jlrs_datatype_typename(self.unwrap(Private));
debug_assert!(!name.is_null());
TypeName::wrap_non_null(NonNull::new_unchecked(name), Private)
}
}
#[inline]
pub fn super_type(self) -> DataType<'scope> {
unsafe {
let super_ty = jlrs_datatype_super(self.unwrap(Private));
debug_assert!(!super_ty.is_null());
DataType::wrap_non_null(NonNull::new_unchecked(super_ty), Private)
}
}
#[inline]
pub fn parameters(self) -> SimpleVector<'scope> {
unsafe {
let parameters = jlrs_datatype_parameters(self.unwrap(Private));
debug_assert!(!parameters.is_null());
SimpleVector::wrap_non_null(NonNull::new_unchecked(parameters), Private)
}
}
#[inline]
pub fn n_parameters(self) -> usize {
unsafe { jlrs_nparams(self.unwrap(Private)) }
}
#[inline]
pub fn parameter(self, idx: usize) -> Option<Value<'scope, 'static>> {
unsafe {
let unrooted = Unrooted::new();
Some(self.parameters().data().get(unrooted, idx)?.as_value())
}
}
#[inline]
pub unsafe fn parameter_unchecked(self, idx: usize) -> Value<'scope, 'static> {
unsafe {
let unrooted = Unrooted::new();
self.parameters()
.data()
.get(unrooted, idx)
.unwrap_unchecked()
.as_value()
}
}
#[inline]
pub fn has_free_type_vars(self) -> bool {
unsafe { jl_has_free_typevars(self.unwrap(Private).cast()) != 0 }
}
#[inline]
pub fn field_types(self) -> SimpleVector<'scope> {
unsafe {
let field_types = jlrs_get_fieldtypes(self.unwrap(Private));
debug_assert!(!field_types.is_null());
SimpleVector::wrap_non_null(NonNull::new_unchecked(field_types), Private)
}
}
#[inline]
pub fn field_type(self, idx: usize) -> Option<Value<'scope, 'static>> {
unsafe {
let unrooted = Unrooted::new();
Some(self.field_types().data().get(unrooted, idx)?.as_value())
}
}
#[inline]
pub unsafe fn field_type_unchecked(self, idx: usize) -> Value<'scope, 'static> {
unsafe {
let unrooted = Unrooted::new();
self.field_types()
.data()
.get(unrooted, idx)
.unwrap_unchecked()
.as_value()
}
}
#[inline]
pub fn field_names(self) -> SimpleVector<'scope> {
self.type_name().names()
}
pub fn field_name(self, idx: usize) -> Option<Symbol<'scope>> {
unsafe {
let unrooted = Unrooted::new();
self.field_names()
.typed_data_unchecked::<Symbol>()
.get(unrooted, idx)
.map(|s| s.as_managed())
}
}
pub fn field_index<N: ToSymbol>(self, field_name: N) -> Option<usize> {
let idx = unsafe {
let sym = field_name.to_symbol_priv(Private);
jl_field_index(self.unwrap(Private), sym.unwrap(Private), 0)
};
if idx < 0 {
return None;
}
Some(idx as usize)
}
pub fn field_index_unchecked<N: ToSymbol>(self, field_name: N) -> i32 {
unsafe {
let sym = field_name.to_symbol_priv(Private);
jl_field_index(self.unwrap(Private), sym.unwrap(Private), 0)
}
}
#[inline]
pub fn field_name_str(self, idx: usize) -> Option<&'scope str> {
if let Some(sym) = self.field_name(idx) {
return sym.as_str().ok();
}
None
}
#[inline]
pub fn instance(self) -> Option<Value<'scope, 'static>> {
unsafe {
let instance = jlrs_datatype_instance(self.unwrap(Private));
if instance.is_null() {
None
} else {
Some(Value::wrap_non_null(
NonNull::new_unchecked(instance),
Private,
))
}
}
}
#[inline]
pub fn size(self) -> Option<u32> {
unsafe {
let t = self.unwrap(Private);
if jlrs_datatype_has_layout(t) == 0 || jlrs_datatype_layout(t).is_null() {
return None;
}
Some(jlrs_datatype_size(t))
}
}
#[inline]
pub fn is_abstract(self) -> bool {
unsafe { jlrs_datatype_abstract(self.unwrap(Private)) != 0 }
}
#[inline]
pub fn mutable(self) -> bool {
unsafe { jlrs_datatype_mutable(self.unwrap(Private)) != 0 }
}
#[inline]
pub fn is_concrete_type(self) -> bool {
unsafe { jlrs_is_concrete_type(self.as_value().unwrap(Private)) != 0 }
}
#[inline]
pub fn is_bits(self) -> bool {
unsafe { jlrs_isbits(self.unwrap(Private).cast()) != 0 }
}
#[inline]
pub fn zero_init(self) -> bool {
unsafe { jlrs_datatype_zeroinit(self.unwrap(Private)) != 0 }
}
#[inline]
pub fn is_inline_alloc(self) -> bool {
unsafe { jlrs_datatype_isinlinealloc(self.unwrap(Private)) != 0 }
}
#[inline]
pub fn is_primitive_type(self) -> bool {
unsafe { jlrs_is_primitivetype(self.unwrap(Private).cast()) != 0 }
}
#[inline]
pub fn is<T: Typecheck>(self) -> bool {
T::typecheck(self)
}
#[inline]
pub fn align(self) -> Option<u16> {
if !self.has_layout() {
return None;
}
unsafe { Some(jlrs_datatype_align(self.unwrap(Private))) }
}
#[inline]
pub fn has_layout(self) -> bool {
unsafe {
jlrs_datatype_has_layout(self.unwrap(Private)) != 0
&& !jlrs_datatype_layout(self.unwrap(Private).cast()).is_null()
}
}
#[inline]
pub fn n_bits(self) -> Option<u32> {
Some(self.size()? * 8)
}
#[inline]
pub fn n_fields(self) -> Option<u32> {
if !self.has_layout() {
return None;
}
unsafe { Some(jlrs_datatype_nfields(self.unwrap(Private))) }
}
#[inline]
pub fn name(self) -> &'scope str {
unsafe {
let name = jl_typename_str(self.unwrap(Private).cast());
CStr::from_ptr(name).to_str().unwrap()
}
}
pub fn field_size(self, idx: usize) -> Option<u32> {
let n_fields = self.n_fields()?;
if idx >= n_fields as usize {
return None;
}
unsafe { Some(jlrs_field_size(self.unwrap(Private), idx as _)) }
}
#[inline]
pub unsafe fn field_size_unchecked(self, idx: usize) -> u32 {
unsafe { jlrs_field_size(self.unwrap(Private), idx as _) }
}
pub fn field_offset(self, idx: usize) -> Option<u32> {
let n_fields = self.n_fields()?;
if idx >= n_fields as usize {
return None;
}
unsafe { Some(jlrs_field_offset(self.unwrap(Private), idx as _)) }
}
#[inline]
pub unsafe fn field_offset_unchecked(self, idx: usize) -> u32 {
unsafe { jlrs_field_offset(self.unwrap(Private), idx as _) }
}
pub fn is_pointer_field(self, idx: usize) -> Option<bool> {
let n_fields = self.n_fields()?;
if idx >= n_fields as usize {
return None;
}
unsafe { Some(jlrs_field_isptr(self.unwrap(Private), idx as _) != 0) }
}
#[inline]
pub unsafe fn is_pointer_field_unchecked(self, idx: usize) -> bool {
unsafe { jlrs_field_isptr(self.unwrap(Private), idx as _) != 0 }
}
pub fn is_atomic_field(self, idx: usize) -> Option<bool> {
let n_fields = self.n_fields()?;
if idx >= n_fields as usize {
return None;
}
unsafe { Some(self.is_atomic_field_unchecked(idx)) }
}
#[inline]
pub unsafe fn is_atomic_field_unchecked(self, idx: usize) -> bool {
unsafe {
let atomicfields = self.type_name().atomicfields();
if atomicfields.is_null() {
return false;
}
let isatomic = (*atomicfields.add(idx / 32)) & (1 << (idx % 32));
isatomic != 0
}
}
pub fn is_const_field(self, idx: usize) -> Option<bool> {
let n_fields = self.n_fields()?;
if idx >= n_fields as usize {
return None;
}
unsafe { Some(self.is_const_field_unchecked(idx)) }
}
#[inline]
pub unsafe fn is_const_field_unchecked(self, idx: usize) -> bool {
unsafe {
let tn = self.type_name();
if !tn.is_mutable() {
return true;
}
let constfields = tn.constfields();
if constfields.is_null() {
return false;
}
let isconst = (*constfields.add(idx / 32)) & (1 << (idx % 32));
isconst != 0
}
}
#[deprecated(
note = "This method will become private in the future, call the type's constructor instead by converting it to a `Value` and calling it as a function.",
since = "0.23.0"
)]
#[inline]
pub unsafe fn instantiate_unchecked<'target, 'value, 'data, V, Tgt>(
self,
target: Tgt,
values: V,
) -> ValueData<'target, 'data, Tgt>
where
Tgt: Target<'target>,
V: AsRef<[Value<'value, 'data>]>,
{
unsafe {
let values = values.as_ref();
let value = jl_new_structv(
self.unwrap(Private),
values.as_ptr() as *mut _,
values.len() as _,
);
target.data_from_ptr(NonNull::new_unchecked(value), Private)
}
}
#[inline]
pub(crate) unsafe fn instantiate_unchecked_priv<'target, 'value, 'data, V, Tgt>(
self,
target: Tgt,
values: V,
) -> ValueData<'target, 'data, Tgt>
where
Tgt: Target<'target>,
V: AsRef<[Value<'value, 'data>]>,
{
unsafe {
let values = values.as_ref();
let value = jl_new_structv(
self.unwrap(Private),
values.as_ptr() as *mut _,
values.len() as _,
);
target.data_from_ptr(NonNull::new_unchecked(value), Private)
}
}
pub fn has_pointer_fields(self) -> Option<bool> {
if !self.has_layout() {
return None;
}
unsafe { Some(jlrs_datatype_first_ptr(self.unwrap(Private)) != -1) }
}
#[inline]
pub fn rewrap<'target, Tgt: Target<'target>>(
self,
target: Tgt,
) -> ValueData<'target, 'static, Tgt> {
UnionAll::rewrap(target, self)
}
}
impl DataType<'_> {
pub fn has_indirect_typevar(self, tvar: TypeVar) -> bool {
let params = self.parameters();
let svec = params.data();
unsafe {
let unrooted = Unrooted::new();
for pidx in 0..svec.len() {
let param = svec.get(unrooted, pidx);
let param = param.expect("encountered null param").as_value();
if param.is::<TypeVar>() {
let param = param.cast_unchecked::<TypeVar>();
if param.has_indirect_typevar(tvar) {
return true;
}
}
}
}
false
}
pub fn wrap_with_env<'target, Tgt>(
self,
target: Tgt,
env: &TypeVarEnv,
) -> ValueData<'target, 'static, Tgt>
where
Tgt: Target<'target>,
{
let svec = env.to_svec();
let tvars = svec.data();
target.with_local_scope::<_, 1>(|target, mut frame| {
let mut reusable_slot = frame.reusable_slot();
unsafe {
let mut out = self.root(&mut reusable_slot).as_value();
for tidx in (0..tvars.len()).rev() {
let Some(tv) = tvars.get(&reusable_slot, tidx) else {
continue;
};
let tv = tv.as_value();
debug_assert!(tv.is::<TypeVar>());
let tv = tv.cast_unchecked::<TypeVar>();
if self.as_value().has_typevar(tv) {
out = UnionAll::new_unchecked(&mut reusable_slot, tv, out).as_value();
} else if self.has_indirect_typevar(tv) {
out = UnionAll::new_unchecked(&mut reusable_slot, tv, out).as_value();
}
}
out.root(target)
}
})
}
pub fn depends_on(&self, tvar: TypeVar) -> bool {
let parameters = self.parameters();
unsafe {
let data = parameters.data();
let slice = data.as_atomic_slice().assume_immutable_non_null();
slice.iter().any(|v| v.depends_on(tvar))
}
}
}
impl<'target> DataType<'target> {
#[inline]
pub fn typeofbottom_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_typeofbottom_type), Private) }
}
#[inline]
pub fn datatype_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_datatype_type), Private) }
}
#[inline]
pub fn uniontype_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_uniontype_type), Private) }
}
#[inline]
pub fn unionall_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_unionall_type), Private) }
}
#[inline]
pub fn tvar_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_tvar_type), Private) }
}
#[inline]
pub fn any_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_any_type), Private) }
}
#[inline]
pub fn typename_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_typename_type), Private) }
}
#[inline]
pub fn symbol_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_symbol_type), Private) }
}
#[inline]
pub fn const_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_const_type), Private) }
}
#[inline]
pub fn simplevector_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_simplevector_type), Private) }
}
#[inline]
pub fn anytuple_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_anytuple_type), Private) }
}
#[inline]
pub fn emptytuple_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_emptytuple_type), Private) }
}
#[inline]
pub fn tuple_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_anytuple_type), Private) }
}
#[inline]
pub fn vararg_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { DataType::wrap_non_null(NonNull::new_unchecked(jl_vararg_type), Private) }
}
#[inline]
pub fn function_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_function_type), Private) }
}
#[inline]
pub fn module_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_module_type), Private) }
}
#[inline]
pub fn abstractstring_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_abstractstring_type), Private) }
}
#[inline]
pub fn string_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_string_type), Private) }
}
#[inline]
pub fn errorexception_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_errorexception_type), Private) }
}
#[inline]
pub fn argumenterror_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_argumenterror_type), Private) }
}
#[inline]
pub fn loaderror_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_loaderror_type), Private) }
}
#[inline]
pub fn initerror_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_initerror_type), Private) }
}
#[inline]
pub fn typeerror_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_typeerror_type), Private) }
}
#[inline]
pub fn methoderror_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_methoderror_type), Private) }
}
#[inline]
pub fn undefvarerror_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_undefvarerror_type), Private) }
}
#[inline]
pub fn atomicerror_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_atomicerror_type), Private) }
}
#[inline]
pub fn boundserror_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_boundserror_type), Private) }
}
#[inline]
pub fn bool_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_bool_type), Private) }
}
#[inline]
pub fn char_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_char_type), Private) }
}
#[inline]
pub fn int8_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_int8_type), Private) }
}
#[inline]
pub fn uint8_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_uint8_type), Private) }
}
#[inline]
pub fn int16_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_int16_type), Private) }
}
#[inline]
pub fn uint16_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_uint16_type), Private) }
}
#[inline]
pub fn int32_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_int32_type), Private) }
}
#[inline]
pub fn uint32_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_uint32_type), Private) }
}
#[inline]
pub fn int64_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_int64_type), Private) }
}
#[inline]
pub fn uint64_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_uint64_type), Private) }
}
#[inline]
pub fn float16_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_float16_type), Private) }
}
#[inline]
pub fn float32_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_float32_type), Private) }
}
#[inline]
pub fn float64_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_float64_type), Private) }
}
#[inline]
pub fn floatingpoint_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_floatingpoint_type), Private) }
}
#[inline]
pub fn number_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_number_type), Private) }
}
#[inline]
pub fn nothing_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_nothing_type), Private) }
}
#[inline]
pub fn signed_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_signed_type), Private) }
}
#[inline]
pub fn voidpointer_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_voidpointer_type), Private) }
}
#[inline]
pub fn task_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_task_type), Private) }
}
#[inline]
pub fn expr_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_expr_type), Private) }
}
#[julia_version(since = "1.11")]
#[inline]
pub fn bfloat16_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe { Self::wrap_non_null(NonNull::new_unchecked(jl_sys::jl_bfloat16_type), Private) }
}
#[inline]
pub fn uint8pointer_type<Tgt>(_: &Tgt) -> Self
where
Tgt: Target<'target>,
{
unsafe {
Self::wrap_non_null(
NonNull::new_unchecked(jl_sys::jl_uint8pointer_type),
Private,
)
}
}
}
impl<'scope> PartialEq for DataType<'scope> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.as_value() == other.as_value()
}
}
impl<'scope, 'data> PartialEq<Value<'scope, 'data>> for DataType<'scope> {
#[inline]
fn eq(&self, other: &Value<'scope, 'data>) -> bool {
self.as_value() == *other
}
}
impl<'scope> Eq for DataType<'scope> {}
impl_debug!(DataType<'_>);
impl_julia_typecheck!(DataType<'frame>, jl_datatype_type, 'frame);
impl<'scope> ManagedPriv<'scope, '_> for DataType<'scope> {
type Wraps = jl_datatype_t;
type WithLifetimes<'target, 'da> = DataType<'target>;
const NAME: &'static str = "DataType";
#[inline]
unsafe fn wrap_non_null(inner: NonNull<Self::Wraps>, _: Private) -> Self {
Self(inner, ::std::marker::PhantomData)
}
#[inline]
fn unwrap_non_null(self, _: Private) -> NonNull<Self::Wraps> {
self.0
}
}
impl_construct_type_managed!(DataType, 1, jl_datatype_type);
pub type WeakDataType<'scope> = Weak<'scope, 'static, DataType<'scope>>;
pub type DataTypeRet = WeakDataType<'static>;
impl_valid_layout!(WeakDataType, DataType, jl_datatype_type);
use crate::memory::target::TargetType;
pub type DataTypeData<'target, Tgt> =
<Tgt as TargetType<'target>>::Data<'static, DataType<'target>>;
pub type DataTypeResult<'target, Tgt> = TargetResult<'target, 'static, DataType<'target>, Tgt>;
impl_ccall_arg_managed!(DataType, 1);
impl_into_typed!(DataType);