#How to call method from optional pointer?
1 messages · Page 1 of 1 (latest)
1 messages · Page 1 of 1 (latest)
Like
const Foo = struct {
pub fn bar(self: *Foo) i32 {
return 42;
}
};
var some: ?*Foo = null;
// ... assign somewhere
pub fn other() {
const something = some.bar() orelse 0;
obviously would not work
const something = (some orelse 0).bar(); also would not