use core::result;
use core::fmt::Debug;
use ctx::{TryIntoCtx};
use error;
use endian::Endian;
pub trait Pwrite<Ctx = Endian, E = error::Error, I = usize, TryCtx = (I, Ctx), SliceCtx = (I, I, Ctx) >
where E: Debug,
Ctx: Copy + Default + Debug,
I: Copy + Debug,
TryCtx: Copy + Default + Debug,
SliceCtx: Copy + Default + Debug,
{
fn pwrite_unsafe<N: TryIntoCtx<TryCtx, Error = E>>(&mut self, n: N, offset: I, ctx: Ctx) {
self.pwrite_with(n, offset, ctx).unwrap()
}
fn pwrite<N: TryIntoCtx<TryCtx, Error = E>>(&mut self, n: N, offset: I) -> result::Result<(), E> {
self.pwrite_with(n, offset, Ctx::default())
}
fn pwrite_with<N: TryIntoCtx<TryCtx, Error = E>>(&mut self, n: N, offset: I, ctx: Ctx) -> result::Result<(), E>;
}
impl<Ctx, E> Pwrite<Ctx, E> for [u8]
where
E: Debug,
Ctx: Copy + Default + Debug
{
fn pwrite_with<N: TryIntoCtx<(usize, Ctx), Error = E>>(&mut self, n: N, offset: usize, le: Ctx) -> result::Result<(), E> {
n.try_into_ctx(self, (offset, le))
}
}
impl<T, Ctx, E> Pwrite<Ctx, E> for T where
T: AsMut<[u8]>,
E: Debug,
Ctx: Copy + Debug + Default,
{
fn pwrite_with<N: TryIntoCtx<(usize, Ctx), Error = E>>(&mut self, n: N, offset: usize, ctx: Ctx) -> result::Result<(), E> {
<[u8] as Pwrite<Ctx, E>>::pwrite_with(self.as_mut(), n, offset, ctx)
}
}