| 1 | struct Foo { |
| 2 | pub mut: |
| 3 | buf shared []u8 = []u8{len: 20, init: 6} |
| 4 | buf2 shared [20]u8 |
| 5 | } |
| 6 | |
| 7 | fn test_main() { |
| 8 | mut foo := Foo{ |
| 9 | buf2: [20]u8{init: 5} |
| 10 | } |
| 11 | rlock foo.buf { |
| 12 | if foo.buf.len > 0 { |
| 13 | x := 10 |
| 14 | println('first ${x} bytes: ' + foo.buf[..x].str()) |
| 15 | sliced := foo.buf[..x] |
| 16 | assert sliced == [u8(6), 6, 6, 6, 6, 6, 6, 6, 6, 6] |
| 17 | } else { |
| 18 | println('no data') |
| 19 | assert false |
| 20 | } |
| 21 | } |
| 22 | rlock foo.buf2 { |
| 23 | x := 4 |
| 24 | println('first ${x} bytes: ' + foo.buf2[..x].str()) |
| 25 | assert foo.buf2[..x] == [u8(5), 5, 5, 5] |
| 26 | } |
| 27 | } |
| 28 | |