impl ToSocketAddrs for (String, u16) by yoshuawuyts · Pull Request #73007 · rust-lang/rust (original) (raw)
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation29 Commits1 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
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:
#[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:
#[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!
(rust_highfive has picked a reviewer for you, use r? to override)
@@ -1000,6 +1000,14 @@ impl ToSocketAddrs for (&str, u16) { |
---|
} |
} |
#[unstable(feature = "string_u16_to_socket_addrs", issue = "73006")] |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trait implementations are always stable.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I didn't realize! — what should this be marked with instead? #[stable()]
with the next major?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep - 1.46.0 specifically.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does these kind of change even needs a FCP? It looks minor but worthy enough to have a release note for it.
sfackler added the T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
label
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
🔔 This is now entering its final comment period, as per the review above. 🔔
📌 Commit 2764e54 has been approved by sfackler
bors added S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request
…u16, r=sfackler
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:
#[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:
#[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!
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request
…u16, r=sfackler
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:
#[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:
#[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!
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request
…u16, r=sfackler
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:
#[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:
#[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!
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request
…u16, r=sfackler
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:
#[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:
#[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!
RalfJung added a commit to RalfJung/rust that referenced this pull request
…u16, r=sfackler
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:
#[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:
#[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!
bors added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
labels
So it really was this one. I have no idea how that is possible...
I also have no idea how to fix or even proceed here. Does anyone have a clue what the right steps are to take? 😅
My guess is this is changing the instantiation of something somewhere which is somehow revealing a bug in the windows implementation of something in rustc, logic which only works if a usize is 64 bits. Searching the error reveals that this assertion only appears in the align method of rustc's DroplessArena.
Someone needs to debug this failure more, probably the first step would be having a 32 bit Windows system to reproduce it on.
The final comment period, with a disposition to merge, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
The RFC will be merged soon.
rfcbot removed the final-comment-period
In the final comment period and will be merged soon unless new substantive objections are raised.
label
Manishearth added a commit to Manishearth/rust that referenced this pull request
Check for overflow in DroplessArena and align returned memory
- Check for overflow when calculating the slice start & end position.
- Align the pointer obtained from the allocator, ensuring that it satisfies user requested alignment (the allocator is only asked for layout compatible with u8 slice).
- Remove an incorrect assertion from DroplessArena::align.
- Avoid forming references to an uninitialized memory in DroplessArena.
Helps with rust-lang#73007, rust-lang#72624.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request
Check for overflow in DroplessArena and align returned memory
- Check for overflow when calculating the slice start & end position.
- Align the pointer obtained from the allocator, ensuring that it satisfies user requested alignment (the allocator is only asked for layout compatible with u8 slice).
- Remove an incorrect assertion from DroplessArena::align.
- Avoid forming references to an uninitialized memory in DroplessArena.
Helps with rust-lang#73007, rust-lang#72624.
@bors r-
This failed CI since it was r+'d, unsure why homu thinks it's still in the queue. Feel free to r+ again once it's expected to pass.
bors added S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
This should be fine to r+ again.
@tmiasko i'm confused, what has changed that would fix the failure that was occurring earlier?
📌 Commit 2764e54 has been approved by sfackler
bors added S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request
according to various people on tech-pkg@, there are no problems with the Firefox build
Version 1.46.0 (2020-08-27)
Language
if
,match
, andloop
expressions can now be used in const functions.- Additionally you are now also able to coerce and cast to slices (
&[T]
) in const functions. - The
#[track_caller]
attribute can now be added to functions to use the function's caller's location information for panic messages. - Recursively indexing into tuples no longer needs parentheses. E.g.
x.0.0
over(x.0).0
. mem::transmute
can now be used in static and constants. Note You currently can't usemem::transmute
in constant functions.
Compiler
- You can now use the
cdylib
target on Apple iOS and tvOS platforms. - Enabled static "Position Independent Executables" by default
for
x86_64-unknown-linux-musl
.
Libraries
mem::forget
is now aconst fn
.String
now implementsFrom<char>
.- The
leading_ones
, andtrailing_ones
methods have been stabilised for all integer types. vec::IntoIter<T>
now implementsAsRef<[T]>
.- All non-zero integer types (
NonZeroU8
) now implementTryFrom
for their zero-able equivalent (e.g.TryFrom<u8>
). &[T]
and&mut [T]
now implementPartialEq<Vec<T>>
.(String, u16)
now implementsToSocketAddrs
.vec::Drain<'_, T>
now implementsAsRef<[T]>
.
Stabilized APIs
Cargo
Added a number of new environment variables that are now available when compiling your crate.
CARGO_BIN_NAME
andCARGO_CRATE_NAME
Providing the name of the specific binary being compiled and the name of the crate.CARGO_PKG_LICENSE
The license from the manifest of the package.CARGO_PKG_LICENSE_FILE
The path to the license file.
Compatibility Notes
- The target configuration option
abi_blacklist
has been renamed tounsupported_abis
. The old name will still continue to work. - Rustc will now warn if you cast a C-like enum that implements
Drop
. This was previously accepted but will become a hard error in a future release. - Rustc will fail to compile if you have a struct with
#[repr(i128)]
or#[repr(u128)]
. This representation is currently only allowed onenum
s. - Tokens passed to
macro_rules!
are now always captured. This helps ensure that spans have the correct information, and may cause breakage if you were relying on receiving spans with dummy information. - The InnoSetup installer for Windows is no longer available. This was a legacy installer that was replaced by a MSI installer a few years ago but was still being built.
{f32, f64}::asinh
now returns the correct values for negative numbers.- Rustc will no longer accept overlapping trait implementations that only differ in how the lifetime was bound.
- Rustc now correctly relates the lifetime of an existential associated
type. This fixes some edge cases where
rustc
would erroneously allow you to pass a shorter lifetime than expected. - Rustc now dynamically links to
libz
(also calledzlib
) on Linux. The library will need to be installed forrustc
to work, even though we expect it to be already available on most systems. - Tests annotated with
#[should_panic]
are broken on ARMv7 while running under QEMU. - Pretty printing of some tokens in procedural macros changed. The exact output returned by rustc's pretty printing is an unstable implementation detail: we recommend any macro relying on it to switch to a more robust parsing system.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request
Pkgsrc changes:
- Portability patches for Illumos have been intregrated upstream, so are no longer needed in pkgsrc.
- Adjust one other patch, and update vendor/libc cargo checksum.
Upstream changes:
Version 1.46.0 (2020-08-27)
Language
- [
if
,match
, andloop
expressions can now be used in const functions.] 72437 - Additionally you are now also able to coerce and cast to slices (
&[T]
) in const functions. - The
#[track_caller]
attribute can now be added to functions to use the function's caller's location information for panic messages. - Recursively indexing into tuples no longer needs parentheses. E.g.
x.0.0
over(x.0).0
. mem::transmute
can now be used in static and constants. Note You currently can't usemem::transmute
in constant functions.
Compiler
- You can now use the
cdylib
target on Apple iOS and tvOS platforms. - Enabled static "Position Independent Executables" by default
for
x86_64-unknown-linux-musl
.
Libraries
mem::forget
is now aconst fn
.String
now implementsFrom<char>
.- The
leading_ones
, andtrailing_ones
methods have been stabilised for all integer types. vec::IntoIter<T>
now implementsAsRef<[T]>
.- All non-zero integer types (
NonZeroU8
) now implementTryFrom
for their zero-able equivalent (e.g.TryFrom<u8>
). &[T]
and&mut [T]
now implementPartialEq<Vec<T>>
.(String, u16)
now implementsToSocketAddrs
.vec::Drain<'_, T>
now implementsAsRef<[T]>
.
Stabilized APIs
Cargo
Added a number of new environment variables that are now available when compiling your crate.
CARGO_BIN_NAME
andCARGO_CRATE_NAME
Providing the name of the specific binary being compiled and the name of the crate.CARGO_PKG_LICENSE
The license from the manifest of the package.CARGO_PKG_LICENSE_FILE
The path to the license file.
Compatibility Notes
- The target configuration option
abi_blacklist
has been renamed tounsupported_abis
. The old name will still continue to work. - Rustc will now warn if you have a C-like enum that implements
Drop
. This was previously accepted but will become a hard error in a future release. - Rustc will fail to compile if you have a struct with
#[repr(i128)]
or#[repr(u128)]
. This representation is currently only allowed onenum
s. - Tokens passed to
macro_rules!
are now always captured. This helps ensure that spans have the correct information, and may cause breakage if you were relying on receiving spans with dummy information. - The InnoSetup installer for Windows is no longer available. This was a legacy installer that was replaced by a MSI installer a few years ago but was still being built.
- [
{f32, f64}::asinh
now returns the correct values for negative numbers.] 72486 - Rustc will no longer accept overlapping trait implementations that only differ in how the lifetime was bound.
- Rustc now correctly relates the lifetime of an existential associated
type. This fixes some edge cases where
rustc
would erroneously allow you to pass a shorter lifetime than expected. - Rustc now dynamically links to
libz
(also calledzlib
) on Linux. The library will need to be installed forrustc
to work, even though we expect it to be already available on most systems. - Tests annotated with
#[should_panic]
are broken on ARMv7 while running under QEMU. - Pretty printing of some tokens in procedural macros changed. The exact output returned by rustc's pretty printing is an unstable implementation detail: we recommend any macro relying on it to switch to a more robust parsing system.