@@ -909,6 +909,9 @@ impl Url {
909
909
910
910
/// Return the port number for this URL, if any.
911
911
///
912
+ /// Note that default port numbers are never reflected by the serialization,
913
+ /// use the `port_or_known_default()` method if you want a default port number returned.
914
+ ///
912
915
/// # Examples
913
916
///
914
917
/// ```
@@ -919,6 +922,9 @@ impl Url {
919
922
/// let url = Url::parse("https://example.com")?;
920
923
/// assert_eq!(url.port(), None);
921
924
///
925
+ /// let url = Url::parse("https://example.com:443/")?;
926
+ /// assert_eq!(url.port(), None);
927
+ ///
922
928
/// let url = Url::parse("ssh://example.com:22")?;
923
929
/// assert_eq!(url.port(), Some(22));
924
930
/// # Ok(())
@@ -1383,6 +1389,8 @@ impl Url {
1383
1389
1384
1390
/// Change this URL’s port number.
1385
1391
///
1392
+ /// Note that default port numbers are not reflected in the serialization.
1393
+ ///
1386
1394
/// If this URL is cannot-be-a-base, does not have a host, or has the `file` scheme;
1387
1395
/// do nothing and return `Err`.
1388
1396
///
@@ -1405,6 +1413,22 @@ impl Url {
1405
1413
/// # run().unwrap();
1406
1414
/// ```
1407
1415
///
1416
+ /// Known default port numbers are not reflected:
1417
+ ///
1418
+ /// ```rust
1419
+ /// use url::Url;
1420
+ /// # use std::error::Error;
1421
+ ///
1422
+ /// # fn run() -> Result<(), Box<Error>> {
1423
+ /// let mut url = Url::parse("https://example.org/")?;
1424
+ ///
1425
+ /// url.set_port(Some(443)).map_err(|_| "cannot be base")?;
1426
+ /// assert!(url.port().is_none());
1427
+ /// # Ok(())
1428
+ /// # }
1429
+ /// # run().unwrap();
1430
+ /// ```
1431
+ ///
1408
1432
/// Cannot set port for cannot-be-a-base URLs:
1409
1433
///
1410
1434
/// ```
0 commit comments