Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upIssue in using infer_schema! #309
Comments
This comment has been minimized.
|
The recommended approach is to use the dotenv! macro provided by the doenv crate.
|
This comment has been minimized.
inxi-pc
commented
Apr 27, 2016
|
@mfpiccolo hi, thanks..but could i use other way like my mentioned, because my .env file is using in project, and format is not compatible dotenv.. |
This comment has been minimized.
|
Both infer_schema! and dotenv! are compiler plugins which are expanding out code. This means that dotenv! will expand out to be a string literal at compile time. You can use env! in the standard library but you will have to get the the env set during compile time. |
This comment has been minimized.
inxi-pc
commented
Apr 27, 2016
|
@mfpiccolo you means my mentioned way is in run time, so we cant use this. Because the macro! only can accept the string literal? infer_schema!(env::var("DATABASE_URL").expect("DATABASE_URL must be set"));The way in complier time is a little not friendly.. i have a matter, dotenv! also get content from file, if we can set a string literal param for dotenv!? |
This comment has been minimized.
|
I mean you could just pass the database url to infer_schema!
|
This comment has been minimized.
|
Seems like what you really are looking for is a way to load ENV from another file through the dotenv! plugin. You may want to open an issue here if that is the case https://github.com/slapresta/rust-dotenv. |
This comment has been minimized.
|
You can pass a string literal, or compile time macro that generates a string literal (like
That's the tradeoff of a compiled language. We can't just evaluate arbitrary Rust code. |
inxi-pc commentedApr 27, 2016
Hi,
When i flow the guide book to learn diesel using, i create schema.rs file and add the
content :
Because my project .env file has been used, and it is toml format, not be compatible.
So i create a new file named env.diesel, and in my main.rs file, add this content:
But i got the comlier error:
Could you help me? thanks very much.