| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 2 | |
| 3 | use percent_encodingrust-analyzer cargo percent-encoding 2.3.2 crate/::{percent_decode_strrust-analyzer cargo percent-encoding 2.3.2 percent_decode_str()., utf8_percent_encoderust-analyzer cargo percent-encoding 2.3.2 utf8_percent_encode()., NON_ALPHANUMERICrust-analyzer cargo percent-encoding 2.3.2 ascii_set/NON_ALPHANUMERIC.}; |
| 4 | use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::Urlrust-analyzer cargo url 2.5.8 Url#; |
| 5 | |
| 6 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::{errorrust-analyzer cargo sqlx-mysql 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#, MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#}; |
| 7 | |
| 8 | use superrust-analyzer cargo sqlx-mysql 0.8.3 options/::MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#; |
| 9 | |
| 10 | impl MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions# { |
| 11 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) fn parse_from_urlrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions]parse_from_url().(url: &Urlrust-analyzer cargo url 2.5.8 Url#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 12 | let mut options = Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions]::newrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]new().(); |
| 13 | |
| 14 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(host) = url.host_strrust-analyzer cargo url 2.5.8 impl#[Url]host_str().() { |
| 15 | options = options.hostrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]host().(host); |
| 16 | } |
| 17 | |
| 18 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(port) = url.portrust-analyzer cargo url 2.5.8 impl#[Url]port().() { |
| 19 | options = options.portrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]port().(port); |
| 20 | } |
| 21 | |
| 22 | let username = url.usernamerust-analyzer cargo url 2.5.8 impl#[Url]username().(); |
| 23 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().username.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 24 | options = options.usernamerust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]username().( |
| 25 | &percent_decode_strrust-analyzer cargo percent-encoding 2.3.2 percent_decode_str().(username) |
| 26 | .decode_utf8rust-analyzer cargo percent-encoding 2.3.2 impl#[`PercentDecode<'a>`]decode_utf8().() |
| 27 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::configrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]config().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(password) = url.passwordrust-analyzer cargo url 2.5.8 impl#[Url]password().() { |
| 32 | options = options.passwordrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]password().( |
| 33 | &percent_decode_strrust-analyzer cargo percent-encoding 2.3.2 percent_decode_str().(password) |
| 34 | .decode_utf8rust-analyzer cargo percent-encoding 2.3.2 impl#[`PercentDecode<'a>`]decode_utf8().() |
| 35 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::configrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]config().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | let path = url.pathrust-analyzer cargo url 2.5.8 impl#[Url]path().().trim_start_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_start_matches().('/'); |
| 40 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().path.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 41 | options = options.databaserust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]database().( |
| 42 | &percent_decode_strrust-analyzer cargo percent-encoding 2.3.2 percent_decode_str().(path) |
| 43 | .decode_utf8rust-analyzer cargo percent-encoding 2.3.2 impl#[`PercentDecode<'a>`]decode_utf8().() |
| 44 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::configrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]config().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | for (key, value) in url.query_pairsrust-analyzer cargo url 2.5.8 impl#[Url]query_pairs().().into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/impl#[I][IntoIterator]into_iter().() { |
| 49 | match &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().key { |
| 50 | "sslmode" | "ssl-mode" => { |
| 51 | options = options.ssl_moderust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]ssl_mode().(value.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::configrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]config().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 52 | } |
| 53 | |
| 54 | "sslca" | "ssl-ca" => { |
| 55 | options = options.ssl_carust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]ssl_ca().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().value); |
| 56 | } |
| 57 | |
| 58 | "charset" => { |
| 59 | options = options.charsetrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]charset().(&value); |
| 60 | } |
| 61 | |
| 62 | "collation" => { |
| 63 | options = options.collationrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]collation().(&value); |
| 64 | } |
| 65 | |
| 66 | "sslcert" | "ssl-cert" => options = options.ssl_client_certrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]ssl_client_cert().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().value), |
| 67 | |
| 68 | "sslkey" | "ssl-key" => options = options.ssl_client_keyrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]ssl_client_key().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().value), |
| 69 | |
| 70 | "statement-cache-capacity" => { |
| 71 | options = |
| 72 | options.statement_cache_capacityrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]statement_cache_capacity().(value.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::configrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]config().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 73 | } |
| 74 | |
| 75 | "socket" => { |
| 76 | options = options.socketrust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]socket().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().value); |
| 77 | } |
| 78 | |
| 79 | "timezone" | "time-zone" => { |
| 80 | options = options.timezonerust-analyzer cargo sqlx-mysql 0.8.3 options/impl#[MySqlConnectOptions]timezone().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 81 | } |
| 82 | |
| 83 | _ => {} |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(options) |
| 88 | } |
| 89 | |
| 90 | pub(craterust-analyzer cargo sqlx-mysql 0.8.3 crate/) fn build_urlrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions]build_url().(&self) -> Urlrust-analyzer cargo url 2.5.8 Url# { |
| 91 | let mut url = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 92 | "mysql://{}@{}:{}", |
| 93 | self.usernamerust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#username., self.hostrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#host., self.portrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#port. |
| 94 | )) |
| 95 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("BUG: generated un-parseable URL"); |
| 96 | |
| 97 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(password) = &self.passwordrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#password. { |
| 98 | let password = utf8_percent_encoderust-analyzer cargo percent-encoding 2.3.2 utf8_percent_encode().(password, NON_ALPHANUMERICrust-analyzer cargo percent-encoding 2.3.2 ascii_set/NON_ALPHANUMERIC.).to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 99 | let _ = url.set_passwordrust-analyzer cargo url 2.5.8 impl#[Url]set_password().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&password)); |
| 100 | } |
| 101 | |
| 102 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(database) = &self.databaserust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#database. { |
| 103 | url.set_pathrust-analyzer cargo url 2.5.8 impl#[Url]set_path().(database); |
| 104 | } |
| 105 | |
| 106 | let ssl_mode = match self.ssl_moderust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_mode. { |
| 107 | MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::Disabledrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#Disabled# => "DISABLED", |
| 108 | MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::Preferredrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#Preferred# => "PREFERRED", |
| 109 | MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::Requiredrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#Required# => "REQUIRED", |
| 110 | MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::VerifyCarust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#VerifyCa# => "VERIFY_CA", |
| 111 | MySqlSslModerust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#::VerifyIdentityrust-analyzer cargo sqlx-mysql 0.8.3 options/ssl_mode/MySqlSslMode#VerifyIdentity# => "VERIFY_IDENTITY", |
| 112 | }; |
| 113 | url.query_pairs_mutrust-analyzer cargo url 2.5.8 impl#[Url]query_pairs_mut().().append_pairrust-analyzer cargo form_urlencoded 1.2.2 impl#[`Serializer<'a, T>`]append_pair().("ssl-mode", ssl_mode); |
| 114 | |
| 115 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ssl_ca) = &self.ssl_carust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_ca. { |
| 116 | url.query_pairs_mutrust-analyzer cargo url 2.5.8 impl#[Url]query_pairs_mut().() |
| 117 | .append_pairrust-analyzer cargo form_urlencoded 1.2.2 impl#[`Serializer<'a, T>`]append_pair().("ssl-ca", &ssl_ca.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 118 | } |
| 119 | |
| 120 | url.query_pairs_mutrust-analyzer cargo url 2.5.8 impl#[Url]query_pairs_mut().().append_pairrust-analyzer cargo form_urlencoded 1.2.2 impl#[`Serializer<'a, T>`]append_pair().("charset", &self.charsetrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#charset.); |
| 121 | |
| 122 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(collation) = &self.collationrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#collation. { |
| 123 | url.query_pairs_mutrust-analyzer cargo url 2.5.8 impl#[Url]query_pairs_mut().().append_pairrust-analyzer cargo form_urlencoded 1.2.2 impl#[`Serializer<'a, T>`]append_pair().("charset", collation); |
| 124 | } |
| 125 | |
| 126 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ssl_client_cert) = &self.ssl_client_certrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_client_cert. { |
| 127 | url.query_pairs_mutrust-analyzer cargo url 2.5.8 impl#[Url]query_pairs_mut().() |
| 128 | .append_pairrust-analyzer cargo form_urlencoded 1.2.2 impl#[`Serializer<'a, T>`]append_pair().("ssl-cert", &ssl_client_cert.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 129 | } |
| 130 | |
| 131 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ssl_client_key) = &self.ssl_client_keyrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#ssl_client_key. { |
| 132 | url.query_pairs_mutrust-analyzer cargo url 2.5.8 impl#[Url]query_pairs_mut().() |
| 133 | .append_pairrust-analyzer cargo form_urlencoded 1.2.2 impl#[`Serializer<'a, T>`]append_pair().("ssl-key", &ssl_client_key.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 134 | } |
| 135 | |
| 136 | url.query_pairs_mutrust-analyzer cargo url 2.5.8 impl#[Url]query_pairs_mut().().append_pairrust-analyzer cargo form_urlencoded 1.2.2 impl#[`Serializer<'a, T>`]append_pair().( |
| 137 | "statement-cache-capacity", |
| 138 | &self.statement_cache_capacityrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#statement_cache_capacity..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 139 | ); |
| 140 | |
| 141 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(socket) = &self.socketrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#socket. { |
| 142 | url.query_pairs_mutrust-analyzer cargo url 2.5.8 impl#[Url]query_pairs_mut().() |
| 143 | .append_pairrust-analyzer cargo form_urlencoded 1.2.2 impl#[`Serializer<'a, T>`]append_pair().("socket", &socket.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_string_lossy().()); |
| 144 | } |
| 145 | |
| 146 | url |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions# { |
| 151 | type Errrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions][FromStr]Err# = Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 152 | |
| 153 | fn from_strrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions][FromStr], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 154 | let url: Urlrust-analyzer cargo url 2.5.8 Url# = s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::configrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]config().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 155 | Selfrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions][FromStr]::parse_from_urlrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions]parse_from_url().(&url) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 160 | fn it_parses_username_with_at_sign_correctlyrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/it_parses_username_with_at_sign_correctly().() { |
| 161 | let url = "mysql://user@hostname:password@hostname:5432/database"; |
| 162 | let opts = MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#::from_strrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions][FromStr]from_str().(url).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 163 | |
| 164 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("user@hostname", &opts.usernamerust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#username.); |
| 165 | } |
| 166 | |
| 167 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 168 | fn it_parses_password_with_non_ascii_chars_correctlyrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/it_parses_password_with_non_ascii_chars_correctly().() { |
| 169 | let url = "mysql://username:p@ssw0rd@hostname:5432/database"; |
| 170 | let opts = MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#::from_strrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions][FromStr]from_str().(url).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 171 | |
| 172 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("p@ssw0rd".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()), opts.passwordrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#password.); |
| 173 | } |
| 174 | |
| 175 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 176 | fn it_returns_the_parsed_urlrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/it_returns_the_parsed_url().() { |
| 177 | let url = "mysql://username:p@ssw0rd@hostname:3306/database"; |
| 178 | let opts = MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#::from_strrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions][FromStr]from_str().(url).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 179 | |
| 180 | let mut expected_url = Urlrust-analyzer cargo url 2.5.8 Url#::parserust-analyzer cargo url 2.5.8 impl#[Url]parse().(url).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 181 | // MySqlConnectOptions defaults |
| 182 | let query_string = "ssl-mode=PREFERRED&charset=utf8mb4&statement-cache-capacity=100"; |
| 183 | expected_url.set_queryrust-analyzer cargo url 2.5.8 impl#[Url]set_query().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(query_string)); |
| 184 | |
| 185 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected_url, opts.build_urlrust-analyzer cargo sqlx-mysql 0.8.3 options/parse/impl#[MySqlConnectOptions]build_url().()); |
| 186 | } |
| 187 | |
| 188 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 189 | fn it_parses_timezonerust-analyzer cargo sqlx-mysql 0.8.3 options/parse/it_parses_timezone().() { |
| 190 | let opts: MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions# = "mysql://user:password@hostname/database?timezone=%2B08:00" |
| 191 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 192 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 193 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opts.timezonerust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#timezone..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("+08:00")); |
| 194 | |
| 195 | let opts: MySqlConnectOptionsrust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions# = "mysql://user:password@hostname/database?time-zone=%2B08:00" |
| 196 | .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().() |
| 197 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 198 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(opts.timezonerust-analyzer cargo sqlx-mysql 0.8.3 options/MySqlConnectOptions#timezone..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("+08:00")); |
| 199 | } |