AWS SDK

AWS SDK

rev. ee444bcd0102e16d8929531917d12f952bedb79d (ignoring whitespace)

Files changed:

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/serde/deserializer.rs

@@ -0,1 +0,176 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! Shape deserialization interfaces for the Smithy data model.
           7  +
           8  +
use crate::Schema;
           9  +
use aws_smithy_types::{BigDecimal, BigInteger, Blob, DateTime, Document};
          10  +
use std::error::Error;
          11  +
          12  +
/// Deserializes Smithy shapes from a serial format.
          13  +
///
          14  +
/// This trait provides a format-agnostic API for deserializing the Smithy data model.
          15  +
/// Implementations read from a serial format and create data objects based on schemas.
          16  +
///
          17  +
/// The deserializer uses a consumer pattern for aggregate types (structures, lists, maps)
          18  +
/// to avoid trait object limitations and enable efficient deserialization without
          19  +
/// intermediate allocations.
          20  +
///
          21  +
/// # Consumer Pattern
          22  +
///
          23  +
/// For aggregate types, the deserializer calls a consumer function for each element/member.
          24  +
/// The consumer receives mutable state and updates it with each deserialized value.
          25  +
/// This pattern:
          26  +
/// - Avoids trait object issues with generic methods
          27  +
/// - Enables zero-cost abstractions (closures can be inlined)
          28  +
/// - Allows caller to control deserialization order and state management
          29  +
/// - Matches the SEP's recommendation for compiled typed languages
          30  +
///
          31  +
/// # Example
          32  +
///
          33  +
/// ```ignore
          34  +
/// // Deserializing a structure
          35  +
/// let mut builder = MyStructBuilder::default();
          36  +
/// deserializer.read_struct(
          37  +
///     &MY_STRUCT_SCHEMA,
          38  +
///     builder,
          39  +
///     |mut builder, member, deser| {
          40  +
///         match member.member_index() {
          41  +
///             0 => builder.field1 = Some(deser.read_string(member)?),
          42  +
///             1 => builder.field2 = Some(deser.read_i32(member)?),
          43  +
///             _ => {}
          44  +
///         }
          45  +
///         Ok(builder)
          46  +
///     },
          47  +
/// )?;
          48  +
/// let my_struct = builder.build();
          49  +
/// ```
          50  +
pub trait ShapeDeserializer {
          51  +
    /// The error type returned by deserialization operations.
          52  +
    type Error: Error;
          53  +
          54  +
    /// Reads a structure from the deserializer.
          55  +
    ///
          56  +
    /// The structure deserialization is driven by a consumer callback that is called
          57  +
    /// for each member. The consumer receives the current state, the member schema,
          58  +
    /// and the deserializer, and returns the updated state.
          59  +
    ///
          60  +
    /// # Arguments
          61  +
    ///
          62  +
    /// * `schema` - The schema of the structure being deserialized
          63  +
    /// * `state` - Initial state (typically a builder)
          64  +
    /// * `consumer` - Callback invoked for each member with (state, member_schema, deserializer)
          65  +
    ///
          66  +
    /// # Returns
          67  +
    ///
          68  +
    /// The final state after processing all members
          69  +
    fn read_struct<T, F>(
          70  +
        &mut self,
          71  +
        schema: &dyn Schema,
          72  +
        state: T,
          73  +
        consumer: F,
          74  +
    ) -> Result<T, Self::Error>
          75  +
    where
          76  +
        F: FnMut(T, &dyn Schema, &mut Self) -> Result<T, Self::Error>;
          77  +
          78  +
    /// Reads a list from the deserializer.
          79  +
    ///
          80  +
    /// The list deserialization is driven by a consumer callback that is called
          81  +
    /// for each element. The consumer receives the current state and the deserializer,
          82  +
    /// and returns the updated state.
          83  +
    ///
          84  +
    /// # Arguments
          85  +
    ///
          86  +
    /// * `schema` - The schema of the list being deserialized
          87  +
    /// * `state` - Initial state (typically a Vec or collection)
          88  +
    /// * `consumer` - Callback invoked for each element with (state, deserializer)
          89  +
    ///
          90  +
    /// # Returns
          91  +
    ///
          92  +
    /// The final state after processing all elements
          93  +
    fn read_list<T, F>(
          94  +
        &mut self,
          95  +
        schema: &dyn Schema,
          96  +
        state: T,
          97  +
        consumer: F,
          98  +
    ) -> Result<T, Self::Error>
          99  +
    where
         100  +
        F: FnMut(T, &mut Self) -> Result<T, Self::Error>;
         101  +
         102  +
    /// Reads a map from the deserializer.
         103  +
    ///
         104  +
    /// The map deserialization is driven by a consumer callback that is called
         105  +
    /// for each entry. The consumer receives the current state, the key, and the
         106  +
    /// deserializer, and returns the updated state.
         107  +
    ///
         108  +
    /// # Arguments
         109  +
    ///
         110  +
    /// * `schema` - The schema of the map being deserialized
         111  +
    /// * `state` - Initial state (typically a HashMap or collection)
         112  +
    /// * `consumer` - Callback invoked for each entry with (state, key, deserializer)
         113  +
    ///
         114  +
    /// # Returns
         115  +
    ///
         116  +
    /// The final state after processing all entries
         117  +
    fn read_map<T, F>(
         118  +
        &mut self,
         119  +
        schema: &dyn Schema,
         120  +
        state: T,
         121  +
        consumer: F,
         122  +
    ) -> Result<T, Self::Error>
         123  +
    where
         124  +
        F: FnMut(T, String, &mut Self) -> Result<T, Self::Error>;
         125  +
         126  +
    /// Reads a boolean value.
         127  +
    fn read_boolean(&mut self, schema: &dyn Schema) -> Result<bool, Self::Error>;
         128  +
         129  +
    /// Reads a byte (i8) value.
         130  +
    fn read_byte(&mut self, schema: &dyn Schema) -> Result<i8, Self::Error>;
         131  +
         132  +
    /// Reads a short (i16) value.
         133  +
    fn read_short(&mut self, schema: &dyn Schema) -> Result<i16, Self::Error>;
         134  +
         135  +
    /// Reads an integer (i32) value.
         136  +
    fn read_integer(&mut self, schema: &dyn Schema) -> Result<i32, Self::Error>;
         137  +
         138  +
    /// Reads a long (i64) value.
         139  +
    fn read_long(&mut self, schema: &dyn Schema) -> Result<i64, Self::Error>;
         140  +
         141  +
    /// Reads a float (f32) value.
         142  +
    fn read_float(&mut self, schema: &dyn Schema) -> Result<f32, Self::Error>;
         143  +
         144  +
    /// Reads a double (f64) value.
         145  +
    fn read_double(&mut self, schema: &dyn Schema) -> Result<f64, Self::Error>;
         146  +
         147  +
    /// Reads a big integer value.
         148  +
    fn read_big_integer(&mut self, schema: &dyn Schema) -> Result<BigInteger, Self::Error>;
         149  +
         150  +
    /// Reads a big decimal value.
         151  +
    fn read_big_decimal(&mut self, schema: &dyn Schema) -> Result<BigDecimal, Self::Error>;
         152  +
         153  +
    /// Reads a string value.
         154  +
    fn read_string(&mut self, schema: &dyn Schema) -> Result<String, Self::Error>;
         155  +
         156  +
    /// Reads a blob (byte array) value.
         157  +
    fn read_blob(&mut self, schema: &dyn Schema) -> Result<Blob, Self::Error>;
         158  +
         159  +
    /// Reads a timestamp value.
         160  +
    fn read_timestamp(&mut self, schema: &dyn Schema) -> Result<DateTime, Self::Error>;
         161  +
         162  +
    /// Reads a document value.
         163  +
    fn read_document(&mut self, schema: &dyn Schema) -> Result<Document, Self::Error>;
         164  +
         165  +
    /// Checks if the current value is null.
         166  +
    ///
         167  +
    /// This is used for sparse collections where null values are significant.
         168  +
    fn is_null(&self) -> bool;
         169  +
         170  +
    /// Returns the size of the current container if known.
         171  +
    ///
         172  +
    /// This is an optimization hint that allows pre-allocating collections
         173  +
    /// with the correct capacity. Returns `None` if the size is unknown or
         174  +
    /// not applicable.
         175  +
    fn container_size(&self) -> Option<usize>;
         176  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/serde/serializer.rs

@@ -0,1 +0,159 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! Shape serialization interfaces for the Smithy data model.
           7  +
           8  +
use crate::Schema;
           9  +
use aws_smithy_types::{BigDecimal, BigInteger, Blob, DateTime, Document};
          10  +
use std::error::Error;
          11  +
          12  +
/// Serializes Smithy shapes to a target format.
          13  +
///
          14  +
/// This trait provides a format-agnostic API for serializing the Smithy data model.
          15  +
/// Implementations serialize each data type to the corresponding encoding in their
          16  +
/// serial format (e.g., Smithy integers and floats to JSON numbers).
          17  +
///
          18  +
/// The serializer accepts a schema along with the value to provide additional
          19  +
/// information about how to serialize the value (e.g., timestamp format, JSON name).
          20  +
///
          21  +
/// # Type Parameter
          22  +
///
          23  +
/// * `Output` - The serialization target type (e.g., `Vec<u8>`, `String`)
          24  +
///
          25  +
/// # Example
          26  +
///
          27  +
/// ```ignore
          28  +
/// let mut serializer = JsonSerializer::new();
          29  +
/// serializer.write_string(&STRING_SCHEMA, "hello")?;
          30  +
/// let json_bytes = serializer.finish()?;
          31  +
/// ```
          32  +
pub trait ShapeSerializer {
          33  +
    /// The serialization target type (e.g., `Vec<u8>`, `String`).
          34  +
    type Output;
          35  +
          36  +
    /// The error type returned by serialization operations.
          37  +
    type Error: Error;
          38  +
          39  +
    /// Finalizes the serialization and returns the serialized output.
          40  +
    ///
          41  +
    /// This method should be called after all values have been written.
          42  +
    /// It may perform final formatting, validation, or resource cleanup.
          43  +
    fn finish(self) -> Result<Self::Output, Self::Error>;
          44  +
          45  +
    /// Writes a structure to the serializer.
          46  +
    ///
          47  +
    /// The structure serialization is driven by a callback that writes each member.
          48  +
    /// This avoids the need for trait objects while maintaining flexibility.
          49  +
    ///
          50  +
    /// # Arguments
          51  +
    ///
          52  +
    /// * `schema` - The schema of the structure being serialized
          53  +
    /// * `write_members` - Callback that writes the structure's members
          54  +
    fn write_struct<F>(&mut self, schema: &dyn Schema, write_members: F) -> Result<(), Self::Error>
          55  +
    where
          56  +
        F: FnOnce(&mut Self) -> Result<(), Self::Error>;
          57  +
          58  +
    /// Writes a list to the serializer.
          59  +
    ///
          60  +
    /// The list serialization is driven by a callback that writes each element.
          61  +
    ///
          62  +
    /// # Arguments
          63  +
    ///
          64  +
    /// * `schema` - The schema of the list being serialized
          65  +
    /// * `write_elements` - Callback that writes the list elements
          66  +
    fn write_list<F>(&mut self, schema: &dyn Schema, write_elements: F) -> Result<(), Self::Error>
          67  +
    where
          68  +
        F: FnOnce(&mut Self) -> Result<(), Self::Error>;
          69  +
          70  +
    /// Writes a map to the serializer.
          71  +
    ///
          72  +
    /// The map serialization is driven by a callback that writes each entry.
          73  +
    ///
          74  +
    /// # Arguments
          75  +
    ///
          76  +
    /// * `schema` - The schema of the map being serialized
          77  +
    /// * `write_entries` - Callback that writes the map entries
          78  +
    fn write_map<F>(&mut self, schema: &dyn Schema, write_entries: F) -> Result<(), Self::Error>
          79  +
    where
          80  +
        F: FnOnce(&mut Self) -> Result<(), Self::Error>;
          81  +
          82  +
    /// Writes a boolean value.
          83  +
    fn write_boolean(&mut self, schema: &dyn Schema, value: bool) -> Result<(), Self::Error>;
          84  +
          85  +
    /// Writes a byte (i8) value.
          86  +
    fn write_byte(&mut self, schema: &dyn Schema, value: i8) -> Result<(), Self::Error>;
          87  +
          88  +
    /// Writes a short (i16) value.
          89  +
    fn write_short(&mut self, schema: &dyn Schema, value: i16) -> Result<(), Self::Error>;
          90  +
          91  +
    /// Writes an integer (i32) value.
          92  +
    fn write_integer(&mut self, schema: &dyn Schema, value: i32) -> Result<(), Self::Error>;
          93  +
          94  +
    /// Writes a long (i64) value.
          95  +
    fn write_long(&mut self, schema: &dyn Schema, value: i64) -> Result<(), Self::Error>;
          96  +
          97  +
    /// Writes a float (f32) value.
          98  +
    fn write_float(&mut self, schema: &dyn Schema, value: f32) -> Result<(), Self::Error>;
          99  +
         100  +
    /// Writes a double (f64) value.
         101  +
    fn write_double(&mut self, schema: &dyn Schema, value: f64) -> Result<(), Self::Error>;
         102  +
         103  +
    /// Writes a big integer value.
         104  +
    fn write_big_integer(
         105  +
        &mut self,
         106  +
        schema: &dyn Schema,
         107  +
        value: &BigInteger,
         108  +
    ) -> Result<(), Self::Error>;
         109  +
         110  +
    /// Writes a big decimal value.
         111  +
    fn write_big_decimal(
         112  +
        &mut self,
         113  +
        schema: &dyn Schema,
         114  +
        value: &BigDecimal,
         115  +
    ) -> Result<(), Self::Error>;
         116  +
         117  +
    /// Writes a string value.
         118  +
    fn write_string(&mut self, schema: &dyn Schema, value: &str) -> Result<(), Self::Error>;
         119  +
         120  +
    /// Writes a blob (byte array) value.
         121  +
    fn write_blob(&mut self, schema: &dyn Schema, value: &Blob) -> Result<(), Self::Error>;
         122  +
         123  +
    /// Writes a timestamp value.
         124  +
    fn write_timestamp(&mut self, schema: &dyn Schema, value: &DateTime)
         125  +
        -> Result<(), Self::Error>;
         126  +
         127  +
    /// Writes a document value.
         128  +
    fn write_document(&mut self, schema: &dyn Schema, value: &Document) -> Result<(), Self::Error>;
         129  +
         130  +
    /// Writes a null value (for sparse collections).
         131  +
    fn write_null(&mut self, schema: &dyn Schema) -> Result<(), Self::Error>;
         132  +
}
         133  +
         134  +
/// Trait for structures that can be serialized.
         135  +
///
         136  +
/// This trait is implemented by generated structure types to enable
         137  +
/// schema-based serialization.
         138  +
///
         139  +
/// # Example
         140  +
///
         141  +
/// ```ignore
         142  +
/// impl SerializableStruct for MyStruct {
         143  +
///     fn serialize<S: ShapeSerializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
         144  +
///         serializer.write_struct(&Self::SCHEMA, |ser| {
         145  +
///             ser.write_string(&FIELD1_SCHEMA, &self.field1)?;
         146  +
///             ser.write_integer(&FIELD2_SCHEMA, self.field2)?;
         147  +
///             Ok(())
         148  +
///         })
         149  +
///     }
         150  +
/// }
         151  +
/// ```
         152  +
pub trait SerializableStruct {
         153  +
    /// Serializes this structure using the provided serializer.
         154  +
    ///
         155  +
    /// # Arguments
         156  +
    ///
         157  +
    /// * `serializer` - The serializer to write to
         158  +
    fn serialize<S: ShapeSerializer>(&self, serializer: &mut S) -> Result<(), S::Error>;
         159  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/shape_id.rs

@@ -0,1 +0,195 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
use std::borrow::Cow;
           7  +
           8  +
/// A Smithy Shape ID.
           9  +
///
          10  +
/// Shape IDs uniquely identify shapes in a Smithy model.
          11  +
/// - `fqn` is `"smithy.example#Foo"`
          12  +
/// - `namespace` is `"smithy.example"`
          13  +
/// - `shape_name` is `"Foo"`
          14  +
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
          15  +
pub struct ShapeId {
          16  +
    fqn: Cow<'static, str>,
          17  +
    namespace: Cow<'static, str>,
          18  +
    shape_name: Cow<'static, str>,
          19  +
}
          20  +
          21  +
impl ShapeId {
          22  +
    /// Creates a ShapeId from a static string at compile time.
          23  +
    ///
          24  +
    /// This is used for const initialization of prelude schemas.
          25  +
    pub const fn from_static(
          26  +
        fqn: &'static str,
          27  +
        namespace: &'static str,
          28  +
        shape_name: &'static str,
          29  +
    ) -> Self {
          30  +
        Self {
          31  +
            fqn: Cow::Borrowed(fqn),
          32  +
            namespace: Cow::Borrowed(namespace),
          33  +
            shape_name: Cow::Borrowed(shape_name),
          34  +
        }
          35  +
    }
          36  +
          37  +
    /// Creates a new ShapeId from a namespace and a shape_name.
          38  +
    ///
          39  +
    /// # Examples
          40  +
    /// ```
          41  +
    /// use aws_smithy_schema::ShapeId;
          42  +
    ///
          43  +
    /// let shape_id = ShapeId::new("smithy.api#String");
          44  +
    /// ```
          45  +
    pub fn new_from_parts(
          46  +
        namespace: impl Into<Cow<'static, str>>,
          47  +
        shape_name: impl Into<Cow<'static, str>>,
          48  +
    ) -> Self {
          49  +
        let namespace = namespace.into();
          50  +
        let shape_name = shape_name.into();
          51  +
        Self {
          52  +
            fqn: format!("{}#{}", namespace.as_ref(), shape_name.as_ref()).into(),
          53  +
            namespace,
          54  +
            shape_name,
          55  +
        }
          56  +
    }
          57  +
          58  +
    /// Creates a new ShapeId from a fully qualified name.
          59  +
    pub fn new_from_fqn(fqn: impl Into<Cow<'static, str>>) -> Option<Self> {
          60  +
        let fqn = fqn.into();
          61  +
        let (namespace, shape_name) = fqn.as_ref().split_once('#').map(|(ns, rest)| {
          62  +
            (
          63  +
                ns.to_string(),
          64  +
                rest.split_once('$')
          65  +
                    .map_or(rest, |(name, _)| name)
          66  +
                    .to_string(),
          67  +
            )
          68  +
        })?;
          69  +
        Some(Self {
          70  +
            fqn,
          71  +
            namespace: namespace.into(),
          72  +
            shape_name: shape_name.into(),
          73  +
        })
          74  +
    }
          75  +
          76  +
    /// Creates a new ShapeId from a fully qualified name.
          77  +
    pub fn new(fqn: impl Into<Cow<'static, str>>) -> Self {
          78  +
        Self::new_from_fqn(fqn).expect("invalid shape ID")
          79  +
    }
          80  +
          81  +
    /// Returns the string representation of this ShapeId.
          82  +
    pub fn as_str(&self) -> &str {
          83  +
        self.fqn.as_ref()
          84  +
    }
          85  +
          86  +
    /// Returns the namespace portion of the ShapeId.
          87  +
    ///
          88  +
    /// # Examples
          89  +
    /// ```
          90  +
    /// use aws_smithy_schema::ShapeId;
          91  +
    ///
          92  +
    /// let shape_id = ShapeId::new("smithy.api#String");
          93  +
    /// assert_eq!(shape_id.namespace(), "smithy.api");
          94  +
    /// ```
          95  +
    pub fn namespace(&self) -> &str {
          96  +
        self.namespace.as_ref()
          97  +
    }
          98  +
          99  +
    /// Returns the shape name portion of the ShapeId.
         100  +
    ///
         101  +
    /// # Examples
         102  +
    /// ```
         103  +
    /// use aws_smithy_schema::ShapeId;
         104  +
    ///
         105  +
    /// let shape_id = ShapeId::new("smithy.api#String");
         106  +
    /// assert_eq!(shape_id.shape_name(), "String");
         107  +
    /// ```
         108  +
    pub fn shape_name(&self) -> &str {
         109  +
        self.shape_name.as_ref()
         110  +
    }
         111  +
         112  +
    /// Returns the member name if this is a member shape ID.
         113  +
    ///
         114  +
    /// # Examples
         115  +
    /// ```
         116  +
    /// use aws_smithy_schema::ShapeId;
         117  +
    ///
         118  +
    /// let shape_id = ShapeId::new("com.example#MyStruct$member");
         119  +
    /// assert_eq!(shape_id.member_name(), Some("member"));
         120  +
    /// ```
         121  +
    pub fn member_name(&self) -> Option<&str> {
         122  +
        self.fqn
         123  +
            .split_once('#')
         124  +
            .and_then(|(_, rest)| rest.split_once('$').map(|(_, member)| member))
         125  +
    }
         126  +
}
         127  +
         128  +
impl From<String> for ShapeId {
         129  +
    fn from(value: String) -> Self {
         130  +
        Self::new(value)
         131  +
    }
         132  +
}
         133  +
         134  +
impl From<&str> for ShapeId {
         135  +
    fn from(value: &str) -> Self {
         136  +
        Self::new(value.to_string())
         137  +
    }
         138  +
}
         139  +
         140  +
#[cfg(test)]
         141  +
mod tests {
         142  +
    use super::*;
         143  +
         144  +
    #[test]
         145  +
    fn test_new() {
         146  +
        let shape_id = ShapeId::new("smithy.api#String");
         147  +
        assert_eq!(shape_id.as_str(), "smithy.api#String");
         148  +
    }
         149  +
         150  +
    #[test]
         151  +
    fn test_namespace() {
         152  +
        assert_eq!(ShapeId::new("smithy.api#String").namespace(), "smithy.api");
         153  +
        assert_eq!(
         154  +
            ShapeId::new("com.example#MyStruct$member").namespace(),
         155  +
            "com.example"
         156  +
        );
         157  +
    }
         158  +
         159  +
    #[test]
         160  +
    fn test_shape_name() {
         161  +
        assert_eq!(ShapeId::new("smithy.api#String").shape_name(), "String");
         162  +
        assert_eq!(
         163  +
            ShapeId::new("com.example#MyStruct$member").shape_name(),
         164  +
            "MyStruct"
         165  +
        );
         166  +
    }
         167  +
         168  +
    #[test]
         169  +
    fn test_member_name() {
         170  +
        assert_eq!(
         171  +
            ShapeId::new("com.example#MyStruct$member").member_name(),
         172  +
            Some("member")
         173  +
        );
         174  +
        assert_eq!(ShapeId::new("smithy.api#String").member_name(), None);
         175  +
    }
         176  +
         177  +
    #[test]
         178  +
    fn test_from_string() {
         179  +
        let shape_id: ShapeId = String::from("smithy.api#String").into();
         180  +
        assert_eq!(shape_id.as_str(), "smithy.api#String");
         181  +
    }
         182  +
         183  +
    #[test]
         184  +
    fn test_from_str() {
         185  +
        let shape_id: ShapeId = "smithy.api#String".into();
         186  +
        assert_eq!(shape_id.as_str(), "smithy.api#String");
         187  +
    }
         188  +
         189  +
    #[test]
         190  +
    fn test_clone_and_equality() {
         191  +
        let shape_id1 = ShapeId::new("smithy.api#String");
         192  +
        let shape_id2 = shape_id1.clone();
         193  +
        assert_eq!(shape_id1, shape_id2);
         194  +
    }
         195  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/shape_type.rs

@@ -0,1 +0,89 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
/// Enumeration of Smithy shape types.
           7  +
///
           8  +
/// This represents the core shape types from the Smithy specification,
           9  +
/// including simple types, aggregate types, and the special member type.
          10  +
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
          11  +
#[non_exhaustive]
          12  +
pub enum ShapeType {
          13  +
    // Simple types
          14  +
    /// Boolean type
          15  +
    Boolean,
          16  +
    /// 8-bit signed integer
          17  +
    Byte,
          18  +
    /// 16-bit signed integer
          19  +
    Short,
          20  +
    /// 32-bit signed integer
          21  +
    Integer,
          22  +
    /// 64-bit signed integer
          23  +
    Long,
          24  +
    /// 32-bit floating point
          25  +
    Float,
          26  +
    /// 64-bit floating point
          27  +
    Double,
          28  +
    /// Arbitrary precision integer
          29  +
    BigInteger,
          30  +
    /// Arbitrary precision decimal
          31  +
    BigDecimal,
          32  +
    /// UTF-8 string
          33  +
    String,
          34  +
    /// Binary data
          35  +
    Blob,
          36  +
    /// Timestamp
          37  +
    Timestamp,
          38  +
    /// Document type
          39  +
    Document,
          40  +
          41  +
    // Aggregate types
          42  +
    /// List type
          43  +
    List,
          44  +
    /// Map type
          45  +
    Map,
          46  +
    /// Structure type
          47  +
    Structure,
          48  +
    /// Union type
          49  +
    Union,
          50  +
          51  +
    // Member
          52  +
    /// Member shape
          53  +
    Member,
          54  +
}
          55  +
          56  +
impl ShapeType {
          57  +
    /// Returns true if this is a simple type.
          58  +
    #[inline]
          59  +
    pub fn is_simple(&self) -> bool {
          60  +
        matches!(
          61  +
            self,
          62  +
            Self::Boolean
          63  +
                | Self::Byte
          64  +
                | Self::Short
          65  +
                | Self::Integer
          66  +
                | Self::Long
          67  +
                | Self::Float
          68  +
                | Self::Double
          69  +
                | Self::BigInteger
          70  +
                | Self::BigDecimal
          71  +
                | Self::String
          72  +
                | Self::Blob
          73  +
                | Self::Timestamp
          74  +
                | Self::Document
          75  +
        )
          76  +
    }
          77  +
          78  +
    /// Returns true if this is an aggregate type.
          79  +
    #[inline]
          80  +
    pub fn is_aggregate(&self) -> bool {
          81  +
        matches!(self, Self::List | Self::Map | Self::Structure | Self::Union)
          82  +
    }
          83  +
          84  +
    /// Returns true if this is a member type.
          85  +
    #[inline]
          86  +
    pub fn is_member(&self) -> bool {
          87  +
        matches!(self, Self::Member)
          88  +
    }
          89  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/trait_map.rs

@@ -0,1 +0,69 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
use crate::{ShapeId, Trait};
           7  +
use std::collections::HashMap;
           8  +
           9  +
/// A map of traits keyed by their Shape ID.
          10  +
///
          11  +
/// This provides efficient lookup of traits during serialization and deserialization.
          12  +
#[derive(Debug)]
          13  +
pub struct TraitMap {
          14  +
    traits: HashMap<ShapeId, Box<dyn Trait>>,
          15  +
}
          16  +
          17  +
impl Default for TraitMap {
          18  +
    fn default() -> Self {
          19  +
        Self::new()
          20  +
    }
          21  +
}
          22  +
          23  +
impl TraitMap {
          24  +
    // TODO(schema) Is there a reasonable with_capacity size for this?
          25  +
    /// Creates a new empty TraitMap.
          26  +
    pub fn new() -> Self {
          27  +
        Self {
          28  +
            traits: HashMap::new(),
          29  +
        }
          30  +
    }
          31  +
          32  +
    /// Creates a TraitMap with zero allocated space for Prelude Schemas.
          33  +
    pub(crate) fn empty() -> Self {
          34  +
        Self {
          35  +
            traits: HashMap::with_capacity(0),
          36  +
        }
          37  +
    }
          38  +
          39  +
    /// Inserts a trait into the map.
          40  +
    pub fn insert(&mut self, trait_obj: Box<dyn Trait>) {
          41  +
        let id = trait_obj.trait_id().clone();
          42  +
        self.traits.insert(id, trait_obj);
          43  +
    }
          44  +
          45  +
    /// Gets a trait by its Shape ID.
          46  +
    pub fn get(&self, id: &ShapeId) -> Option<&dyn Trait> {
          47  +
        self.traits.get(id).map(|t| t.as_ref())
          48  +
    }
          49  +
          50  +
    /// Returns true if the map contains a trait with the given Shape ID.
          51  +
    pub fn contains(&self, id: &ShapeId) -> bool {
          52  +
        self.traits.contains_key(id)
          53  +
    }
          54  +
          55  +
    /// Returns an iterator over all traits.
          56  +
    pub fn iter(&self) -> impl Iterator<Item = (&ShapeId, &dyn Trait)> {
          57  +
        self.traits.iter().map(|(s, t)| (s, t.as_ref()))
          58  +
    }
          59  +
          60  +
    /// Returns the number of traits in the map.
          61  +
    pub fn len(&self) -> usize {
          62  +
        self.traits.len()
          63  +
    }
          64  +
          65  +
    /// Returns true if the map is empty.
          66  +
    pub fn is_empty(&self) -> bool {
          67  +
        self.traits.is_empty()
          68  +
    }
          69  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/trait_type.rs

@@ -0,1 +0,20 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
use crate::ShapeId;
           7  +
use std::any::Any;
           8  +
use std::fmt;
           9  +
          10  +
/// Trait representing a Smithy trait at runtime.
          11  +
///
          12  +
/// Traits provide additional metadata about shapes that affect serialization,
          13  +
/// validation, and other behaviors.
          14  +
pub trait Trait: Any + Send + Sync + fmt::Debug {
          15  +
    /// Returns the Shape ID of this trait.
          16  +
    fn trait_id(&self) -> &ShapeId;
          17  +
          18  +
    /// Returns this trait as `&dyn Any` for downcasting.
          19  +
    fn as_any(&self) -> &dyn Any;
          20  +
}