Getting Destroyed by Lifetime related Errors

A little background, I am attempting to create an application that works with AWS SDK for Rust. To reduce total code, I will provide just the trouble areas right now, and I just want to know what is happening as I seem to get to this point every time, regardless of what I implement or change in the type descriptions.

I use user-input to create the following structure:

    #[derive(Debug)]
    pub struct LogClient {
        pub environment_name: String,
        pub region_id: String,
        pub bucket_name: String,
        pub from_timestamp_epoch: i64,
        pub to_timestamp_epoch: i64,
        pub prefix: String,
    }

I then attempt to create a aws_sdk_mwaa client, with the following code:

pub async fn validate_environment_name(self) -> Result<GetEnvironmentFluentBuilder, aws_sdk_mwaa::Error> {
            println!("Checking environment's existence in region provided.");
            let config = aws_config::defaults(BehaviorVersion::v2023_11_09())
                .region(self.region_id)
                .load()
                .await;
            let client = mwaa::Client::new(&config);
            let response = client.get_environment()
                .name(self.environment_name);
            Ok(response)
        }

This continues to throw an error regarding requiring 'static lifetime in order to work.

error[E0277]: the trait bound `&std::string::String: aws_config::meta::region::ProvideRegion` is not satisfied
   --> src/lib.rs:48:25
    |
48  |                 .region(self.region_id)
    |                  ------ ^^^^^^^^^^^^^^ the trait `aws_config::meta::region::ProvideRegion` is not implemented for `&std::string::String`
    |                  |
    |                  required by a bound introduced by this call
    |
    = help: the trait `aws_config::meta::region::ProvideRegion` is implemented for `&'static str`
note: required by a bound in `ConfigLoader::region`
   --> /Users/anpmcken/.cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-config-1.1.2/src/lib.rs:292:46
    |
292 |         pub fn region(mut self, region: impl ProvideRegion + 'static) -> Self {
    |                                              ^^^^^^^^^^^^^ required by this bound in `ConfigLoader::region`

My initial assumptions, regardless of my efforts, suggests that the problem starts immediately, when I declare my structure. But how else do you store string data from users? Is attempting to use String just not a good idea in general because of the lifetime restrictions?

Like I said previously, this isn't the first time I have got into this situation, and I usually get so discouraged that I stop using Rust for a few months XD. But I really just want to understand this, fundamentally, so that I can code through it from the beginning. Since I keep coming back with new code, that ultimately will end up here just feels like I need some good documentation or explanation on this to grasp it.

Any help what-so-ever would be greatly appreciated, as well as any good documentation out there that can explain the issue behind this in "laymans" terms.

Judging by the API in question (in particular the relevant trait implementations of ProvideRegion), String doesn’t seem to be supported directly for some reason. Perhaps try .region(aws_config::Region::new(self.region_id)).


I’m not sure why the error speaks of &String instead of String, given the type of the field you quoted was String. In case LogClient happens not to be the correct struct and where the error appears self.region_id is of type &String, then you might need to clone the String as in “.region(aws_config::Region::new(self.region_id.clone()))”.

You have to construct a Region from your string:

.region(Region::new(self.region_id.clone()))

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.