id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:9 | assert!(matches!(
u64::try_from(Number::NegInt(-1i64)).unwrap_err(),
TryFromNumberError {
kind: TryFromNumberErrorKind::NegativeToUnsignedLossyConversion(..)
}
));
for val in [69.69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0/sdk/aws-smithy-types/src/lib.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:10 | TryFromNumberError {
kind: TryFromNumberErrorKind::OutsideIntegerRange(..)
}
));
assert!(matches!(
$typ::try_from(Number::NegInt(($typ::MIN as i64) - 1i64)).unwrap_err(),
TryFromNumberError {
kind: TryFromNu... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0/sdk/aws-smithy-types/src/lib.rs | 361 | 420 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:11 | to_signed_converter_tests!(i32);
}
#[test]
fn to_i16() {
to_signed_converter_tests!(i16);
}
#[test]
fn to_i8() {
to_signed_converter_tests!(i8);
}
#[test]
fn to_f64() {
assert_eq!(f64::try_from(Number::PosInt(69u64)).unwrap(), 69f64);
assert_eq!(f64... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0/sdk/aws-smithy-types/src/lib.rs | 401 | 460 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:12 | assert_eq!(
f64::try_from(Number::NegInt(-significand_max_i64)).unwrap(),
-9007199254740992f64
);
assert!(matches!(
f64::try_from(Number::PosInt(significand_max_u64 + 1)).unwrap_err(),
TryFromNumberError {
kind: TryFromNumberErrorKind::U64... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0/sdk/aws-smithy-types/src/lib.rs | 441 | 500 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:13 | f32::try_from(Number::NegInt(significand_max_i64)).unwrap(),
16777216f32
);
assert_eq!(
f32::try_from(Number::NegInt(-significand_max_i64)).unwrap(),
-16777216f32
);
assert!(matches!(
f32::try_from(Number::PosInt(significand_max_u64 + 1)).... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0/sdk/aws-smithy-types/src/lib.rs | 481 | 540 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:14 | assert_eq!(Number::PosInt(69u64).to_f64_lossy(), 69f64);
assert_eq!(
Number::PosInt((1 << 53) + 1).to_f64_lossy(),
9007199254740992f64
);
assert_eq!(
Number::NegInt(-(1 << 53) - 1).to_f64_lossy(),
-9007199254740992f64
);
}
#[test]
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4b63da536d7ab05c7918f3e21a270e4fdcf9cfe0/sdk/aws-smithy-types/src/lib.rs | 521 | 542 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//! Protocol-agnostic types for smithy-rs.
#![warn(
missing_docs,
rustdoc::missing_crate_level_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]
use std::col... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:2 | inner: input.into(),
}
}
/// Consumes the `Blob` and returns a `Vec<u8>` with its contents.
pub fn into_inner(self) -> Vec<u8> {
self.inner
}
}
impl AsRef<[u8]> for Blob {
fn as_ref(&self) -> &[u8] {
&self.inner
}
}
/* ANCHOR: document */
/// Document Type
///
/// Doc... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:4 | /// Use `Number::try_from` to make the conversion only if it is not lossy.
pub fn to_f64_lossy(self) -> f64 {
match self {
Number::PosInt(v) => v as f64,
Number::NegInt(v) => v as f64,
Number::Float(v) => v as f64,
}
}
/// Converts to an `f32` lossily.
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:5 | match self {
TryFromNumberError::OutsideIntegerRange(err) => write!(f, "integer too large: {}", err),
TryFromNumberError::FloatToIntegerLossyConversion(v) => write!(
f,
"cannot convert floating point number {} into an integer",
v
),
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:6 | macro_rules! to_unsigned_integer_converter {
($typ:ident, $styp:expr) => {
#[doc = "Converts to a `"]
#[doc = $styp]
#[doc = "`. This conversion fails if it is lossy."]
impl TryFrom<Number> for $typ {
type Error = TryFromNumberError;
fn try_from(value: Number... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:7 | };
($typ:ident) => {
to_signed_integer_converter!($typ, stringify!($typ));
};
}
/// Converts to a `u64`. The conversion fails if it is lossy.
impl TryFrom<Number> for u64 {
type Error = TryFromNumberError;
fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:8 | type Error = TryFromNumberError;
fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
// Integers can only be represented with full precision in a float if they fit in the
// significand, which is 24 bits in `f32` and 53 bits in `f64`.
// https://githu... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:9 | if (-(1 << 24)..=(1 << 24)).contains(&v) {
Ok(v as Self)
} else {
Err(Self::Error::I64ToFloatLossyConversion(v))
}
}
Number::Float(v) => Err(Self::Error::F64ToF32LossyConversion(v)),
}
}
}
#[cfg(test)]
mod numbe... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:10 | assert_eq!(u64::try_from(Number::PosInt(69u64)).unwrap(), 69u64);
assert!(matches!(
u64::try_from(Number::NegInt(-1i64)).unwrap_err(),
TryFromNumberError::NegativeToUnsignedLossyConversion(..)
));
for val in [69.69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 361 | 420 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:11 | assert!(matches!(
$typ::try_from(Number::NegInt(($typ::MIN as i64) - 1i64)).unwrap_err(),
TryFromNumberError::OutsideIntegerRange(..)
));
for val in [69.69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(matches!(
u64... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 401 | 460 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:12 | }
#[test]
fn to_f64() {
assert_eq!(f64::try_from(Number::PosInt(69u64)).unwrap(), 69f64);
assert_eq!(f64::try_from(Number::NegInt(-69i64)).unwrap(), -69f64);
assert_eq!(f64::try_from(Number::Float(-69f64)).unwrap(), -69f64);
assert!(f64::try_from(Number::Float(f64::NAN)).unwrap(... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 441 | 500 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:13 | f64::try_from(Number::NegInt(significand_max_i64 + 1)).unwrap_err(),
TryFromNumberError::I64ToFloatLossyConversion(..)
));
assert!(matches!(
f64::try_from(Number::NegInt(-significand_max_i64 - 1)).unwrap_err(),
TryFromNumberError::I64ToFloatLossyConversion(..)
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 481 | 540 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:14 | assert!(matches!(
f32::try_from(Number::NegInt(-significand_max_i64 - 1)).unwrap_err(),
TryFromNumberError::I64ToFloatLossyConversion(..)
));
for val in [69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(matches!(
f32::try_from(Number::Floa... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 10fe75faa5af6b46fe6e065e027dae9b0024c645 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/10fe75faa5af6b46fe6e065e027dae9b0024c645/sdk/aws-smithy-types/src/lib.rs | 521 | 557 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//! Protocol-agnostic types for smithy-rs.
#![warn(
missing_docs,
rustdoc::missing_crate_level_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]
use std::col... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:2 | }
/// Consumes the `Blob` and returns a `Vec<u8>` with its contents.
pub fn into_inner(self) -> Vec<u8> {
self.inner
}
}
impl AsRef<[u8]> for Blob {
fn as_ref(&self) -> &[u8] {
&self.inner
}
}
/* ANCHOR: document */
/// Document Type
///
/// Document types represents protocol-agn... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:3 | Document::Bool(value)
}
}
impl From<String> for Document {
fn from(value: String) -> Self {
Document::String(value)
}
}
impl From<Vec<Document>> for Document {
fn from(values: Vec<Document>) -> Self {
Document::Array(values)
}
}
impl From<HashMap<String, Document>> for Document {
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:4 | match self {
Number::PosInt(v) => v as f64,
Number::NegInt(v) => v as f64,
Number::Float(v) => v as f64,
}
}
/// Converts to an `f32` lossily.
/// Use `Number::try_from` to make the conversion only if it is not lossy.
pub fn to_f32_lossy(self) -> f32 {
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:5 | TryFromNumberError::FloatToIntegerLossyConversion(v) => write!(
f,
"cannot convert floating point number {} into an integer",
v
),
TryFromNumberError::NegativeToUnsignedLossyConversion(v) => write!(
f,
"cannot conver... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:6 | ($typ:ident, $styp:expr) => {
#[doc = "Converts to a `"]
#[doc = $styp]
#[doc = "`. This conversion fails if it is lossy."]
impl TryFrom<Number> for $typ {
type Error = TryFromNumberError;
fn try_from(value: Number) -> Result<Self, Self::Error> {
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:7 | ($typ:ident) => {
to_signed_integer_converter!($typ, stringify!($typ));
};
}
/// Converts to a `u64`. The conversion fails if it is lossy.
impl TryFrom<Number> for u64 {
type Error = TryFromNumberError;
fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
Num... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:8 | fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
// Integers can only be represented with full precision in a float if they fit in the
// significand, which is 24 bits in `f32` and 53 bits in `f64`.
// https://github.com/rust-lang/rust/blob/58f11791af4f... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:9 | } else {
Err(Self::Error::I64ToFloatLossyConversion(v))
}
}
Number::Float(v) => Err(Self::Error::F64ToF32LossyConversion(v)),
}
}
}
#[cfg(test)]
mod number {
use super::*;
macro_rules! to_unsigned_converter_tests {
($typ:ident) =>... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:10 | assert!(matches!(
u64::try_from(Number::NegInt(-1i64)).unwrap_err(),
TryFromNumberError::NegativeToUnsignedLossyConversion(..)
));
for val in [69.69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(matches!(
u64::try_from(Number::Float(val)).... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 361 | 420 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:11 | TryFromNumberError::OutsideIntegerRange(..)
));
for val in [69.69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(matches!(
u64::try_from(Number::Float(val)).unwrap_err(),
TryFromNumberError::FloatToIntegerLossyConversion(..)
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 401 | 460 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:12 | #[test]
fn to_f64() {
assert_eq!(f64::try_from(Number::PosInt(69u64)).unwrap(), 69f64);
assert_eq!(f64::try_from(Number::NegInt(-69i64)).unwrap(), -69f64);
assert_eq!(f64::try_from(Number::Float(-69f64)).unwrap(), -69f64);
assert!(f64::try_from(Number::Float(f64::NAN)).unwrap().is_na... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 441 | 500 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:13 | ));
assert!(matches!(
f64::try_from(Number::NegInt(-significand_max_i64 - 1)).unwrap_err(),
TryFromNumberError::I64ToFloatLossyConversion(..)
));
}
#[test]
fn to_f32() {
assert_eq!(f32::try_from(Number::PosInt(69u64)).unwrap(), 69f32);
assert_eq!(f32:... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 481 | 540 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:14 | TryFromNumberError::I64ToFloatLossyConversion(..)
));
for val in [69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(matches!(
f32::try_from(Number::Float(val)).unwrap_err(),
TryFromNumberError::F64ToF32LossyConversion(..)
));
}
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 521 | 580 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:15 | use crate::retry::{ErrorKind, ProvideErrorKind};
use std::collections::HashMap;
use std::fmt;
use std::fmt::{Display, Formatter};
/// Generic Error type
///
/// For many services, Errors are modeled. However, many services only partially model errors or don't
/// model errors at all. In the... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 561 | 620 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:16 | self
}
/// Set a custom field on the error metadata
///
/// Typically, these will be accessed with an extension trait:
/// ```rust
/// use aws_smithy_types::Error;
/// const HOST_ID: &str = "host_id";
/// trait S3ErrorExt {
/// fn extended_req... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 601 | 660 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:17 | /// Returns the error code.
pub fn code(&self) -> Option<&str> {
self.code.as_deref()
}
/// Returns the error message.
pub fn message(&self) -> Option<&str> {
self.message.as_deref()
}
/// Returns the request ID the error occurred for, if it's avai... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 641 | 699 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:18 | let mut fmt = f.debug_struct("Error");
if let Some(code) = &self.code {
fmt.field("code", code);
}
if let Some(message) = &self.message {
fmt.field("message", message);
}
if let Some(req_id) = &self.request_id {
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 7a46124da32a066e7fb6a1d647e2f99cbbb026e0 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/7a46124da32a066e7fb6a1d647e2f99cbbb026e0/sdk/aws-smithy-types/src/lib.rs | 681 | 699 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:7 | ($typ:ident) => {
to_signed_integer_converter!($typ, stringify!($typ));
};
}
/// Converts to a `u64`. The conversion fails if it is lossy.
impl TryFrom<Number> for u64 {
type Error = TryFromNumberError;
fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
Num... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 9407b2314c6568f5e73be6951cba668511d366d5 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/9407b2314c6568f5e73be6951cba668511d366d5/sdk/aws-smithy-types/src/lib.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:8 | fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
// Integers can only be represented with full precision in a float if they fit in the
// significand, which is 24 bits in `f32` and 53 bits in `f64`.
// https://github.com/rust-lang/rust/blob/58f11791af4f... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 9407b2314c6568f5e73be6951cba668511d366d5 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/9407b2314c6568f5e73be6951cba668511d366d5/sdk/aws-smithy-types/src/lib.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//! Protocol-agnostic types for smithy-rs.
#![warn(
missing_docs,
rustdoc::missing_crate_level_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]
use std::col... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:2 | }
}
/// Consumes the `Blob` and returns a `Vec<u8>` with its contents.
pub fn into_inner(self) -> Vec<u8> {
self.inner
}
}
impl AsRef<[u8]> for Blob {
fn as_ref(&self) -> &[u8] {
&self.inner
}
}
/* ANCHOR: document */
/// Document Type
///
/// Document types represents protoc... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:3 | fn from(value: bool) -> Self {
Document::Bool(value)
}
}
impl From<String> for Document {
fn from(value: String) -> Self {
Document::String(value)
}
}
impl From<Vec<Document>> for Document {
fn from(values: Vec<Document>) -> Self {
Document::Array(values)
}
}
impl From<Has... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:4 | pub fn to_f64_lossy(self) -> f64 {
match self {
Number::PosInt(v) => v as f64,
Number::NegInt(v) => v as f64,
Number::Float(v) => v as f64,
}
}
/// Converts to an `f32` lossily.
/// Use `Number::try_from` to make the conversion only if it is not lossy.
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:5 | TryFromNumberError::OutsideIntegerRange(err) => write!(f, "integer too large: {}", err),
TryFromNumberError::FloatToIntegerLossyConversion(v) => write!(
f,
"cannot convert floating point number {} into an integer",
v
),
TryFromNumberErr... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:6 | macro_rules! to_unsigned_integer_converter {
($typ:ident, $styp:expr) => {
#[doc = "Converts to a `"]
#[doc = $styp]
#[doc = "`. This conversion fails if it is lossy."]
impl TryFrom<Number> for $typ {
type Error = TryFromNumberError;
fn try_from(value: Number... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:7 | ($typ:ident) => {
to_signed_integer_converter!($typ, stringify!($typ));
};
}
/// Converts to a `u64`. The conversion fails if it is lossy.
impl TryFrom<Number> for u64 {
type Error = TryFromNumberError;
fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
Num... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:8 | fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
// Integers can only be represented with full precision in a float if they fit in the
// significand, which is 24 bits in `f32` and 53 bits in `f64`.
// https://github.com/rust-lang/rust/blob/58f11791af4f... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:9 | Ok(v as Self)
} else {
Err(Self::Error::I64ToFloatLossyConversion(v))
}
}
Number::Float(v) => Err(Self::Error::F64ToF32LossyConversion(v)),
}
}
}
#[cfg(test)]
mod number {
use super::*;
macro_rules! to_unsigned_converter_t... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:10 | assert!(matches!(
u64::try_from(Number::NegInt(-1i64)).unwrap_err(),
TryFromNumberError::NegativeToUnsignedLossyConversion(..)
));
for val in [69.69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(matches!(
u64::try_from(Number::Float(val)).... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 361 | 420 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:11 | $typ::try_from(Number::NegInt(($typ::MIN as i64) - 1i64)).unwrap_err(),
TryFromNumberError::OutsideIntegerRange(..)
));
for val in [69.69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(matches!(
u64::try_from(Number::Float(val)).unw... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 401 | 460 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:13 | TryFromNumberError::I64ToFloatLossyConversion(..)
));
assert!(matches!(
f64::try_from(Number::NegInt(-significand_max_i64 - 1)).unwrap_err(),
TryFromNumberError::I64ToFloatLossyConversion(..)
));
}
#[test]
fn to_f32() {
assert_eq!(f32::try_from(Number... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 481 | 540 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:14 | f32::try_from(Number::NegInt(-significand_max_i64 - 1)).unwrap_err(),
TryFromNumberError::I64ToFloatLossyConversion(..)
));
for val in [69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(matches!(
f32::try_from(Number::Float(val)).unwrap_err(),
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 521 | 580 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:15 | pub mod error {
use crate::retry::{ErrorKind, ProvideErrorKind};
use std::collections::HashMap;
use std::fmt;
use std::fmt::{Display, Formatter};
/// Generic Error type
///
/// For many services, Errors are modeled. However, many services only partially model errors or don't
/// model e... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 561 | 620 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:16 | self.inner.request_id = Some(request_id.into());
self
}
/// Set a custom field on the error metadata
///
/// Typically, these will be accessed with an extension trait:
/// ```rust
/// use aws_smithy_types::Error;
/// const HOST_ID: &str = "host_id";
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 601 | 660 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:17 | impl Error {
/// Returns the error code.
pub fn code(&self) -> Option<&str> {
self.code.as_deref()
}
/// Returns the error message.
pub fn message(&self) -> Option<&str> {
self.message.as_deref()
}
/// Returns the request ID the error occur... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 641 | 700 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:18 | fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut fmt = f.debug_struct("Error");
if let Some(code) = &self.code {
fmt.field("code", code);
}
if let Some(message) = &self.message {
fmt.field("message", message);
}
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 2009bc55e8c04a2d18f86edacf0f41203dd8b106 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/2009bc55e8c04a2d18f86edacf0f41203dd8b106/sdk/aws-smithy-types/src/lib.rs | 681 | 700 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//! Protocol-agnostic types for smithy-rs.
#![warn(
missing_docs,
rustdoc::missing_crate_level_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]
use std::col... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:2 | }
/// Consumes the `Blob` and returns a `Vec<u8>` with its contents.
pub fn into_inner(self) -> Vec<u8> {
self.inner
}
}
impl AsRef<[u8]> for Blob {
fn as_ref(&self) -> &[u8] {
&self.inner
}
}
/* ANCHOR: document */
/// Document Type
///
/// Document types represents protocol-agn... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:3 | #[derive(Debug, Clone, Copy, PartialEq)]
pub enum Number {
/// Unsigned 64-bit integer value.
PosInt(u64),
/// Signed 64-bit integer value. The wrapped value is _always_ negative.
NegInt(i64),
/// 64-bit floating-point value.
Float(f64),
}
/* ANCHOR_END: document */
impl Number {
/// Conve... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:4 | U64ToFloatLossyConversion(u64),
/// Used when the conversion from an `i64` into a floating point type would be lossy.
I64ToFloatLossyConversion(i64),
/// Used when attempting to convert an `f64` into an `f32`.
F64ToF32LossyConversion(f64),
/// Used when attempting to convert a decimal, infinite, or ... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:5 | TryFromNumberError::F64ToF32LossyConversion(v) => {
write!(f, "will not attempt to convert {}f64 into a f32", v)
}
}
}
}
impl std::error::Error for TryFromNumberError {}
impl From<std::num::TryFromIntError> for TryFromNumberError {
fn from(value: std::num::TryFromIntError) ... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:6 | #[doc = "Converts to a `"]
#[doc = $styp]
#[doc = "`. This conversion fails if it is lossy."]
impl TryFrom<Number> for $typ {
type Error = TryFromNumberError;
fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
Numb... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:7 | fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
Number::PosInt(v) => Ok(Self::try_from(v)?),
Number::NegInt(v) => Ok(v),
Number::Float(v) => Err(Self::Error::FloatToIntegerLossyConversion(v)),
}
}
}
to_signed_integer_converter!(i32);
to_sig... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:8 | /// Converts to an `f64`. The conversion fails if it is lossy.
impl TryFrom<Number> for f32 {
type Error = TryFromNumberError;
fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
Number::PosInt(v) => {
if v <= (1 << 24) {
Ok(v as Self)... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 281 | 340 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:9 | TryFromNumberError::NegativeToUnsignedLossyConversion(..)
));
for val in [69.69f64, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(matches!(
$typ::try_from(Number::Float(val)).unwrap_err(),
TryFromNumberError::FloatToIntegerLossyCon... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 321 | 380 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:10 | fn to_u8() {
to_unsigned_converter_tests!(u8);
}
macro_rules! to_signed_converter_tests {
($typ:ident) => {
assert_eq!($typ::try_from(Number::PosInt(69u64)).unwrap(), 69);
assert_eq!($typ::try_from(Number::NegInt(-69i64)).unwrap(), -69);
assert!(matches!(
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 361 | 420 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:11 | #[test]
fn to_i32() {
to_signed_converter_tests!(i32);
}
#[test]
fn to_i16() {
to_signed_converter_tests!(i16);
}
#[test]
fn to_i8() {
to_signed_converter_tests!(i8);
}
#[test]
fn to_f64() {
assert_eq!(f64::try_from(Number::PosInt(69u64)).unwrap... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 401 | 460 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:12 | f64::try_from(Number::NegInt(significand_max_i64)).unwrap(),
9007199254740992f64
);
assert_eq!(
f64::try_from(Number::NegInt(-significand_max_i64)).unwrap(),
-9007199254740992f64
);
assert!(matches!(
f64::try_from(Number::PosInt(significan... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 441 | 500 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:13 | assert_eq!(
f32::try_from(Number::NegInt(-significand_max_i64)).unwrap(),
-16777216f32
);
assert!(matches!(
f32::try_from(Number::PosInt(significand_max_u64 + 1)).unwrap_err(),
TryFromNumberError::U64ToFloatLossyConversion(..)
));
assert!... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 481 | 540 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:14 | #[test]
fn to_f32_lossy() {
assert_eq!(Number::PosInt(69u64).to_f32_lossy(), 69f32);
assert_eq!(Number::PosInt((1 << 24) + 1).to_f32_lossy(), 16777216f32);
assert_eq!(Number::NegInt(-(1 << 24) - 1).to_f32_lossy(), -16777216f32);
assert_eq!(
Number::Float(1452089033.767493... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 521 | 580 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:15 | impl Builder {
/// Sets the error message.
pub fn message(&mut self, message: impl Into<String>) -> &mut Self {
self.inner.message = Some(message.into());
self
}
/// Sets the error code.
pub fn code(&mut self, code: impl Into<String>) -> &mut Self {
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 561 | 620 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:16 | /// println!("request id: {:?}, extended request id: {:?}", err.request_id(), err.extended_request_id());
/// }
/// }
/// ```
pub fn custom(&mut self, key: &'static str, value: impl Into<String>) -> &mut Self {
self.inner.extras.insert(key, value.into());
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 601 | 660 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:17 | Builder { inner: self }
}
}
impl ProvideErrorKind for Error {
fn retryable_error_kind(&self) -> Option<ErrorKind> {
None
}
fn code(&self) -> Option<&str> {
Error::code(self)
}
}
impl Display for Error {
fn fmt(&self, f: &mut Form... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8fc189b2b3d2f245aad67de7cd6c4c0cdbc6acc7/sdk/aws-smithy-types/src/lib.rs | 641 | 675 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:2 | }
/// Consumes the `Blob` and returns a `Vec<u8>` with its contents.
pub fn into_inner(self) -> Vec<u8> {
self.inner
}
}
impl AsRef<[u8]> for Blob {
fn as_ref(&self) -> &[u8] {
&self.inner
}
}
/* ANCHOR: document */
/// Document Type
///
/// Document types represents protocol-agn... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8159cb8ff570e4dca718e354c31cecdfadfeb0b8 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8159cb8ff570e4dca718e354c31cecdfadfeb0b8/sdk/aws-smithy-types/src/lib.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:3 | #[derive(Debug, Clone, Copy, PartialEq)]
pub enum Number {
/// Unsigned 64-bit integer value
PosInt(u64),
/// Signed 64-bit integer value
NegInt(i64),
/// 64-bit floating-point value
Float(f64),
}
macro_rules! to_num_fn {
($name:ident, $typ:ident, $styp:expr) => {
#[doc = "Converts ... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8159cb8ff570e4dca718e354c31cecdfadfeb0b8 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8159cb8ff570e4dca718e354c31cecdfadfeb0b8/sdk/aws-smithy-types/src/lib.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:4 | to_num_fn!(to_u32, u32);
to_num_fn!(to_u64, u64);
}
/* ANCHOR_END: document */
pub use error::Error;
/// Generic errors for Smithy codegen
pub mod error {
use crate::retry::{ErrorKind, ProvideErrorKind};
use std::collections::HashMap;
use std::fmt;
use std::fmt::{Display, Formatter};
/// Gen... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8159cb8ff570e4dca718e354c31cecdfadfeb0b8 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8159cb8ff570e4dca718e354c31cecdfadfeb0b8/sdk/aws-smithy-types/src/lib.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:5 | /// Sets the error code.
pub fn code(&mut self, code: impl Into<String>) -> &mut Self {
self.inner.code = Some(code.into());
self
}
/// Sets the request ID the error happened for.
pub fn request_id(&mut self, request_id: impl Into<String>) -> &mut Self {
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8159cb8ff570e4dca718e354c31cecdfadfeb0b8 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8159cb8ff570e4dca718e354c31cecdfadfeb0b8/sdk/aws-smithy-types/src/lib.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:6 | self
}
/// Creates the error.
pub fn build(&mut self) -> Error {
std::mem::take(&mut self.inner)
}
}
impl Error {
/// Returns the error code.
pub fn code(&self) -> Option<&str> {
self.code.as_deref()
}
/// Returns the erro... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8159cb8ff570e4dca718e354c31cecdfadfeb0b8 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8159cb8ff570e4dca718e354c31cecdfadfeb0b8/sdk/aws-smithy-types/src/lib.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:7 | None
}
fn code(&self) -> Option<&str> {
Error::code(self)
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut fmt = f.debug_struct("Error");
if let Some(code) = &self.code {
fmt.field("co... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 8159cb8ff570e4dca718e354c31cecdfadfeb0b8 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/8159cb8ff570e4dca718e354c31cecdfadfeb0b8/sdk/aws-smithy-types/src/lib.rs | 241 | 269 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
//! Protocol-agnostic types for smithy-rs.
#![warn(
missing_docs,
rustdoc::missing_crate_level_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]
use std::co... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | d53c304b35177bacd4c2c1b29211236f8a995cdc | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/d53c304b35177bacd4c2c1b29211236f8a995cdc/sdk/aws-smithy-types/src/lib.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:2 | }
/// Consumes the `Blob` and returns a `Vec<u8>` with its contents.
pub fn into_inner(self) -> Vec<u8> {
self.inner
}
}
impl AsRef<[u8]> for Blob {
fn as_ref(&self) -> &[u8] {
&self.inner
}
}
/* ANCHOR: document */
/// Document Type
///
/// Document types represents protocol-agn... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4affc2ae319f6aef20a5fa66617c6774b3a7f4ea | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4affc2ae319f6aef20a5fa66617c6774b3a7f4ea/sdk/aws-smithy-types/src/lib.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:3 | #[derive(Debug, Clone, Copy, PartialEq)]
pub enum Number {
/// Unsigned 64-bit integer value
PosInt(u64),
/// Signed 64-bit integer value
NegInt(i64),
/// 64-bit floating-point value
Float(f64),
}
macro_rules! to_num_fn {
($name:ident, $typ:ident) => {
/// Converts to a `$typ`. This... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4affc2ae319f6aef20a5fa66617c6774b3a7f4ea | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4affc2ae319f6aef20a5fa66617c6774b3a7f4ea/sdk/aws-smithy-types/src/lib.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:4 | pub use error::Error;
/// Generic errors for Smithy codegen
pub mod error {
use crate::retry::{ErrorKind, ProvideErrorKind};
use std::collections::HashMap;
use std::fmt;
use std::fmt::{Display, Formatter};
/// Generic Error type
///
/// For many services, Errors are modeled. However, many ... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4affc2ae319f6aef20a5fa66617c6774b3a7f4ea | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4affc2ae319f6aef20a5fa66617c6774b3a7f4ea/sdk/aws-smithy-types/src/lib.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:5 | /// Sets the request ID the error happened for.
pub fn request_id(&mut self, request_id: impl Into<String>) -> &mut Self {
self.inner.request_id = Some(request_id.into());
self
}
/// Set a custom field on the error metadata
///
/// Typically, these will b... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4affc2ae319f6aef20a5fa66617c6774b3a7f4ea | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4affc2ae319f6aef20a5fa66617c6774b3a7f4ea/sdk/aws-smithy-types/src/lib.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:6 | }
}
impl Error {
/// Returns the error code.
pub fn code(&self) -> Option<&str> {
self.code.as_deref()
}
/// Returns the error message.
pub fn message(&self) -> Option<&str> {
self.message.as_deref()
}
/// Returns the request ID th... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4affc2ae319f6aef20a5fa66617c6774b3a7f4ea | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4affc2ae319f6aef20a5fa66617c6774b3a7f4ea/sdk/aws-smithy-types/src/lib.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:7 | }
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut fmt = f.debug_struct("Error");
if let Some(code) = &self.code {
fmt.field("code", code);
}
if let Some(message) = &self.message {
fmt.fiel... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 4affc2ae319f6aef20a5fa66617c6774b3a7f4ea | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/4affc2ae319f6aef20a5fa66617c6774b3a7f4ea/sdk/aws-smithy-types/src/lib.rs | 241 | 263 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
//! Protocol-agnostic types for smithy-rs.
#![warn(
missing_docs,
rustdoc::missing_crate_level_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]
use std::co... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 5f4378d3e820cebbb6b7e7413d4592c7d5441559 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5f4378d3e820cebbb6b7e7413d4592c7d5441559/sdk/aws-smithy-types/src/lib.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:2 | /// Consumes the `Blob` and returns a `Vec<u8>` with its contents.
pub fn into_inner(self) -> Vec<u8> {
self.inner
}
}
impl AsRef<[u8]> for Blob {
fn as_ref(&self) -> &[u8] {
&self.inner
}
}
/* ANCHOR: document */
/// Document Type
///
/// Document types represents protocol-agnostic o... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 5f4378d3e820cebbb6b7e7413d4592c7d5441559 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5f4378d3e820cebbb6b7e7413d4592c7d5441559/sdk/aws-smithy-types/src/lib.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:3 | pub enum Number {
/// Unsigned 64-bit integer value
PosInt(u64),
/// Signed 64-bit integer value
NegInt(i64),
/// 64-bit floating-point value
Float(f64),
}
macro_rules! to_num_fn {
($name:ident, $typ:ident) => {
/// Converts to a `$typ`. This conversion may be lossy.
pub fn ... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 5f4378d3e820cebbb6b7e7413d4592c7d5441559 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5f4378d3e820cebbb6b7e7413d4592c7d5441559/sdk/aws-smithy-types/src/lib.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:4 | /// Generic errors for Smithy codegen
pub mod error {
use crate::retry::{ErrorKind, ProvideErrorKind};
use std::collections::HashMap;
use std::fmt;
use std::fmt::{Display, Formatter};
/// Generic Error type
///
/// For many services, Errors are modeled. However, many services only partially... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 5f4378d3e820cebbb6b7e7413d4592c7d5441559 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5f4378d3e820cebbb6b7e7413d4592c7d5441559/sdk/aws-smithy-types/src/lib.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:6 | }
impl Error {
/// Returns the error code.
pub fn code(&self) -> Option<&str> {
self.code.as_deref()
}
/// Returns the error message.
pub fn message(&self) -> Option<&str> {
self.message.as_deref()
}
/// Returns the request ID the erro... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 5f4378d3e820cebbb6b7e7413d4592c7d5441559 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5f4378d3e820cebbb6b7e7413d4592c7d5441559/sdk/aws-smithy-types/src/lib.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/lib.rs:7 | impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut fmt = f.debug_struct("Error");
if let Some(code) = &self.code {
fmt.field("code", code);
}
if let Some(message) = &self.message {
fmt.field("mess... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/lib.rs | Apache-2.0 | 5f4378d3e820cebbb6b7e7413d4592c7d5441559 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5f4378d3e820cebbb6b7e7413d4592c7d5441559/sdk/aws-smithy-types/src/lib.rs | 241 | 262 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/number.rs:1 | /*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
//! A number type that implements Javascript / JSON semantics.
use crate::error::{TryFromNumberError, TryFromNumberErrorKind};
#[cfg(all(
aws_sdk_unstable,
any(feature = "serde-serialize", featu... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/number.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/number.rs | 1 | 60 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/number.rs:2 | /* ANCHOR_END: document */
impl Number {
/// Converts to an `f64` lossily.
/// Use `Number::try_from` to make the conversion only if it is not lossy.
pub fn to_f64_lossy(self) -> f64 {
match self {
Number::PosInt(v) => v as f64,
Number::NegInt(v) => v as f64,
Num... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/number.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/number.rs | 41 | 100 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/number.rs:3 | }
}
}
};
($typ:ident) => {
to_unsigned_integer_converter!($typ, stringify!($typ));
};
}
macro_rules! to_signed_integer_converter {
($typ:ident, $styp:expr) => {
#[doc = "Converts to a `"]
#[doc = $styp]
#[doc = "`. This conversion fails if it is loss... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/number.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/number.rs | 81 | 140 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/number.rs:4 | }
}};
}
/// Converts to a `u64`. The conversion fails if it is lossy.
impl TryFrom<Number> for u64 {
type Error = TryFromNumberError;
fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
Number::PosInt(v) => Ok(v),
Number::NegInt(v) => {
E... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/number.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/number.rs | 121 | 180 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/number.rs:5 | fn try_from(value: Number) -> Result<Self, Self::Error> {
match value {
// Integers can only be represented with full precision in a float if they fit in the
// significand, which is 24 bits in `f32` and 53 bits in `f64`.
// https://github.com/rust-lang/rust/blob/58f11791af4f... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/number.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/number.rs | 161 | 220 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/number.rs:6 | Ok(v as Self)
} else {
Err(TryFromNumberErrorKind::I64ToFloatLossyConversion(v).into())
}
}
Number::Float(v) => Err(TryFromNumberErrorKind::F64ToF32LossyConversion(v).into()),
}
}
}
#[cfg(test)]
mod test {
use super::Number;
... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/number.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/number.rs | 201 | 260 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/number.rs:7 | }
assert_eq!($typ::try_from(Number::Float(25.0)).unwrap(), 25);
};
}
#[test]
fn to_u64() {
assert_eq!(u64::try_from(Number::PosInt(69u64)).unwrap(), 69u64);
assert!(matches!(
u64::try_from(Number::NegInt(-1i64)).unwrap_err(),
TryFromNumberError {... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/number.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/number.rs | 241 | 300 |
awslabs/aws-sdk-rust:sdk/aws-smithy-types/src/number.rs:8 | macro_rules! to_signed_converter_tests {
($typ:ident) => {
assert_eq!($typ::try_from(Number::PosInt(69u64)).unwrap(), 69);
assert_eq!($typ::try_from(Number::NegInt(-69i64)).unwrap(), -69);
assert!(matches!(
$typ::try_from(Number::PosInt(($typ::MAX as u64) + 1... | rust | rust | macro-heavy | awslabs/aws-sdk-rust | sdk/aws-smithy-types/src/number.rs | Apache-2.0 | 5e17b3723799bff475dc95cdcca40c9d54602f18 | github | sdk | https://github.com/awslabs/aws-sdk-rust/blob/5e17b3723799bff475dc95cdcca40c9d54602f18/sdk/aws-smithy-types/src/number.rs | 281 | 340 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.