Can anyone help with std.RingBuffer

I’m trying to write and read slices from the std.RingBuffer but I’m not understanding exactly how to do this and can’t find any examples.

This is the write side (thread 1)
var slice = iq[0 … num_smpls * defs.BYTES_PER_SAMPLE];
// Copy the IQ data into the ring buffer
rb.writeSlice(slice) catch |err| {
if (err == error.Full) {
std.debug.print(“IQ ring buffer full!\n”, .{});

and the read side (thread 2)
var rb_slice: std.RingBuffer.Slice = try rb.sliceAt(rb.read_index, sz);
iq_data = rb_slice.first + rb_slice.second;

The write side compiles but the read side gives this error.
error: expected error union type, found ‘RingBuffer.Slice’

I’m pretty sure this is way off correct as I don’t understand how to use the start_unmasked parameters.

The error you’re getting is because try expects an error union to unwrap, but rb.sliceAt doesn’t return errors.

Thanks. So used to stuffing try in front of everything that should return an error. If there isn’t enough read space it should return an error. I need to play with it a bit because its not like other ring buffers I’ve used.