livox2 0.2.2

A lightweight and pure Rust implementation of Livox SDK2, based on async-net and zerocopy.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::sync::atomic::{AtomicU32, Ordering};

static SEQ: AtomicU32 = AtomicU32::new(1);
const MAX_SEQ: u32 = u16::MAX as u32;

pub fn next_seq() -> u32 {
    let seq = SEQ.fetch_update(Ordering::SeqCst, Ordering::Relaxed, |seq| {
        let seq = match seq {
            MAX_SEQ => 1,
            _ => seq + 1,
        };
        Some(seq)
    });
    // Safety: safe because fn in fetch_update always returns Some(seq).
    unsafe { seq.unwrap_unchecked() }
}