mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
29 lines
589 B
Rust
29 lines
589 B
Rust
use std::mem;
|
|
|
|
pub trait Seq {
|
|
fn next(&self) -> Self;
|
|
}
|
|
|
|
macro_rules! impl_seq {
|
|
($($ty:ty)*) => { $(
|
|
impl Seq for $ty {
|
|
fn next(&self) -> Self { (*self).wrapping_add(1) }
|
|
}
|
|
)* }
|
|
}
|
|
|
|
impl_seq!(u8 u16 u32 u64 usize);
|
|
|
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Default)]
|
|
pub struct SeqGenerator<T: Seq>(T);
|
|
|
|
impl<T: Seq> SeqGenerator<T> {
|
|
pub fn new(value: T) -> Self {
|
|
SeqGenerator(value)
|
|
}
|
|
|
|
pub fn get(&mut self) -> T {
|
|
let value = self.0.next();
|
|
mem::replace(&mut self.0, value)
|
|
}
|
|
}
|