#Can my function return a slice with only 1 heap-allocated variable?

1 messages · Page 1 of 1 (latest)

lucid coral
#

Hi, I have the following example:

pub fn getActiveWindows(self: *@This()) []const *Window {
    if (!self.selection.isEmpty()) return self.selection.windows.items;
    return &.{self.active_window};
}

Will I run into trouble when it comes to returning &.{self.active_window}?
Thank you very much.

coral elm
#

yes, you likely want to do (&self.active_window)[0..1]

lucid coral
#

thanks, I'll try it out

#

never tried that type of syntax before

#

sorry I forgot to clarify but self.active_window is a pointer *Window, not a literal variable Window.

coral elm
#

i understand, and my answer accounts for that