# \#struct

**URL:** https://discourse.julialang.org/tag/struct/383.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Create \`BigInt\` directedly from MPZ pointer](https://discourse.julialang.org/t/create-bigint-directedly-from-mpz-pointer/138903)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 6\
**Last updated:** [August 25, 2026, 5:52am UTC](https://discourse.julialang.org/t/create-bigint-directedly-from-mpz-pointer/138903 "2026-08-25T05:52:11Z")

</div>

I have some FFI code that interfaces with another library, and the target library has GNU multiprecision integers. Is it possible to create a BigInt directly from such a multiprecision integer pointer? The default constr…

---

## [Using type parameters in the types of the fields](https://discourse.julialang.org/t/using-type-parameters-in-the-types-of-the-fields/138790)

<div class="topic-metadata">

**Author:** [@rokke](https://discourse.julialang.org/u/rokke)\
**Replies:** 16\
**Last updated:** [August 20, 2026, 5:48am UTC](https://discourse.julialang.org/t/using-type-parameters-in-the-types-of-the-fields/138790 "2026-08-20T05:48:43Z")

</div>

I’m not a data structures person, so the right answer here might be “you’re doing it wrong, try this instead”; but I’ll start with the immediate question I have: in a recursive type, is it not possible to have the type …

---

## [Puzzling construction with executable statements in struct definition](https://discourse.julialang.org/t/puzzling-construction-with-executable-statements-in-struct-definition/136887)

<div class="topic-metadata">

**Author:** [@sgaure](https://discourse.julialang.org/u/sgaure)\
**Replies:** 2\
**Last updated:** [April 26, 2026, 9:22am UTC](https://discourse.julialang.org/t/puzzling-construction-with-executable-statements-in-struct-definition/136887 "2026-04-26T09:22:11Z")

</div>

I thought I had seen most things in julia, but I’ve come across the following construction which I don’t think I’ve seen in the docs: using MacroTools const gotit = Set() macro genconstructor(spec) if !@capture(spe…

---

## [Passing all functions on object A to object B](https://discourse.julialang.org/t/passing-all-functions-on-object-a-to-object-b/134654)

<div class="topic-metadata">

**Author:** [@alequa](https://discourse.julialang.org/u/alequa)\
**Replies:** 9\
**Last updated:** [December 31, 2025, 2:32pm UTC](https://discourse.julialang.org/t/passing-all-functions-on-object-a-to-object-b/134654 "2025-12-31T14:32:48Z")

</div>

Hello, I have the type: struct Car color::String model::String gears::Int end and I have another struct struct CarGroup cars::Vector{Car} end I would like all the functions called on Car to be applied …

---

## [Make custom type behave like Float64](https://discourse.julialang.org/t/make-custom-type-behave-like-float64/132926)

<div class="topic-metadata">

**Author:** [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Replies:** 4\
**Last updated:** [October 7, 2025, 2:12pm UTC](https://discourse.julialang.org/t/make-custom-type-behave-like-float64/132926 "2025-10-07T14:12:31Z")

</div>

(Related to Packages for colored REPL output?.) If I make a function return a custom type so that I can create a formatted show method for it, what functions do I then need to extend to make my type behave like Float64 …

---

## [How do I define a structure inside a function?](https://discourse.julialang.org/t/how-do-i-define-a-structure-inside-a-function/132379)

<div class="topic-metadata">

**Author:** [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Replies:** 8\
**Last updated:** [September 15, 2025, 9:47pm UTC](https://discourse.julialang.org/t/how-do-i-define-a-structure-inside-a-function/132379 "2025-09-15T21:47:33Z")

</div>

Hello, I want to define a structure inside a function: function PrintDate(d::Date) struct Date day::Int64 month::String year::Int64 end println(d.day,d.month,d.year) end chmas = Da…

---

## [Passing arguments separately versus packing them into a struct](https://discourse.julialang.org/t/passing-arguments-separately-versus-packing-them-into-a-struct/132291)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 5\
**Last updated:** [September 12, 2025, 1:38am UTC](https://discourse.julialang.org/t/passing-arguments-separately-versus-packing-them-into-a-struct/132291 "2025-09-12T01:38:09Z")

</div>

I regularly have a large number of arguments to carry around, where each of the arguments has a concrete type, but where the concrete types can be different (multiple dispatch). The arguments are typically more complica…

---

## [Change struct dataframe value correct way](https://discourse.julialang.org/t/change-struct-dataframe-value-correct-way/132121)

<div class="topic-metadata">

**Author:** [@rdl987](https://discourse.julialang.org/u/rdl987)\
**Replies:** 6\
**Last updated:** [September 8, 2025, 3:02pm UTC](https://discourse.julialang.org/t/change-struct-dataframe-value-correct-way/132121 "2025-09-08T15:02:05Z")

</div>

Hello I have a struct with inside other two structs: Base.@kwdef mutable struct MyDataset input::MyInputDataset = MyInputDataset() processed::MyInputDataset = MyInputDataset() end Base.@kwdef mutable struct MyInput…

---

## [Type stability and OffsetArray components of a struct](https://discourse.julialang.org/t/type-stability-and-offsetarray-components-of-a-struct/131313)

<div class="topic-metadata">

**Author:** [@billmclean](https://discourse.julialang.org/u/billmclean)\
**Replies:** 5\
**Last updated:** [August 6, 2025, 2:03am UTC](https://discourse.julialang.org/t/type-stability-and-offsetarray-components-of-a-struct/131313 "2025-08-06T02:03:33Z")

</div>

I found that @code\_warntype indicated a type instability in a finite difference code. The same issue arises in the following simple example. using OffsetArrays abstract type AbstractGrid end struct Grid \<: AbstractGr…

---

## [Broadcasting over an array of custom struct gives type instability](https://discourse.julialang.org/t/broadcasting-over-an-array-of-custom-struct-gives-type-instability/131086)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 5\
**Last updated:** [July 27, 2025, 9:02am UTC](https://discourse.julialang.org/t/broadcasting-over-an-array-of-custom-struct-gives-type-instability/131086 "2025-07-27T09:02:52Z")

</div>

Hello, I have a simple problem in Julia v1.10 using Test struct MyMatrix{MT\<:AbstractMatrix} M::MT end Base.:(\*)(A::MyMatrix, x::Number) = MyMatrix(A.M \* x) function f(x) # return \[y / 10 for y in x\] ret…

---

## [Order of Base.convert calls with \`@kwdef\` constructors](https://discourse.julialang.org/t/order-of-base-convert-calls-with-kwdef-constructors/130460)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 4\
**Last updated:** [July 4, 2025, 5:22am UTC](https://discourse.julialang.org/t/order-of-base-convert-calls-with-kwdef-constructors/130460 "2025-07-04T05:22:38Z")

</div>

Base.convert( ::Type{Int64}, x::AbstractString ) = parse(Int64,x) @kwdef struct X a::Int64 b::Int64=a+1 end X(a="1") ERROR: MethodError: no method matching +(::String, ::Int64) Can I make the conversion pars…

---

## [How to properly do thread-safe element-wise mutation on atomic fields?](https://discourse.julialang.org/t/how-to-properly-do-thread-safe-element-wise-mutation-on-atomic-fields/130138)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 4\
**Last updated:** [June 23, 2025, 7:57pm UTC](https://discourse.julialang.org/t/how-to-properly-do-thread-safe-element-wise-mutation-on-atomic-fields/130138 "2025-06-23T19:57:52Z")

</div>

MWE: julia\> mutable struct Atomic{T} @atomic a::T end julia\> obj1 = Atomic(collect(1:4)) Atomic{Vector{Int64}}(\[1, 2, 3, 4\]) julia\> obj1.a .= 2 4-element Vector{Int64}: 2 2 2 2 Unlike directly c…

---

## [How should one make a struct that handles a HTTP.jl server?](https://discourse.julialang.org/t/how-should-one-make-a-struct-that-handles-a-http-jl-server/129799)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 0\
**Last updated:** [June 11, 2025, 10:10am UTC](https://discourse.julialang.org/t/how-should-one-make-a-struct-that-handles-a-http-jl-server/129799 "2025-06-11T10:10:21Z")

</div>

HTTP.server says it can’t be finalizerd. ERROR: objects of type HTTP.Servers.Server{HTTP.Servers.Listener{Nothing, Sockets.TCPServer}} cannot be finalized So if I have a struct like mutable struct M reciverClient::HT…

---

## [Questions about function inside struct](https://discourse.julialang.org/t/questions-about-function-inside-struct/129669)

<div class="topic-metadata">

**Author:** [@Cyan](https://discourse.julialang.org/u/Cyan)\
**Replies:** 3\
**Last updated:** [June 5, 2025, 1:27pm UTC](https://discourse.julialang.org/t/questions-about-function-inside-struct/129669 "2025-06-05T13:27:55Z")

</div>

Hi, all. I am new to Julia, is it possible to build a function in struct, and whether it is efficient in coding comparing with an independent function? struct s a function f(x,a) return a\*x …

---

## [Tracking a program and storing information in a data structure](https://discourse.julialang.org/t/tracking-a-program-and-storing-information-in-a-data-structure/129651)

<div class="topic-metadata">

**Author:** [@billyblueberry](https://discourse.julialang.org/u/billyblueberry)\
**Replies:** 0\
**Last updated:** [June 4, 2025, 6:06pm UTC](https://discourse.julialang.org/t/tracking-a-program-and-storing-information-in-a-data-structure/129651 "2025-06-04T18:06:50Z")

</div>

I am relatively new to Julia (\<1 year) and I am developing a tool for tracking floating point addition. I have set up my work as a package, here is a reduced MWE: module TestModule # used for storing information when a…

---

## [Struct with read-only and write-only properties](https://discourse.julialang.org/t/struct-with-read-only-and-write-only-properties/129179)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 7\
**Last updated:** [May 21, 2025, 7:15pm UTC](https://discourse.julialang.org/t/struct-with-read-only-and-write-only-properties/129179 "2025-05-21T19:15:16Z")

</div>

Suppose I have the following mutable struct @kwdef mutable struct Rectangle{T} x::T = 0 y::T = 0 function Rectangle(args...) return new{promote\_type(typeof.(args)...)}(args...) end end I would like for this…

---

## [Revise type annotations without edits?](https://discourse.julialang.org/t/revise-type-annotations-without-edits/128700)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 0\
**Last updated:** [May 5, 2025, 4:16am UTC](https://discourse.julialang.org/t/revise-type-annotations-without-edits/128700 "2025-05-05T04:16:03Z")

</div>

Because of the upcoming world age-partitioned semantics (PR #57253), Revise can pull off type redefinitions by reassigning the const name (Issue #18). Let’s say we start with: julia\> begin struct X{T} x::T end; …

---

## [Correct usage of type-dependent constructors](https://discourse.julialang.org/t/correct-usage-of-type-dependent-constructors/128605)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 7\
**Last updated:** [May 2, 2025, 11:33am UTC](https://discourse.julialang.org/t/correct-usage-of-type-dependent-constructors/128605 "2025-05-02T11:33:29Z")

</div>

Hello, I need to create a constructor with a parametric type to be able to dispatch. One possible way is the following abstract type MyType end # Singletons occupying 0 bytes struct Type1 \<: MyType end struct Type2 \<:…

---

## [Mutually recursive types, recommended style?](https://discourse.julialang.org/t/mutually-recursive-types-recommended-style/128228)

<div class="topic-metadata">

**Author:** [@DrEntropy](https://discourse.julialang.org/u/DrEntropy)\
**Replies:** 2\
**Last updated:** [April 20, 2025, 12:41am UTC](https://discourse.julialang.org/t/mutually-recursive-types-recommended-style/128228 "2025-04-20T00:41:39Z")

</div>

When faced with a situation where you may need mutually recursive types like this: mutable struct MyAgent \<: AbstractAgent id::Int friendB :: AbstractAgent # will always be AgentB type though #other fields …

---

## [From Named Tuple to Struct](https://discourse.julialang.org/t/from-named-tuple-to-struct/127927)

<div class="topic-metadata">

**Author:** [@Magnus\_Lilledahl](https://discourse.julialang.org/u/Magnus_Lilledahl)\
**Replies:** 2\
**Last updated:** [April 10, 2025, 2:35pm UTC](https://discourse.julialang.org/t/from-named-tuple-to-struct/127927 "2025-04-10T14:35:24Z")

</div>

Say I have a Named Tuple like a = (switch = dataframe1, swatch = dataframe2) and I have some structs struct switch df::DataFrame ...more fields end struct swatch df::DataFrame ...more fields end I want to ite…

---

## [Difficulty when differentiating with DifferentiationInterface.jl and Mooncake.jl](https://discourse.julialang.org/t/difficulty-when-differentiating-with-differentiationinterface-jl-and-mooncake-jl/125982)

<div class="topic-metadata">

**Author:** [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Replies:** 3\
**Last updated:** [February 17, 2025, 5:23pm UTC](https://discourse.julialang.org/t/difficulty-when-differentiating-with-differentiationinterface-jl-and-mooncake-jl/125982 "2025-02-17T17:23:25Z")

</div>

Hello everyone. I am stuck with the following problem for which I have created below a MWE. It concerns automatic differentiation using DifferentiationInterface.jl together with Mooncake.jl. From the error message I get,…

---

## [Redefine Struct when working with REPL](https://discourse.julialang.org/t/redefine-struct-when-working-with-repl/25942)

<div class="topic-metadata">

**Author:** [@LudiWin](https://discourse.julialang.org/u/LudiWin)\
**Replies:** 10\
**Last updated:** [January 21, 2025, 2:03am UTC](https://discourse.julialang.org/t/redefine-struct-when-working-with-repl/25942 "2025-01-21T02:03:06Z")

</div>

Hi, I would like to use structs to bundle values in a way similar to pure OOP. So I would create a struct to encapsulate the relevant attributes. Down below is an example: struct Lion maneColor::String roar::…

---

## [Error at structure initialization](https://discourse.julialang.org/t/error-at-structure-initialization/124893)

<div class="topic-metadata">

**Author:** [@Bogdan\_Virag](https://discourse.julialang.org/u/Bogdan_Virag)\
**Replies:** 1\
**Last updated:** [January 19, 2025, 12:06pm UTC](https://discourse.julialang.org/t/error-at-structure-initialization/124893 "2025-01-19T12:06:26Z")

</div>

Hi! I created a structure for ML (for a generalized linear modell) and i want to store the linking function by initializing the structure using the name of the distribution. The code of the structure: mutable struct G…

---

## [Error: Structure using its function](https://discourse.julialang.org/t/error-structure-using-its-function/124617)

<div class="topic-metadata">

**Author:** [@Bogdan\_Virag](https://discourse.julialang.org/u/Bogdan_Virag)\
**Replies:** 4\
**Last updated:** [January 17, 2025, 3:43pm UTC](https://discourse.julialang.org/t/error-structure-using-its-function/124617 "2025-01-17T15:43:58Z")

</div>

Hi! I want to create this structure for generalized linear models (GLM) but I get the following error message: ERROR: type GLM has no field train! Stacktrace: \[1\] getproperty @ ./Base.jl:49 \[inlined\] \[2\] main() @ …

---

## [Passing a Julia struct to a already compiled cpp program](https://discourse.julialang.org/t/passing-a-julia-struct-to-a-already-compiled-cpp-program/124731)

<div class="topic-metadata">

**Author:** [@TheBreadFarmer](https://discourse.julialang.org/u/TheBreadFarmer)\
**Replies:** 1\
**Last updated:** [January 13, 2025, 6:01pm UTC](https://discourse.julialang.org/t/passing-a-julia-struct-to-a-already-compiled-cpp-program/124731 "2025-01-13T18:01:10Z")

</div>

I am writing a program in Julia that reads data from a file into memory. I’d like to take that data and somehow pass it to a c++ program which will make use of OpenGL to draw that data to the screen. I am making use of …

---

## [Improving error messages for structs](https://discourse.julialang.org/t/improving-error-messages-for-structs/124390)

<div class="topic-metadata">

**Author:** [@Ken\_Williams](https://discourse.julialang.org/u/Ken_Williams)\
**Replies:** 2\
**Last updated:** [January 3, 2025, 1:02am UTC](https://discourse.julialang.org/t/improving-error-messages-for-structs/124390 "2025-01-03T01:02:29Z")

</div>

If I have a situation like the following: struct Bar x::Float64 y::Float64 end Bar(missing, 2) then the error message doesn’t seem to indicate whether x or y was the problem: ERROR: LoadError: MethodError: Ca…

---

## [Pluto.jl - How do I dispatch to a subtype created in a notebook?](https://discourse.julialang.org/t/pluto-jl-how-do-i-dispatch-to-a-subtype-created-in-a-notebook/124162)

<div class="topic-metadata">

**Author:** [@g-gundam](https://discourse.julialang.org/u/g-gundam)\
**Replies:** 2\
**Last updated:** [December 25, 2024, 1:18am UTC](https://discourse.julialang.org/t/pluto-jl-how-do-i-dispatch-to-a-subtype-created-in-a-notebook/124162 "2024-12-25T01:18:30Z")

</div>

I created a small package called ProblematicAnimals.jl to demonstrate a problem I’m having with Pluto.jl notebooks. I sincerely hope a solution to this can be found. Defined outside of Pluto abstract type AbstractAnima…

---

## [Mutable structs with all constant fields outperform immutable structs for equality comparison](https://discourse.julialang.org/t/mutable-structs-with-all-constant-fields-outperform-immutable-structs-for-equality-comparison/123430)

<div class="topic-metadata">

**Author:** [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Replies:** 1\
**Last updated:** [December 4, 2024, 12:13am UTC](https://discourse.julialang.org/t/mutable-structs-with-all-constant-fields-outperform-immutable-structs-for-equality-comparison/123430 "2024-12-04T00:13:04Z")

</div>

MWE: julia\> x1 = \[rand(Int) for \_=1:1000\]; julia\> x2 = \[rand(Int) for \_=1:1000\]; julia\> v1 = \[rand(3,3) for \_=1:1000\]; julia\> v2 = \[rand(3,3) for \_=1:1000\]; julia\> struct myT a::Int b::Any end …

---

## [Mutable struct vs Ref in an immutable one?](https://discourse.julialang.org/t/mutable-struct-vs-ref-in-an-immutable-one/92846)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 7\
**Last updated:** [November 28, 2024, 6:04pm UTC](https://discourse.julialang.org/t/mutable-struct-vs-ref-in-an-immutable-one/92846 "2024-11-28T18:04:24Z")

</div>

I want to define a struct where one field is mutable, and one isn’t,. I see two ways to approach this: struct A x :: Int y :: typeof(Ref(1)) end and mutable struct B const x :: Int y :: Int end Wh…

---

## [Allocations when using getfield with a tuple/vector of symbols](https://discourse.julialang.org/t/allocations-when-using-getfield-with-a-tuple-vector-of-symbols/122756)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 12\
**Last updated:** [November 20, 2024, 2:45am UTC](https://discourse.julialang.org/t/allocations-when-using-getfield-with-a-tuple-vector-of-symbols/122756 "2024-11-20T02:45:24Z")

</div>

MWE: using Parameters, BenchmarkTools @with\_kw struct Test A :: String = "A" B :: Int64 = 0 end test = Test() tup = (:A, :B) @btime getfield($test, :A) @btime getfield($test, $tup\[1\]) Is there a way to loop…

[Next page](https://discourse.julialang.org/tag/struct/383.md?match_all_tags=true&page=1&tags%5B%5D=struct)
