Should I use Objects for unique structs? #307
-
Discord user IDEnjin Describe your question in detail.Hello, I had a question for how/when to use objects. I have a list of structs that I want to keep unique, and I'm curious if i can use an id field to identify them, or if its best to make them each an object. I would also need a way to identify each struct (i.e. being able to pass it in as parameter) What error, if any, are you getting?No response What have you tried or looked at? Or how can we reproduce the error?No response Which operating system are you using?N/A Which SDK or tool are you using? (if any)N/A Describe your environment or tooling in detailNo response |
Beta Was this translation helpful? Give feedback.
Answered by
MoonShiesty
Jul 22, 2024
Replies: 1 comment 2 replies
-
objects come with a unique id (address) so the object approach makes sense to me you can pass and store global references to objects with Object<MyStruct> |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i wouldn't use an object for singletons that don't have an owner, for example a GlobalConfig struct
objects allow you to type check, store and pass global references through Object
objects also allow you manage lifetimes, you can delete/transfer/upgrade through refs
aptos also supports named objects, which have a deterministic mapping between some key (name) and object address
if you really don't need those features an id probably works too