News for hackers. Stuff that matters.
Re:Rust Dependencies Scare Me by f_devd on Friday May 09, 2025 @08:41PM (#43942298)

  let uri: Uri<HTTP> = get_uri_from_stdin().parse()?; 
If the library is made in a modular way this is how it would typically be done. The `HTTP` may be inferred by calls further along in the function.
Re:Rust Dependencies Scare Me by saagarjha on Saturday May 10, 2025 @03:51AM (#43943944)
No, this wouldn't work. The type of the request needs to be dynamic because the user can pass in any URI.
Re:Rust Dependencies Scare Me by devnullbrain on Saturday May 10, 2025 @09:13PM (#43950404)
Then they can also pass in an erroneous URI. You still need some way to deal with the ones you're not accepting.
Re:Rust Dependencies Scare Me by whstl on Saturday May 10, 2025 @06:55AM (#43944691)
So what happens if the user passes an url containing ftp:// or even https:// to stdin? Or is this an HTTP only library?
Re:Rust Dependencies Scare Me by f_devd on Saturday May 10, 2025 @07:01AM (#43944708)
Depends on what is desired, in this case it would fail (through the `?`), and report it's not a valid HTTP Uri. This would be for a generic parsing library that allows for multiple schemes to be parsed each with their own parsing rules.

If you want to mix schemes you would need to be able to handle all schemes; you can either go through all variations (through the same generics) you want to test or just just accept that you need a full URI parser and lose the generic.

Re:Rust Dependencies Scare Me by tmtvl on Saturday May 10, 2025 @10:39AM (#43946007)
If you want to mix schemes you should just mix schemes.

  let uri: Uri<FTP or HTTP or HTTPS> = parse_uri(get_uri_from_stdin()) or fail;
Re:Rust Dependencies Scare Me by okanat on Saturday May 10, 2025 @07:16AM (#43944773)
See, the trait system in Rust actually forced you to discover your requirements at a very core level. It is not a bug, but a feature. If you need HTTPS, then you need to include the code to do HTTPS of course. Then LTO shouldn't remove it.

If your library cannot parse FTP, either you enable that feature, add that feature, or use a different library.