Unverified Commit 375e0b2b authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Hide external buffer types used by `primitive::Encoder` in aws-smithy-types (#1209)

* Fix exit status in `api-linter`

* Run `api-linter` against `aws-smithy-types` in CI

* Hide external buffer types used by `primitive::Encoder`

* Unpin nightly in CI

* Make `Encoder` a struct and split out an inner enum

* Update changelog
parent 458b413b
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ jobs:
        - name: Clippy
          run: cargo clippy --all-features
        - name: Unused Dependencies
          run: cargo +nightly-2022-02-08 udeps
          run: cargo +nightly udeps
        - name: Additional per-crate checks
          run: ../tools/additional-per-crate-checks.sh ./sdk/ ../tools/ci-cdk/
    env:
@@ -87,7 +87,7 @@ jobs:
        default: true
    - uses: actions-rs/toolchain@v1
      with:
        toolchain: nightly-2022-02-08
        toolchain: nightly
        default: false
    - name: Cache cargo bin
      uses: actions/cache@v2
@@ -97,11 +97,15 @@ jobs:
    - name: Install additional cargo binaries
      run: |
        if [[ ! -f ~/.cargo/bin/cargo-udeps ]]; then
          cargo +nightly-2022-02-08 install cargo-udeps
          cargo +nightly install cargo-udeps
        fi
        if [[ ! -f ~/.cargo/bin/cargo-hack ]]; then
          cargo install cargo-hack
        fi
        # Install the api-linter tool for finding external types in public APIs
        pushd tools/api-linter &>/dev/null
        cargo install --debug --path .
        popd &>/dev/null
    - name: Generate a name for the SDK
      id: gen-name
      run: echo "name=${GITHUB_REF##*/}" >> $GITHUB_ENV
+6 −0
Original line number Diff line number Diff line
@@ -10,3 +10,9 @@
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false }
# author = "rcoh"

[[smithy-rs]]
message = "`aws_smithy_types::primitive::Encoder` is now a struct rather than an enum, but its usage remains the same."
references = ["smithy-rs#1209"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"
+15 −0
Original line number Diff line number Diff line
#!/bin/bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.
#

# This script contains additional CI checks to run for this specific package

set -e

echo "### Checking for duplicate dependency versions in the normal dependency graph with all features enabled"
cargo tree -d --edges normal --all-features

echo "### Running api-linter"
cargo +nightly api-linter --all-features
+30 −35
Original line number Diff line number Diff line
@@ -94,41 +94,26 @@ impl Parse for f64 {
    }
}

/// Primitive Type Encoder
///
/// Encodes primitive types in Smithy's specified format. For floating-point numbers,
/// Smithy requires that NaN and Infinity values be specially encoded.
///
/// This type implements `From<T>` for all Smithy primitive types.
#[non_exhaustive]
pub enum Encoder {
enum Inner {
    /// Boolean
    #[non_exhaustive]
    Bool(bool),
    /// 8-bit signed integer
    #[non_exhaustive]
    I8(i8, itoa::Buffer),
    /// 16-bit signed integer
    #[non_exhaustive]
    I16(i16, itoa::Buffer),
    /// 32-bit signed integer
    #[non_exhaustive]
    I32(i32, itoa::Buffer),
    /// 64-bit signed integer
    #[non_exhaustive]
    I64(i64, itoa::Buffer),
    /// 64-bit unsigned integer
    #[non_exhaustive]
    U64(u64, itoa::Buffer),
    #[non_exhaustive]
    /// 32-bit IEEE 754 single-precision floating-point number
    F32(f32, ryu::Buffer),
    /// 64-bit IEEE 754 double-precision floating-point number
    #[non_exhaustive]
    F64(f64, ryu::Buffer),
}

impl Debug for Encoder {
impl Debug for Inner {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Bool(v) => write!(f, "Bool({})", v),
@@ -143,18 +128,28 @@ impl Debug for Encoder {
    }
}

/// Primitive Type Encoder
///
/// Encodes primitive types in Smithy's specified format. For floating-point numbers,
/// Smithy requires that NaN and Infinity values be specially encoded.
///
/// This type implements `From<T>` for all Smithy primitive types.
#[non_exhaustive]
#[derive(Debug)]
pub struct Encoder(Inner);

impl Encoder {
    /// Encodes a Smithy primitive as a string.
    pub fn encode(&mut self) -> &str {
        match self {
            Encoder::Bool(true) => "true",
            Encoder::Bool(false) => "false",
            Encoder::I8(v, buf) => buf.format(*v),
            Encoder::I16(v, buf) => buf.format(*v),
            Encoder::I32(v, buf) => buf.format(*v),
            Encoder::I64(v, buf) => buf.format(*v),
            Encoder::U64(v, buf) => buf.format(*v),
            Encoder::F32(v, buf) => {
        match &mut self.0 {
            Inner::Bool(true) => "true",
            Inner::Bool(false) => "false",
            Inner::I8(v, buf) => buf.format(*v),
            Inner::I16(v, buf) => buf.format(*v),
            Inner::I32(v, buf) => buf.format(*v),
            Inner::I64(v, buf) => buf.format(*v),
            Inner::U64(v, buf) => buf.format(*v),
            Inner::F32(v, buf) => {
                if v.is_nan() {
                    float::NAN
                } else if *v == f32::INFINITY {
@@ -165,7 +160,7 @@ impl Encoder {
                    buf.format_finite(*v)
                }
            }
            Encoder::F64(v, buf) => {
            Inner::F64(v, buf) => {
                if v.is_nan() {
                    float::NAN
                } else if *v == f64::INFINITY {
@@ -182,49 +177,49 @@ impl Encoder {

impl From<bool> for Encoder {
    fn from(input: bool) -> Self {
        Self::Bool(input)
        Self(Inner::Bool(input))
    }
}

impl From<i8> for Encoder {
    fn from(input: i8) -> Self {
        Self::I8(input, itoa::Buffer::new())
        Self(Inner::I8(input, itoa::Buffer::new()))
    }
}

impl From<i16> for Encoder {
    fn from(input: i16) -> Self {
        Self::I16(input, itoa::Buffer::new())
        Self(Inner::I16(input, itoa::Buffer::new()))
    }
}

impl From<i32> for Encoder {
    fn from(input: i32) -> Self {
        Self::I32(input, itoa::Buffer::new())
        Self(Inner::I32(input, itoa::Buffer::new()))
    }
}

impl From<i64> for Encoder {
    fn from(input: i64) -> Self {
        Self::I64(input, itoa::Buffer::new())
        Self(Inner::I64(input, itoa::Buffer::new()))
    }
}

impl From<u64> for Encoder {
    fn from(input: u64) -> Self {
        Self::U64(input, itoa::Buffer::new())
        Self(Inner::U64(input, itoa::Buffer::new()))
    }
}

impl From<f32> for Encoder {
    fn from(input: f32) -> Self {
        Self::F32(input, ryu::Buffer::new())
        Self(Inner::F32(input, ryu::Buffer::new()))
    }
}

impl From<f64> for Encoder {
    fn from(input: f64) -> Self {
        Self::F64(input, ryu::Buffer::new())
        Self(Inner::F64(input, ryu::Buffer::new()))
    }
}

+4 −4
Original line number Diff line number Diff line
@@ -112,9 +112,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "clap"
version = "3.0.14"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63edc3f163b3c71ec8aa23f9bd6070f77edbf3d1d198b164afa90ff00e4ec62"
checksum = "e5f1fea81f183005ced9e59cdb01737ef2423956dac5a6d731b06b2ecfaa3467"
dependencies = [
 "atty",
 "bitflags",
@@ -129,9 +129,9 @@ dependencies = [

[[package]]
name = "clap_derive"
version = "3.0.14"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a1132dc3944b31c20dd8b906b3a9f0a5d0243e092d59171414969657ac6aa85"
checksum = "5fd1122e63869df2cb309f449da1ad54a7c6dfeb7c7e6ccd8e0825d9eb93bb72"
dependencies = [
 "heck",
 "proc-macro-error",
Loading