Does there already exist functionality for detecting whether a variable has any mutable data? So something like ismutable(x)
except that it checks the mutability of the fields of x
recursively.
Not exactly that, but isbits(x)
, although unions can yield false negatives.
Also Base.allocatedinline(typeof(x))
can avoid these:
julia> struct MaybeMissing{T}
x::Union{Missing,T}
end
julia> x = MaybeMissing(1.2)
MaybeMissing{Float64}(1.2)
julia> Base.isbits(x)
false
julia> Base.allocatedinline(typeof(x))
true
Last updated: Dec 28 2024 at 04:38 UTC