update ByteStream type to include Pin (#36)
This commit is contained in:
parent
ea80069ef3
commit
b7bbb5cdff
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
//! Support code for generated clients.
|
//! Support code for generated clients.
|
||||||
|
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::{
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
pin::Pin,
|
||||||
|
};
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_core::Stream;
|
use futures_core::Stream;
|
||||||
|
@ -10,7 +13,8 @@ use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
/// Represents a streaming, untyped byte stream for both success and error
|
/// Represents a streaming, untyped byte stream for both success and error
|
||||||
/// responses.
|
/// responses.
|
||||||
pub type ByteStream = Box<dyn Stream<Item = reqwest::Result<Bytes>>>;
|
pub type ByteStream =
|
||||||
|
Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send>>;
|
||||||
|
|
||||||
/// Success value returned by generated client methods.
|
/// Success value returned by generated client methods.
|
||||||
pub struct ResponseValue<T> {
|
pub struct ResponseValue<T> {
|
||||||
|
@ -46,7 +50,7 @@ impl ResponseValue<ByteStream> {
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
let headers = response.headers().clone();
|
let headers = response.headers().clone();
|
||||||
Self {
|
Self {
|
||||||
inner: Box::new(response.bytes_stream()),
|
inner: Box::pin(response.bytes_stream()),
|
||||||
status,
|
status,
|
||||||
headers,
|
headers,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,23 @@
|
||||||
// Copyright 2021 Oxide Computer Company
|
// Copyright 2021 Oxide Computer Company
|
||||||
|
|
||||||
progenitor::generate_api!("../sample_openapi/nexus.json");
|
progenitor::generate_api!("../sample_openapi/nexus.json");
|
||||||
|
|
||||||
|
pub async fn iteration_example() {
|
||||||
|
let client = Client::new("xxx");
|
||||||
|
|
||||||
|
let bod = types::LoginParams {
|
||||||
|
username: "ahl".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut stream = client.spoof_login(&bod).await.unwrap();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
|
match stream.try_next().await {
|
||||||
|
Ok(Some(bytes)) => println!("bytes: {:?}", bytes),
|
||||||
|
Ok(None) => break,
|
||||||
|
Err(e) => panic!("{}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue