ITADN

Don't abuse `unsafe` for "dangerous" methods

#103Closedteohhanhui 创建于 2025-10-07
T
teohhanhuicommented
Instead, use a pattern such as https://docs.rs/rustls/latest/rustls/struct.ConfigBuilder.html#method.dangerous Also see discussion e.g. https://www.reddit.com/r/rust/comments/1liohyr/thoughts_on_using_unsafe_for_highly_destructive/ ## Use case My crate is `forbid(unsafe_code)` and I'm writing a test. Currently, [`ClientBuilder::with_no_certificate_verification`](https://docs.rs/web-transport-quinn/latest/web_transport_quinn/struct.ClientBuilder.html#method.with_no_certificate_verification) is marked as an `unsafe fn`, so I'd have to use an `unsafe` block, e.g. https://github.com/kixelated/web-transport/blob/838291f87fe82018471a33d553da42246028a231/web-transport-quinn/examples/echo-client.rs#L36-L37 ## Alternatives considered Call [`ClientBuilder::with_server_certificates`](https://docs.rs/web-transport-quinn/latest/web_transport_quinn/struct.ClientBuilder.html#method.with_server_certificates) with a self-signed root CA.
关闭于 2025-10-17 0 条评论