about summary refs log tree commit diff
path: root/src/libstd/net/addr.rs
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-1245/+0
2020-06-23Auto merge of #73007 - yoshuawuyts:socketaddr-from-string-u16, r=sfacklerbors-0/+8
impl ToSocketAddrs for (String, u16) This adds a convenience impl of `ToSocketAddrs for (String, u16)`. When authoring HTTP services it's common to take command line options for `host` and `port` and parse them into `String` and `u16` respectively. Consider the following program: ```rust #[derive(Debug, StructOpt)] struct Config { host: String, port: u16, } async fn main() -> io::Result<()> { let config = Config::from_args(); let stream = TcpStream::connect((&*config.host, config.port))?; // &* is not ideal // ... } ``` Networking is a pretty common starting point for people new to Rust, and seeing `&*` in basic examples can be confusing. Even as someone that has experience with networking in Rust I tend to forget that `String` can't be passed directly there. Instead with this patch we can omit the `&*` conversion and pass `host` directly: ```rust #[derive(Debug, StructOpt)] struct Config { host: String, port: u16, } async fn main() -> io::Result<()> { let config = Config::from_args(); let stream = TcpStream::connect((config.host, config.port))?; // no more conversions! // ... } ``` I think should be an easy and small ergonomics improvement for networking. Thanks!
2020-06-13Add test for comparing SocketAddr with inferred right-hand sideDavid Tolnay-0/+5
2020-06-12Revert heterogeneous SocketAddr PartialEq implsDavid Tolnay-40/+0
These lead to inference regressions (mostly in tests) in code that looks like: let socket = std::net::SocketAddrV4::new(std::net::Ipv4Addr::new(127, 0, 0, 1), 8080); assert_eq!(socket, "127.0.0.1:8080".parse().unwrap()); That compiles as of stable 1.44.0 but fails in beta with: error[E0284]: type annotations needed --> src/main.rs:3:41 | 3 | assert_eq!(socket, "127.0.0.1:8080".parse().unwrap()); | ^^^^^ cannot infer type for type parameter `F` declared on the associated function `parse` | = note: cannot satisfy `<_ as std::str::FromStr>::Err == _` help: consider specifying the type argument in the method call | 3 | assert_eq!(socket, "127.0.0.1:8080".parse::<F>().unwrap()); |
2020-06-05impl ToSocketAddrs for (String, u16)Yoshua Wuyts-0/+8
2020-05-29Clarify comment message & MAX_LENGTH constNathan West-3/+7
2020-05-29Added fast-path, testsNathan West-20/+54
2020-05-29`SocketAddr(V4|V6)?`::Display now correctly pads its contentNathan West-3/+27
IpAddr and friends pad when displaying; SocketAddr now does this as well
2020-05-24Fix testsHoe Hao Cheng-2/+2
2020-05-24Remove heterogeneous ordering for SocketAddrHoe Hao Cheng-55/+15
2020-05-16Implement PartialOrd and Ord for SocketAddr*Hoe Hao Cheng-1/+146
2020-03-20For issue 53957: revise unit tests to focus on underlying bug of 23076.Felix S. Klock II-4/+19
Namely, this version focuses on the end-to-end behavior that the attempt to create the UDP binding will fail, regardless of the semantics of how particular DNS servers handle junk inputs. (I spent some time trying to create a second more-focused test that would sidestep the DNS resolution, but this is not possible without more invasive changes to the internal infrastructure of `ToSocketAddrs` and what not. It is not worth it.)
2020-03-02Don't convert Results to Options just for matching.Matthias Krüger-1/+1
2020-01-08Use matches macro in libcore and libstdIgor Aleksanov-8/+2
2019-12-15make htons const fnLzu Tao-7/+7
2019-11-29Format libstd with rustfmtDavid Tolnay-35/+56
This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd *that are not involved in any currently open PR* to minimize merge conflicts. THe list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in outstanding_files, the relevant commands were: $ find src/libstd -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libstd. To confirm no funny business: $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference
2019-10-01Remove unneeded `fn main` blocks from docsLzu Tao-11/+6
2019-05-20Rollup merge of #60511 - taiki-e:libstd-intra-doc, r=Dylan-DPCMazdak Farrokhzad-0/+13
Fix intra-doc link resolution failure on re-exporting libstd Currently, re-exporting libstd items as below will [occur a lot of failures](https://gist.github.com/taiki-e/e33e0e8631ef47f65a74a3b69f456366). ```rust pub use std::*; ``` Until the underlying issue (#56922) fixed, we can fix that so they don't propagate to downstream crates. Related: https://github.com/rust-lang/rust/pull/56941 (That PR fixed failures that occur when re-exporting from libcore to libstd.) r? @QuietMisdreavus
2019-05-13Remove bitrig support from rustMarcel Hellwig-2/+2
2019-05-04Fix intra-doc link resolution failure on re-exporting libstdTaiki Endo-0/+13
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-5/+5
2019-03-25SGX target: fix std unit testsJethro Beekman-0/+6
2019-02-28libstd => 2018Taiki Endo-15/+15
2019-02-20Rollup merge of #58553 - scottmcm:more-ihle, r=Centrilkennytm-2/+2
Use more impl header lifetime elision Inspired by seeing explicit lifetimes on these two: - https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator - https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore. Most of the changes in here fall into two big categories: - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm). I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-17Use more impl header lifetime elisionScott McMurray-2/+2
There are two big categories of changes in here - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
2019-02-10libs: doc commentsAlexander Regueiro-1/+1
2019-02-10tests: doc commentsAlexander Regueiro-1/+1
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-1/+1
2018-12-06Refactor net::each_addr/lookup_host to forward error from resolveJethro Beekman-21/+7
2018-08-21Add doc for impl From for AddrSon-0/+8
2018-05-03Remove the deprecated std::net::{lookup_host,LookupHost}Josh Stone-3/+1
These are unstable, and were deprecated by #47510, since Rust 1.25. The internal `sys` implementations are still kept to support the call in the common `resolve_socket_addr`.
2018-03-24Add backticksPhlosioneer-2/+2
2018-03-20Remove StdioRaw doc additions, add backticksPhlosioneer-1/+1
2018-03-11Remove "and may change between Rust releases"Phlosioneer-3/+3
2018-03-11Document when types have OS-dependent sizesPhlosioneer-0/+9
As per issue #43601, types that can change size depending on the target operating system should say so in their documentation. I used this template when adding doc comments: The size of a(n) <name> struct may vary depending on the target operating system, and may change between Rust releases. For enums, I used "instance" instead of "struct".
2018-01-17Deprecate std::net::lookup_hostSteven Fackler-1/+4
We intended to do this quite a while ago but it snuck through.
2017-11-21Fix a typo in ToSocketAddrs documentationAlexey Orlenko-1/+1
Fix a typo in ToSocketAddrs documentation: s/ToSocketsAddr/ToSocketAddrs
2017-08-30Fix typo in doc `ToSocketAddrs` example.Corey Farwell-1/+1
2017-08-28Rewrite `std::net::ToSocketAddrs` doc examples.Corey Farwell-22/+66
in particular: * show how to create an iterator that yields multiple socket addresses * show more failing scenarios
2017-03-27Addressed requested changes for PR #40838lukaramu-18/+12
* Fixed spelling ToSocketAddr -> ToSocketAddrs in module docs (which also fixes a link) * Added missing "when" before "interacting" in module docs * Changed SocketAddr's top-level docs to explicitly state what socket addresses consist of, making them more consistent with SocketAddrV4's and SocketAddrV6's docs * Changed "in C" -> "in C's `netinet/in.h`" * Changed wording in is_ipv4/is_ipv6 methods to ", `false` otherwise" * Add missing closing ` ``` ` in Ipv6Addr's examples * Removed "Errors" section in ToSocketAddrs' to_socket_addrs method as it was rather redundant
2017-03-26Added examples to std::net::{SocketAddr, SocketAddrV4, SocketAddrV6} docslukaramu-0/+36
2017-03-26Expanded and added links to std::net::{SocketAddr,SocketAddrV4,SocketAddrV6} ↵lukaramu-25/+89
docs Part of #29363 Changed summary sentences of SocketAddr and IpAddr for consistency Linked to SocketAddrV4 and SocketAddrV6 from SocketAddr, moving explaination there Expanded top-level docs for SocketAddrV4 and SocketAddrV6, linking to some relevant IETF RFCs, and linking back to SocketAddr Changed some of the method summaries to third person as per RFC 1574; added links to IETF RFCs where appropriate
2017-03-26Removed link in std::net::ToSocketAddr's summary sentencelukaramu-3/+1
Relative links in trait methods don't resolve in e.g. std/primitive.tuple.html :(
2017-03-26Added links throughout std::net::ToSocketAddrs' documentationlukaramu-17/+35
Part of #29363 In the section about the default implementations of ToSocketAddrs, I moved the bulletpoint of SocketAddrV4 & SocketAddrV6 to the one stating that SocketAddr is constructed trivially, as this is what's actually the case
2017-01-31add From<(I, u16)> for SocketAddr where I: Into<IpAddr>Sean McArthur-0/+7
2017-01-25std: Stabilize APIs for the 1.16.0 releaseAlex Crichton-6/+2
This commit applies the stabilization/deprecations of the 1.16.0 release, as tracked by the rust-lang/rust issue tracker and the final-comment-period tag. The following APIs were stabilized: * `VecDeque::truncate` * `VecDeque::resize` * `String::insert_str` * `Duration::checked_{add,sub,div,mul}` * `str::replacen` * `SocketAddr::is_ipv{4,6}` * `IpAddr::is_ipv{4,6}` * `str::repeat` * `Vec::dedup_by` * `Vec::dedup_by_key` * `Result::unwrap_or_default` * `<*const T>::wrapping_offset` * `<*mut T>::wrapping_offset` * `CommandExt::creation_flags` (on Windows) * `File::set_permissions` * `String::split_off` The following APIs were deprecated * `EnumSet` - replaced with other ecosystem abstractions, long since unstable Closes #27788 Closes #35553 Closes #35774 Closes #36436 Closes #36949 Closes #37079 Closes #37087 Closes #37516 Closes #37827 Closes #37916 Closes #37966 Closes #38080
2017-01-13impl ToSocketAddrs for StringBrian Campbell-0/+20
`ToSocketAddrs` is implemented for a number of different types, including `(IpAddr, u16)`, `&str`, and various others, for the convenience of being able to run things like `TcpListener::bind("10.11.12.13:1415")`. However, because this is a generic parameter with a trait bound, if you have a `String` you cannot pass it in, either directly as `TcpListener::bind(string)`, or the `TcpListener::bind(&string)` as you might expect due to deref coercion; you have to use `TcpListener::bind(&*string)`, which is noisy and hard to discover (though #39029 suggests better error messages to make it more discoverable). Rather than making people stumble over this, just implement `ToSocketAddrs` for `String`.
2016-12-25Impl From<inner> for IpAddr and SocketAddr.Yamakaky-0/+14
Fixes https://github.com/rust-lang/rfcs/issues/1816.
2016-11-26Rollup merge of #37962 - GuillaumeGomez:socket-v6, r=frewsxcvSeo Sanghyeon-0/+84
Add missing examples to SocketAddrV6 r? @steveklabnik cc @frewsxcv