How a create struct from environment variable?

Hi everyone!. I newbie to rust. I want to create a DatabaseConfig struct from the environment variable.

  1. I think properties of the struct never change I choose &str over String.

  2. But I have trouble with lifetime, I try to clone but it doesn't work.

I don't know have appropriate way to construct my struct, please give me suggestions :slight_smile:

Cloning a reference doesn't do anything; a reference is just a compile-time checked pointer, so clonig it is a trivial bitwise copy, and it doesn't result in a clone of the underlying data. (Even without considering this: you can't change the type of a value by cloning it, since Clone::clone() returns Self, ie. the identical type.)

You should probably put a String in your struct instead.

1 Like

Awesome, Thank you for your response. :laughing:

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.