Ryan
Ryan
MModular
Created by Ryan on 11/1/2024 in #questions
How Unsafe/Safe is this code?
Whenever you append or get from it, I just bitcasts the pointer to the provided type. So I don't need to keep track of element locations in the pointer because the pointer is accessed like it is UnsafePointer[T]. Is this what you are referencing?
fn append[T: CollectionElement](inout self, owned value: T) raises:
var data_ptr = self.data.bitcast[T]()
(data_ptr + self.element_count).init_pointee_move(value^)

fn get[T: CollectionElement](inout self, idx: Int) raises -> ref [__lifetime_of(self)] T:
return self.data.bitcast[T]()[idx]
fn append[T: CollectionElement](inout self, owned value: T) raises:
var data_ptr = self.data.bitcast[T]()
(data_ptr + self.element_count).init_pointee_move(value^)

fn get[T: CollectionElement](inout self, idx: Int) raises -> ref [__lifetime_of(self)] T:
return self.data.bitcast[T]()[idx]
5 replies
MModular
Created by toasty on 5/30/2024 in #questions
Is it possible to store a list of References in Struct?
Something like this
var arr = InlineArray[command, 10](command())
var cli = CLI[True, __lifetime_of(arr)]()
# if it had an add method
cli.add(arr[i])
var arr = InlineArray[command, 10](command())
var cli = CLI[True, __lifetime_of(arr)]()
# if it had an add method
cli.add(arr[i])
10 replies
MModular
Created by toasty on 5/30/2024 in #questions
Is it possible to store a list of References in Struct?
It is possible if the items going into the list share a lifetime. If they are stored together in some other structure you can use that structures lifetime for the list. Or maybe you could use a MutableStaticLifetime for the list.
10 replies
MModular
Created by diro5t on 3/10/2024 in #questions
Debugger not stopping
6 replies
MModular
Created by diro5t on 3/10/2024 in #questions
Debugger not stopping
I have the same issue, but not in codespaces, just vscode. Should I file a separate issue?
6 replies