Read and parse MySQL's .mylogin.cnf file.
Add myloginrs to Cargo.toml:
toml
[dependencies]
myloginrs = "0.1"
To get a HashMap of login info for "client" just use the parse function:
```rust let filepath = PathBuf::from( "tests/testmylogin.cnf", );
let clientinfo = myloginrs::parse("client", Some(&filepath)); ```
Then you can use that HashMap with an OptsBuilder or other structs
from the mysql:
```rust let opts = OptsBuilder::new() .iporhostname(Some(&clientinfo["host"])) .tcpport(u16::fromstrradix(&clientinfo["port"], 10)?) .user(Some(&clientinfo["user"])) .pass(Some(&client_info["password"]));
let _conn = Conn::new(opts); ```
Starting with mysql 20.1.0, you can do the even simpler:
rust
let opts = OptsBuilder::new().from_hash_map(&client_info).unwrap();
let _conn = Conn::new(opts);
If you would rather get a String that contains the whole file, use read:
```rust let mylogin_plaintext = myloginrs::read(None);
println!("{}", mylogin_plaintext); ```
This second example passes None as the path to use the
default .mylogin.cnf location (%APPDATA%\MySQL\.mylogin.cnf on windows or
~/.mylogin.cnf on everything else).
Thanks to * github.com/PyMySQL and * github.com/ocelot-inc for doing all the hard work and from whom I port.
Licensed under either of
at your option.
Pull requests welcome. :)
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.