aws_sdk_s3/endpoint_lib/
diagnostic.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/*
3 *  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *  SPDX-License-Identifier: Apache-2.0
5 */
6
7use std::error::Error;
8
9/// Diagnostic collector for endpoint resolution
10///
11/// Endpoint functions return `Option<T>`—to enable diagnostic information to flow, we capture the
12/// last error that occurred.
13#[derive(Debug, Default)]
14pub(crate) struct DiagnosticCollector {
15    last_error: Option<Box<dyn Error + Send + Sync>>,
16}
17
18impl DiagnosticCollector {
19    #[allow(unused)]
20    /// Report an error to the collector
21    pub(crate) fn report_error(&mut self, err: impl Into<Box<dyn Error + Send + Sync>>) {
22        self.last_error = Some(err.into());
23    }
24
25    #[allow(unused)]
26    /// Capture a result, returning Some(t) when the input was `Ok` and `None` otherwise
27    pub(crate) fn capture<T, E: Into<Box<dyn Error + Send + Sync>>>(&mut self, err: Result<T, E>) -> Option<T> {
28        match err {
29            Ok(res) => Some(res),
30            Err(e) => {
31                self.report_error(e);
32                None
33            }
34        }
35    }
36
37    pub(crate) fn take_last_error(&mut self) -> Option<Box<dyn Error + Send + Sync>> {
38        self.last_error.take()
39    }
40
41    /// Create a new diagnostic collector
42    pub(crate) fn new() -> Self {
43        Self { last_error: None }
44    }
45}