use std::future::IntoFuture;
use bytes::Bytes;
use serde::de::DeserializeOwned;
use crate::{error::OsuError, model::ContainedUsers, request::Request, OsuResult};
#[allow(
private_bounds,
reason = "users should not implement this trait anyway"
)]
pub trait OsuFutureData: IntoFuture<Output = OsuResult<Self::OsuOutput>> {
type FromBytes: FromBytes;
type OsuOutput: ContainedUsers;
type FromUserData;
type PostProcessData;
}
pub(crate) trait FromBytes: Sized {
fn from_bytes(bytes: Bytes) -> OsuResult<Self>;
}
#[doc(hidden)]
pub struct BytesWrap(pub(crate) Bytes);
impl FromBytes for BytesWrap {
fn from_bytes(bytes: Bytes) -> OsuResult<Self> {
Ok(Self(bytes))
}
}
impl<T: DeserializeOwned> FromBytes for T {
fn from_bytes(bytes: Bytes) -> OsuResult<Self> {
serde_json::from_slice(&bytes).map_err(|source| OsuError::Parsing { bytes, source })
}
}
pub(crate) trait IntoPostProcessData<D> {
fn into_data(self) -> (Request, D);
}
impl IntoPostProcessData<()> for Request {
fn into_data(self) -> (Request, ()) {
(self, ())
}
}
impl<D> IntoPostProcessData<D> for (Request, D) {
fn into_data(self) -> (Request, D) {
self
}
}