use kevy_resp::ArgvView;
#[cfg(not(target_arch = "wasm32"))]
pub(crate) struct Args<'a>(&'a [Vec<u8>]);
#[cfg(not(target_arch = "wasm32"))]
impl<'a> Args<'a> {
pub(crate) fn new(argv: &'a [Vec<u8>]) -> Self {
Args(argv)
}
}
#[cfg(not(target_arch = "wasm32"))]
impl core::ops::Index<usize> for Args<'_> {
type Output = [u8];
fn index(&self, i: usize) -> &[u8] {
&self.0[i]
}
}
#[cfg(not(target_arch = "wasm32"))]
impl ArgvView for Args<'_> {
fn len(&self) -> usize {
self.0.len()
}
fn get(&self, i: usize) -> Option<&[u8]> {
self.0.get(i).map(Vec::as_slice)
}
}
#[cfg(target_arch = "wasm32")]
pub(crate) enum Args<'a> {
Client(&'a [Vec<u8>]),
#[cfg_attr(not(feature = "persist"), allow(dead_code, reason = "only a replay builds it"))]
Frame(&'a kevy_resp::Argv),
}
#[cfg(target_arch = "wasm32")]
impl<'a> Args<'a> {
pub(crate) fn new(argv: &'a [Vec<u8>]) -> Self {
Args::Client(argv)
}
}
#[cfg(target_arch = "wasm32")]
impl core::ops::Index<usize> for Args<'_> {
type Output = [u8];
fn index(&self, i: usize) -> &[u8] {
match self {
Args::Client(a) => &a[i],
Args::Frame(a) => &a[i],
}
}
}
#[cfg(target_arch = "wasm32")]
impl ArgvView for Args<'_> {
fn len(&self) -> usize {
match self {
Args::Client(a) => a.len(),
Args::Frame(a) => a.len(),
}
}
fn get(&self, i: usize) -> Option<&[u8]> {
match self {
Args::Client(a) => a.get(i).map(Vec::as_slice),
Args::Frame(a) => a.get(i),
}
}
}