aws_db_esdk/deps/aws_cryptography_keyStore/conversions/
error.rs

1// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3// Do not modify this file. This file is machine generated, and any changes to it will be overwritten.
4/// Wraps up an arbitrary Rust Error value as a Dafny Error
5pub fn to_opaque_error(
6    value: String,
7) -> ::dafny_runtime::Rc<
8    crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error,
9> {
10    let error_msg = value.clone();
11    let error_msg =
12        ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(
13            &error_msg,
14        );
15    let error_obj: ::dafny_runtime::Object<::dafny_runtime::DynAny> =
16        ::dafny_runtime::Object(Some(::dafny_runtime::Rc::new(
17            ::dafny_runtime::UnsafeCell::new(value),
18        )));
19    ::dafny_runtime::Rc::new(
20        crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::OpaqueWithText {
21            obj: error_obj,
22	    objMessage: error_msg
23        },
24    )
25}
26
27/// Wraps up an arbitrary Rust Error value as a Dafny Result<T, Error>.Failure
28pub fn to_opaque_error_result<T: ::dafny_runtime::DafnyType>(
29    value: String,
30) -> ::dafny_runtime::Rc<
31    crate::_Wrappers_Compile::Result<
32        T,
33        ::dafny_runtime::Rc<
34            crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error,
35        >,
36    >,
37> {
38    ::dafny_runtime::Rc::new(crate::_Wrappers_Compile::Result::Failure {
39        error: to_opaque_error(value),
40    })
41}
42pub fn to_dafny(
43    value: crate::deps::aws_cryptography_keyStore::types::error::Error,
44) -> ::dafny_runtime::Rc<
45    crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error,
46> {
47    ::dafny_runtime::Rc::new(match value {
48        crate::deps::aws_cryptography_keyStore::types::error::Error::KeyStoreException { message } =>
49    crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::KeyStoreException {
50        message: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&message),
51    },
52crate::deps::aws_cryptography_keyStore::types::error::Error::DynamoDB_20120810Error { error } =>
53    crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::ComAmazonawsDynamodb {
54        ComAmazonawsDynamodb: crate::deps::com_amazonaws_dynamodb::conversions::error::to_dafny(error),
55    },
56crate::deps::aws_cryptography_keyStore::types::error::Error::TrentServiceError { error } =>
57    crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::ComAmazonawsKms {
58        ComAmazonawsKms: crate::deps::com_amazonaws_kms::conversions::error::to_dafny(error),
59    },
60        crate::deps::aws_cryptography_keyStore::types::error::Error::CollectionOfErrors { list, message } =>
61            crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::CollectionOfErrors {
62                message: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&message),
63                list: ::dafny_runtime::dafny_runtime_conversions::vec_to_dafny_sequence(&list, |e| to_dafny(e.clone()))
64            },
65        crate::deps::aws_cryptography_keyStore::types::error::Error::ValidationError(inner) =>
66            crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::Opaque {
67                obj: {
68                    let rc = ::dafny_runtime::Rc::new(inner) as ::dafny_runtime::Rc<::dafny_runtime::DynAny>;
69                    // safety: `rc` is new, ensuring it has refcount 1 and is uniquely owned.
70                    // we should use `dafny_runtime_conversions::rc_struct_to_dafny_class` once it
71                    // accepts unsized types (https://github.com/dafny-lang/dafny/pull/5769)
72                    unsafe { ::dafny_runtime::Object::from_rc(rc) }
73                },
74            },
75            crate::deps::aws_cryptography_keyStore::types::error::Error::Opaque { obj } =>
76            crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::Opaque {
77                obj: ::dafny_runtime::Object(obj.0)
78            },
79            crate::deps::aws_cryptography_keyStore::types::error::Error::OpaqueWithText { obj, objMessage } =>
80            crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::OpaqueWithText {
81                obj: ::dafny_runtime::Object(obj.0),
82                objMessage: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&objMessage),
83            },
84    })
85}
86
87#[allow(dead_code)]
88pub fn from_dafny(
89    dafny_value: ::dafny_runtime::Rc<
90        crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error,
91    >,
92) -> crate::deps::aws_cryptography_keyStore::types::error::Error {
93    match ::std::borrow::Borrow::borrow(&dafny_value) {
94        crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::KeyStoreException { message } =>
95    crate::deps::aws_cryptography_keyStore::types::error::Error::KeyStoreException {
96        message: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string(&message),
97    },
98crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::ComAmazonawsDynamodb { ComAmazonawsDynamodb } =>
99    crate::deps::aws_cryptography_keyStore::types::error::Error::DynamoDB_20120810Error {
100        error: crate::deps::com_amazonaws_dynamodb::conversions::error::from_dafny(ComAmazonawsDynamodb.clone()),
101    },
102crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::ComAmazonawsKms { ComAmazonawsKms } =>
103    crate::deps::aws_cryptography_keyStore::types::error::Error::TrentServiceError {
104        error: crate::deps::com_amazonaws_kms::conversions::error::from_dafny(ComAmazonawsKms.clone()),
105    },
106        crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::CollectionOfErrors { list, message } =>
107            crate::deps::aws_cryptography_keyStore::types::error::Error::CollectionOfErrors {
108                message: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string(&message),
109                list: ::dafny_runtime::dafny_runtime_conversions::dafny_sequence_to_vec(&list, |e| from_dafny(e.clone()))
110            },
111        crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::Opaque { obj } =>
112            crate::deps::aws_cryptography_keyStore::types::error::Error::Opaque {
113                obj: obj.clone()
114            },
115            crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::Opaque { obj } =>
116            {
117                use ::std::any::Any;
118                if ::dafny_runtime::is_object!(obj, crate::deps::aws_cryptography_keyStore::types::error::ValidationError) {
119                    let typed = ::dafny_runtime::cast_object!(obj.clone(), crate::deps::aws_cryptography_keyStore::types::error::ValidationError);
120                    crate::deps::aws_cryptography_keyStore::types::error::Error::ValidationError(
121                        // safety: dafny_class_to_struct will increment ValidationError's Rc
122                        unsafe {
123                            ::dafny_runtime::dafny_runtime_conversions::object::dafny_class_to_struct(typed)
124                        }
125                    )
126                } else {
127                    crate::deps::aws_cryptography_keyStore::types::error::Error::Opaque {
128                        obj: obj.clone()
129                    }
130                }
131            },
132            crate::r#software::amazon::cryptography::keystore::internaldafny::types::Error::OpaqueWithText { obj, objMessage } =>
133            {
134                use ::std::any::Any;
135                if ::dafny_runtime::is_object!(obj, crate::deps::aws_cryptography_keyStore::types::error::ValidationError) {
136                    let typed = ::dafny_runtime::cast_object!(obj.clone(), crate::deps::aws_cryptography_keyStore::types::error::ValidationError);
137                    crate::deps::aws_cryptography_keyStore::types::error::Error::ValidationError(
138                        // safety: dafny_class_to_struct will increment ValidationError's Rc
139                        unsafe {
140                            ::dafny_runtime::dafny_runtime_conversions::object::dafny_class_to_struct(typed)
141                        }
142                    )
143                } else {
144                    crate::deps::aws_cryptography_keyStore::types::error::Error::OpaqueWithText {
145                        obj: obj.clone(),
146                        objMessage: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::dafny_string_to_string(&objMessage),
147                    }
148                }
149            },
150    }
151}