Commit e1ed3585 authored by AWS SDK Rust Bot's avatar AWS SDK Rust Bot
Browse files

[smithy-rs] Rollup of 2 commits



Includes commits:
  f9c05262 Avoid exposing `aws_smithy_http::event_stream::receiver::Receiver` in SDK's public API  (#3114)
  a42c818b Allow SDK examples to rename from `rust_dev_preview` to `rust` (#3115)

Co-authored-by: default avatarJohn DiSanti <jdisanti@amazon.com>
Co-authored-by: default avatarysaito1001 <awsaito@amazon.com>
parent 4d454abf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,4 +17,4 @@ pub type BoxError = Box<dyn StdError + Send + Sync + 'static>;
pub use sender::{EventStreamSender, MessageStreamAdapter, MessageStreamError};

#[doc(inline)]
pub use receiver::{RawMessage, Receiver, ReceiverError};
pub use receiver::{Receiver, ReceiverError};
+3 −19
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use aws_smithy_eventstream::frame::{
};
use aws_smithy_runtime_api::client::result::{ConnectorError, SdkError};
use aws_smithy_types::body::SdkBody;
use aws_smithy_types::event_stream::Message;
use aws_smithy_types::event_stream::{Message, RawMessage};
use bytes::Buf;
use bytes::Bytes;
use bytes_utils::SegmentedBuf;
@@ -87,23 +87,6 @@ impl RecvBuf {
    }
}

/// Raw message from a [`Receiver`] when a [`SdkError::ResponseError`] is returned.
#[derive(Debug)]
#[non_exhaustive]
pub enum RawMessage {
    /// Message was decoded into a valid frame, but failed to unmarshall into a modeled type.
    Decoded(Message),
    /// Message failed to be decoded into a valid frame. The raw bytes may not be available in the
    /// case where decoding consumed the buffer.
    Invalid(Option<Bytes>),
}

impl RawMessage {
    pub(crate) fn invalid(buf: &mut SegmentedBuf<Bytes>) -> Self {
        Self::Invalid(Some(buf.copy_to_bytes(buf.remaining())))
    }
}

#[derive(Debug)]
enum ReceiverErrorKind {
    /// The stream ended before a complete message frame was received.
@@ -210,11 +193,12 @@ impl<T, E> Receiver<T, E> {
        }
        if self.buffer.has_data() {
            trace!(remaining_data = ?self.buffer, "data left over in the event stream response stream");
            let buf = self.buffer.buffered();
            return Err(SdkError::response_error(
                ReceiverError {
                    kind: ReceiverErrorKind::UnexpectedEndOfStream,
                },
                RawMessage::invalid(self.buffer.buffered()),
                RawMessage::invalid(Some(buf.copy_to_bytes(buf.remaining()))),
            ));
        }
        Ok(None)
+18 −0
Original line number Diff line number Diff line
@@ -183,3 +183,21 @@ impl Message {
        &self.payload
    }
}

/// Raw message from an event stream receiver when a response error is encountered.
#[derive(Debug)]
#[non_exhaustive]
pub enum RawMessage {
    /// Message was decoded into a valid frame, but failed to unmarshall into a modeled type.
    Decoded(Message),
    /// Message failed to be decoded into a valid frame. The raw bytes may not be available in the
    /// case where decoding consumed the buffer.
    Invalid(Option<Bytes>),
}

impl RawMessage {
    /// Creates a `RawMessage` for failure to decode a message into a valid frame.
    pub fn invalid(bytes: Option<Bytes>) -> Self {
        Self::Invalid(bytes)
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ impl super::Client {
    ///   - [`accept(impl Into<String>)`](crate::operation::invoke_model_with_response_stream::builders::InvokeModelWithResponseStreamFluentBuilder::accept) / [`set_accept(Option<String>)`](crate::operation::invoke_model_with_response_stream::builders::InvokeModelWithResponseStreamFluentBuilder::set_accept):<br>required: **false**<br><p>The desired MIME type of the inference body in the response. The default value is <code>application/json</code>.</p><br>
    ///   - [`model_id(impl Into<String>)`](crate::operation::invoke_model_with_response_stream::builders::InvokeModelWithResponseStreamFluentBuilder::model_id) / [`set_model_id(Option<String>)`](crate::operation::invoke_model_with_response_stream::builders::InvokeModelWithResponseStreamFluentBuilder::set_model_id):<br>required: **true**<br><p>Id of the model to invoke using the streaming request.</p><br>
    /// - On success, responds with [`InvokeModelWithResponseStreamOutput`](crate::operation::invoke_model_with_response_stream::InvokeModelWithResponseStreamOutput) with field(s):
    ///   - [`body(Receiver<ResponseStream, ResponseStreamError>)`](crate::operation::invoke_model_with_response_stream::InvokeModelWithResponseStreamOutput::body): <p>Inference response from the model in the format specified by Content-Type. To see the format and content of this field for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>.</p>
    ///   - [`body(EventReceiver<ResponseStream, ResponseStreamError>)`](crate::operation::invoke_model_with_response_stream::InvokeModelWithResponseStreamOutput::body): <p>Inference response from the model in the format specified by Content-Type. To see the format and content of this field for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>.</p>
    ///   - [`content_type(String)`](crate::operation::invoke_model_with_response_stream::InvokeModelWithResponseStreamOutput::content_type): <p>The MIME type of the inference result.</p>
    /// - On failure, responds with [`SdkError<InvokeModelWithResponseStreamError>`](crate::operation::invoke_model_with_response_stream::InvokeModelWithResponseStreamError)
    pub fn invoke_model_with_response_stream(
+29 −0
Original line number Diff line number Diff line
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
/*
 *  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *  SPDX-License-Identifier: Apache-2.0
 */

use aws_smithy_http::event_stream::Receiver;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::event_stream::RawMessage;

#[derive(Debug)]
/// Receives unmarshalled events at a time out of an Event Stream.
pub struct EventReceiver<T, E> {
    inner: Receiver<T, E>,
}

impl<T, E> EventReceiver<T, E> {
    pub(crate) fn new(inner: Receiver<T, E>) -> Self {
        Self { inner }
    }

    /// Asynchronously tries to receive an event from the stream. If the stream has ended, it
    /// returns an `Ok(None)`. If there is a transport layer error, it will return
    /// `Err(SdkError::DispatchFailure)`. Service-modeled errors will be a part of the returned
    /// messages.
    pub async fn recv(&mut self) -> Result<Option<T>, SdkError<E, RawMessage>> {
        self.inner.recv().await
    }
}
Loading