6 ms·
That only applies when dynamic dispatch is involved and the linker can't trace the calls. For direct calls and generics(which idiomatic Rust code tends to prefe
by vvanders 1y ago
That only applies when dynamic dispatch is involved and the linker can't trace the calls. For direct calls and generics(which idiomatic Rust code tends to prefer over dyn traits) LTO will prune extensively.
- rafram 1y agolet uri = get_uri_from_stdin(); networking_library::make_request(uri); How is the compiler supposed to prune that?
- f_devd 1y agolet 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.
- saagarjha 1y agoNo, this wouldn't work. The type of the request needs to be dynamic because the user can pass in any URI.
- devnullbrain 1y agoThen they can also pass in an erroneous URI. You still need some way to deal with the ones you're not accepting.
- whstl 1y agoSo what happens if the user passes an url containing ftp:// or even https:// https:// to stdin? Or is this an HTTP only library?
- f_devd 1y agoDepends 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.
- tmtvl 1y agoIf 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;
- okanat 1y agoSee, 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.
- deleted 1y ago[deleted]