Unverified Commit 43993b38 authored by Nugine's avatar Nugine
Browse files

s3s-aws: conv

parent 7f40dfe2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) {
            rust::Type::StructEnum(_) => {}
        }

        let s3s_path = f!("crate::dto::{name}");
        let s3s_path = f!("s3s::dto::{name}");
        let aws_name = aws_ty_name(name);

        g.ln(f!("impl AwsConversion for {s3s_path} {{"));
@@ -138,6 +138,7 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) {
                for variant in &ty.variants {
                    g.ln(f!("Self::{0} => {aws_name}::{0},", variant.name));
                }
                g.ln("_ => unreachable!(),");
                g.ln("})");
            }
            rust::Type::StructEnum(ty) => {
@@ -145,6 +146,7 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) {
                for variant in &ty.variants {
                    g.ln(f!("Self::{0}(v) => {aws_name}::{0}(try_into_aws(v)?),", variant.name));
                }
                g.ln("_ => unreachable!(),");
                g.ln("})");
            }
            _ => panic!(),
+3 −3
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ mod error;
mod headers;
mod ops;

mod aws;
mod aws_conv;

use crate::gen::Codegen;

@@ -65,8 +65,8 @@ fn main() {
    }

    {
        let path = "crates/s3s/src/aws/generated.rs";
        let path = "crates/s3s-aws/src/conv/generated.rs";
        let mut gen = Codegen::create_file(path).unwrap();
        aws::codegen(&ops, &rust_types, &mut gen);
        aws_conv::codegen(&ops, &rust_types, &mut gen);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ categories = ["web-programming", "web-programming::http-server"]
aws-sdk-s3 = "0.23.0"
aws-smithy-http = "0.53.1"
aws-smithy-types = "0.53.1"
aws-smithy-types-convert = { version = "0.53.1", features = ["convert-time"] }
futures = { version = "0.3.25", default-features = false, features = ["std"] }
hyper = "0.14.23"
s3s = { version = "0.2.0-dev", path = "../s3s" }
+404 −343

File changed and moved.

Preview size limit exceeded, changes collapsed.

+11 −23
Original line number Diff line number Diff line
mod generated;

use crate::error::{S3Error, S3Result};
use s3s::s3_error;
use s3s::{S3Error, S3Result};

use std::collections::HashMap;

@@ -73,7 +74,7 @@ impl<T: AwsConversion> AwsConversion for Vec<T> {
    }
}

impl AwsConversion for crate::dto::Timestamp {
impl AwsConversion for s3s::dto::Timestamp {
    type Target = aws_sdk_s3::types::DateTime;

    fn try_from_aws(x: Self::Target) -> S3Result<Self> {
@@ -87,7 +88,7 @@ impl AwsConversion for crate::dto::Timestamp {
    }
}

impl AwsConversion for crate::dto::ContentType {
impl AwsConversion for s3s::dto::ContentType {
    type Target = String;

    fn try_from_aws(x: Self::Target) -> S3Result<Self> {
@@ -99,7 +100,7 @@ impl AwsConversion for crate::dto::ContentType {
    }
}

impl AwsConversion for crate::dto::CopySource {
impl AwsConversion for s3s::dto::CopySource {
    type Target = String;

    fn try_from_aws(x: Self::Target) -> S3Result<Self> {
@@ -111,7 +112,7 @@ impl AwsConversion for crate::dto::CopySource {
    }
}

impl AwsConversion for crate::dto::Range {
impl AwsConversion for s3s::dto::Range {
    type Target = String;

    fn try_from_aws(x: Self::Target) -> S3Result<Self> {
@@ -123,7 +124,7 @@ impl AwsConversion for crate::dto::Range {
    }
}

impl AwsConversion for crate::dto::Event {
impl AwsConversion for s3s::dto::Event {
    type Target = aws_sdk_s3::model::Event;

    fn try_from_aws(x: Self::Target) -> S3Result<Self> {
@@ -135,11 +136,11 @@ impl AwsConversion for crate::dto::Event {
    }
}

fn stream_from_aws(x: aws_sdk_s3::types::ByteStream) -> Option<crate::dto::StreamingBlob> {
    Some(crate::dto::StreamingBlob::wrap(x))
fn stream_from_aws(x: aws_sdk_s3::types::ByteStream) -> Option<s3s::dto::StreamingBlob> {
    Some(s3s::dto::StreamingBlob::wrap(x))
}

impl AwsConversion for crate::dto::StreamingBlob {
impl AwsConversion for s3s::dto::StreamingBlob {
    type Target = aws_sdk_s3::types::ByteStream;

    fn try_from_aws(x: Self::Target) -> S3Result<Self> {
@@ -151,7 +152,7 @@ impl AwsConversion for crate::dto::StreamingBlob {
    }
}

impl AwsConversion for crate::dto::Body {
impl AwsConversion for s3s::dto::Body {
    type Target = aws_sdk_s3::types::Blob;

    fn try_from_aws(x: Self::Target) -> S3Result<Self> {
@@ -162,16 +163,3 @@ impl AwsConversion for crate::dto::Body {
        Ok(Self::Target::new(x))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn mime() {
        let x: crate::dto::ContentType = mime::TEXT_XML;
        let y = try_into_aws(x.clone()).unwrap();
        let z: crate::dto::ContentType = try_from_aws(y).unwrap();
        assert_eq!(x, z);
    }
}
Loading