From 622f529996cb29cb296761d79bed99921a4d3e80 Mon Sep 17 00:00:00 2001 From: aumetra Date: Sun, 1 Dec 2024 20:12:54 +0100 Subject: [PATCH] get rid of pin-project --- Cargo.lock | 2 +- crates/kitsune-http-client/Cargo.toml | 2 +- crates/kitsune-http-client/src/body.rs | 58 ++++++++++++++++++-------- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1151a050d..21812631d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3637,7 +3637,7 @@ dependencies = [ "hyper-util", "kitsune-core", "kitsune-type", - "pin-project", + "pin-project-lite", "serde", "simdutf8", "sonic-rs", diff --git a/crates/kitsune-http-client/Cargo.toml b/crates/kitsune-http-client/Cargo.toml index eb214e947..f4134c457 100644 --- a/crates/kitsune-http-client/Cargo.toml +++ b/crates/kitsune-http-client/Cargo.toml @@ -31,7 +31,7 @@ hyper-rustls = { version = "0.27.3", default-features = false, features = [ ] } kitsune-core.workspace = true kitsune-type.workspace = true -pin-project = "1.1.7" +pin-project-lite.workspace = true serde.workspace = true simdutf8.workspace = true sonic-rs.workspace = true diff --git a/crates/kitsune-http-client/src/body.rs b/crates/kitsune-http-client/src/body.rs index 62f7c2cf9..9ed508156 100644 --- a/crates/kitsune-http-client/src/body.rs +++ b/crates/kitsune-http-client/src/body.rs @@ -1,8 +1,7 @@ use bytes::Bytes; -use futures_util::{stream::BoxStream, StreamExt, TryStream, TryStreamExt}; +use futures_util::{StreamExt, TryStream, TryStreamExt}; use http_body::Frame; use http_body_util::StreamBody; -use pin_project::pin_project; use std::{ borrow::Cow, fmt::{self, Debug}, @@ -11,19 +10,40 @@ use std::{ }; use tower::BoxError; -/// Body on a budget -#[derive(Default)] -#[pin_project(project = BodyProj)] -pub enum Body { - /// Empty body - #[default] - Empty, +mod body_def { + #![allow(missing_docs)] + + use super::{BoxError, Bytes, Frame, StreamBody}; + use futures_util::stream::BoxStream; + use pin_project_lite::pin_project; + + pin_project! { + #[project = BodyProj] + // Body on a budget + pub enum Body { + // Empty body + Empty, + + // Body consisting of a single chunk + Full { data: Option }, + + // Body backed by a `StreamBody` + Stream { + #[pin] + stream: StreamBody, BoxError>>> + }, + } + } +} - /// Body consisting of a single chunk - Full(Option), +pub use self::body_def::Body; +use self::body_def::BodyProj; - /// Body backed by a `StreamBody` - Stream(#[pin] StreamBody, BoxError>>>), +impl Default for Body { + #[inline] + fn default() -> Self { + Self::empty() + } } impl Body { @@ -40,7 +60,9 @@ impl Body { where D: Into, { - Self::Full(Some(data.into())) + Self::Full { + data: Some(data.into()), + } } /// Stream body @@ -56,7 +78,9 @@ impl Body { .map_err(Into::into) .boxed(); - Self::Stream(StreamBody::new(stream)) + Self::Stream { + stream: StreamBody::new(stream), + } } } @@ -107,8 +131,8 @@ impl http_body::Body for Body { ) -> Poll, Self::Error>>> { match self.project() { BodyProj::Empty => Poll::Ready(None), - BodyProj::Full(data) => Poll::Ready(data.take().map(|data| Ok(Frame::data(data)))), - BodyProj::Stream(stream) => stream.poll_frame(cx), + BodyProj::Full { data } => Poll::Ready(data.take().map(|data| Ok(Frame::data(data)))), + BodyProj::Stream { stream } => stream.poll_frame(cx), } } }