# rust.cratesio-search **Repository Path**: zinface/rust.cratesio-search ## Basic Information - **Project Name**: rust.cratesio-search - **Description**: 一个基于 http 的 crates.io 依赖搜索工具 - **Primary Language**: Rust - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-05-26 - **Last Updated**: 2022-05-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # rust.cratesio-search > 一个基于 http 的 crates.io 依赖搜索工具 ## 构建/运行/安装/使用 - 构建\ `cargo build` - 运行\ `cargo run -- --query http` - 安装(将会安装到 $HOME/.cargo/bin 中) - 像golang一样安装到 `$GOPATH/bin`\ `cargo install --path .` - 使用: ```bash $ cargo run -- --query http # 或者已安装命令 cratesio-search --query http # 输出 - GET https://crates.io/api/v1/crates?page=1&q=http >>> http = "0.2.7" >>> qiniu-http-client = "0.1.1" >>> constellation-server = "1.14.0" >>> gTickCheckerRust = "0.1.2" >>> tokio-http2 = "0.1.9" >>> didkit-http = "0.2.0" >>> http_desync_guardian = "0.1.3" >>> http-server = "0.7.2" >>> hurl = "1.6.1" >>> tiny_http_sccache = "0.0.0" ``` ## 数据来源于 crates.io 该 curl 命令可以请求到来自 crates.io 的 查询 ferris_says 的json信息 ``` shell curl 'https://crates.io/api/v1/crates?page=1&per_page=10&q=ferris_says' \ -H 'authority: crates.io' \ -H 'accept: */*' \ -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8' \ -H 'referer: https://crates.io/search?q=ferris_says' \ -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'sec-ch-ua-platform: "Linux"' \ -H 'sec-fetch-dest: empty' \ -H 'sec-fetch-mode: cors' \ -H 'sec-fetch-site: same-origin' \ -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36' \ --compressed ``` ## 使用到的一些扩充内容 - rust中String,&str,Vec 和&[u8]的惯用转换 ```rust &str -> String--| String::from(s) or s.to_string() or s.to_owned() &str -> &[u8]---| s.as_bytes() &str -> Vec-| s.as_bytes().to_vec() or s.as_bytes().to_owned() String -> &str----| &s if possible* else s.as_str() String -> &[u8]---| s.as_bytes() String -> Vec-| s.into_bytes() &[u8] -> &str----| s.to_vec() or s.to_owned() &[u8] -> String--| std::str::from_utf8(s).unwrap(), but don't** &[u8] -> Vec-| String::from_utf8(s).unwrap(), but don't** Vec -> &str----| &s if possible* else s.as_slice() Vec -> String--| std::str::from_utf8(&s).unwrap(), but don't** Vec -> &[u8]---| String::from_utf8(s).unwrap(), but don't** ```