Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate regex;
- use regex::Regex;
- #[derive(Debug)]
- struct Deets {
- name: String,
- host: String,
- password: String,
- user: String,
- }
- fn main() {
- let re =
- Regex::new("postgres://(?P<user>.+):(?P<password>.+)@(?P<host>.+)/(?P<name>.+)").unwrap();
- let creds: Deets = {
- let cap = re.captures("postgres://user:k\")Tk6]2aLMH@db-pool.laika.com/database_name")
- .unwrap();
- Deets {
- user: cap[1].into(),
- password: cap[2].into(),
- host: cap[3].into(),
- name: cap[4].into(),
- }
- };
- println!("{:?}", &creds);
- // assert!(issue_list_url.scheme() == "postgres");
- // assert!(issue_list_url.username() == "user");
- // assert_eq!(issue_list_url.password(), Some("k\")Tk6]2aLMH"));
- // assert_eq!(issue_list_url.host_str(), Some("db-pool.laika.com"));
- // assert!(issue_list_url.path() == "/database_name");
- // assert!(!issue_list_url.cannot_be_a_base());
- }
Add Comment
Please, Sign In to add comment