11 lines
365 B
Plaintext
11 lines
365 B
Plaintext
import std::io;
|
|||
|
|
type bytes = span<u8>;
|
||
|
|
type count = u64;
|
||
|
|
trait viewer<T> { def see(&this, from: u64): span<T>; }
|
||
|
|
struct box : viewer<u8> { var n: u8[3]; }
|
||
|
|
def box::see(&this, from: count): bytes { return this.n[from:3 - from]; }
|
||
|
|
def use(v: &viewer<u8>): u64 { return v.see(1).length; }
|
||
|
|
def main(): void {
|
||
|
|
val b := box{ n = [1, 2, 3] };
|
||
|
|
println($"{use(&b)}");
|
||
|
|
}
|