Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binary request example #1865

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
use tokio::fs;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::fmt::format::FmtSpan;
use typespec_client_core::{
fs::FileStreamBuilder,
http::{Body, RequestContent},
};
use typespec_client_core::{fs::FileStreamBuilder, http::RequestContent};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -30,8 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.buffer_size(256usize)
.build()
.await?;
let body: Body = file.into();
client::put_binary_data(body.into()).await?;
client::put_binary_data(file.into()).await?;
}

Ok(())
Expand Down
20 changes: 20 additions & 0 deletions sdk/typespec/typespec_client_core/src/http/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,26 @@ impl<T> From<Body> for RequestContent<T> {
}
}

#[cfg(all(feature = "tokio_fs", not(target_arch = "wasm32")))]
impl<T> From<crate::fs::FileStream> for RequestContent<T> {
fn from(body: crate::fs::FileStream) -> Self {
Self {
body: body.into(),
phantom: PhantomData,
}
}
}

#[cfg(all(feature = "tokio_fs", not(target_arch = "wasm32")))]
impl<T> From<&crate::fs::FileStream> for RequestContent<T> {
fn from(body: &crate::fs::FileStream) -> Self {
Self {
body: body.into(),
phantom: PhantomData,
}
}
}

heaths marked this conversation as resolved.
Show resolved Hide resolved
impl<T> TryFrom<Bytes> for RequestContent<T> {
type Error = crate::Error;
fn try_from(body: Bytes) -> Result<Self, Self::Error> {
Expand Down