// expect: run // result: 0 // phase: 6 // spec: docs/spec/16-standard-library.md ยง2.4 module test.bounded import std.bytes; fn expect_copy(result: std.bytes.WriteResult, success: bool) -> void effects [] { match result { std.bytes.WriteResult::ok => { assert(success); } std.bytes.WriteResult::short_output => { assert(not success); } } } fn main() -> u8 effects [] { // Every source/output length through eight, including all empty combinations. var src: [u8; 8] = zero; for i in 0..src.len { src[i] = (i * 31 + 7) as! u8; } for count in 0usize..9usize { for capacity in 0usize..9usize { var dst: [u8; 10] = [165; 10]; expect_copy(std.bytes.copy(mut dst[1..1 + capacity], ref src[0..count]), capacity >= count); for i in 0..dst.len { if capacity >= count and i >= 1 and i < 1 + count { assert(dst[i] == src[i - 1]); } else { assert(dst[i] == 165); } } for i in 0..src.len { assert(src[i] == (i * 31 + 7) as! u8); } } } // Same allocation is allowed through proven disjoint split borrows. var buf: [u8; 8] = zero; for i in 0..4usize { buf[i] = i as! u8 + 1; } { mut all = buf; let (left, right) = all.split_at(4); expect_copy(std.bytes.copy(mut right, ref left), true); } assert(std.bytes.equal(ref buf, b"\x01\x02\x03\x04\x01\x02\x03\x04")); return 0; }