TeamPuzel
(Team Puzel)
January 24, 2023, 3:08pm
#1
I found this pitch from forever ago: Pitch: Deinit for structs
Now that references and ownership are being worked on, does that mean deinit
could finally be added to structs?
More powerful types without having to reach for reference counted classes sounds like a cool feature
3 Likes
scanon
(Steve Canon)
January 24, 2023, 3:21pm
#2
Yes, this has been discussed extensively in the proposals. See "Destructuring methods for move-only types with deinit
" under Future Directions in SE-0366 , for example. This is already partially supported behind a feature flag in the development toolchains (@Michael_Gottesman can tell you more on the implementation status).
2 Likes
TeamPuzel
(Team Puzel)
January 24, 2023, 3:30pm
#3
Oh, cool
Is that the -enable-experimental-move-only
flag or something else?
It doesn't seem like this flag allows move only structs with deinit on the toolchain from yesterday, unless the keyword is somehow different for now
*yeah I was forgetting the _
It works thank you
1 Like
scanon
(Steve Canon)
January 24, 2023, 4:23pm
#4
There are still plenty of rough edges to sand down, any bugs you might report are much appreciated.
1 Like
This was recently discussed here:
We've been building our way toward the concepts laid out in the ownership manifesto , introducing features that add new degrees of control over Swift's memory management and copying behavior. The ultimate level of control is to be able to declare a type that can't be copied at all, whether by value or by reference, opening up the ability for Swift to safely and efficiently represent resources that always have unique ownership, using a model similar to Rust to statically control access to and lifeβ¦