我得到的错误:
error[E0433]: failed to resolve: could not find `openssl` in `backend`
--> ...\src\...\swagger-0.12.1\src\connector.rs:41:34
|
41 | native_tls::backend::openssl::TlsConnectorBuilderExt::from_openssl(ssl);
| ^^^^^^^ could not find `openssl` in `backend`
error[E0433]: failed to resolve: could not find `openssl` in `backend`
--> ...\swagger-0.12.1\src\connector.rs:85:34
|
85 | native_tls::backend::openssl::TlsConnectorBuilderExt::from_openssl(ssl);
| ^^^^^^^ could not find `openssl` in `backend`
Compiling hyper v0.2.1
error: expected identifier, found `"rustc-serialize"`
--> ...\hyper-0.2.1\src\lib.rs:129:14
|
129 | extern crate "rustc-serialize" as serialize;
| ^^^^^^^^^^^^^^^^^ expected identifier
生成了一个服务器 stub 用户 swagger。遇到 cargo 找不到 openssl 的问题,并给出类似“自定义构建一些 openssl-sys 0.9.24”的错误。这是一个已知问题,我通过下载 vcpkg 并使用 vcpkg 下载 openssl 来克服它。然后使用环境变量指向下载文件夹,以便 cargo 可以使用 openssl。但是现在错误好像是 openssl
doesn't exist in backend
?
它似乎也特定于 Windows,有什么想法吗?
尝试将 native-tls 的版本更改为最新版本,但它似乎根本没有影响。看起来 swagger 的依赖项需要更新,但我实际上只是生成了这个 stub ...
最佳答案
您发现了 Rust 文档工具的缺陷;它获取包裹中的内容,但不显示限制。
backend
模块定义定义为:
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub mod security_framework;
#[cfg(target_os = "windows")]
pub mod schannel;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
pub mod openssl;
也就是说,情况是这样的:
- 如果您使用的是 linux(即不是 macOS,不是 windows,不是 iOS),则
openssl
可用 - 如果您使用的是 Windows,则
schannel
可用 - 如果您使用的是 MacOS 或 iOS
security_framework
可用
但是,您不应尝试以特定后端为目标,因为这违背了库的目的。不要导入 native_tls::backend::openssl::TlsConnectorBuilderExt
,而是导入 native_tls::TlsConnectorBuilder
并让它决定您需要什么后端。
然而,这可能说起来容易做起来难,因为从您的错误来看,这是由第三方库引起的,这表明它仅在 Linux 上进行了测试。
关于server - 在后端找不到 openssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58447385/