#prime #factorization #command-line #api-bindings

bin+lib factordb

Rust 对 FactorDB API 的封装

3 个版本 (破坏性更新)

0.3.0 2024年2月5日
0.2.0 2022年3月31日
0.1.0 2022年3月31日

#1215 in 数学

每月 25 下载量

MIT/Apache

28KB
494

factordb-rust

Crates.io Version Crates.io License GitHub Actions Workflow Status

Rust 对 FactorDB API 的封装。

包括一个库以及一个简单的命令行应用程序。

命令行应用程序

安装

cargo install factordb --all-features

从源代码构建

git clone https://github.com/megascrapper/factordb-rust
cd factordb-rust
cargo build --all-features

命令行使用

Rust wrapper for FactorDB API

Usage: factordb [OPTIONS] <NUMBER>

Arguments:
  <NUMBER>  Number to find its factor

Options:
      --unique   Print unique factors on each line
      --json     Print JSON output of FactorDB API
  -h, --help     Print help
  -V, --version  Print version

添加依赖项

cargo add factordb

库使用示例

use std::error::Error;
use factordb::FactorDbClient;
use num_bigint::BigInt; // All numeric values in the result object are of this type

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Initialise the client
    let client = FactorDbClient::new();

    // Make requests
    let forty_two = client.get(42).await?;
    let expect_factors: Vec<BigInt> = vec![2, 3, 7].into_iter().map(|n| BigInt::from(n)).collect();
    assert_eq!(forty_two.into_factors_flattened(), expect_factors);

    Ok(())
 }

文档

https://docs.rs/factordb/latest/factordb/

许可证

根据您的选择,受以下任何一个许可证的约束:

贡献

除非您明确表示,否则您提交的任何有意包含在本作品中的贡献,根据 Apache-2.0 许可证的界定,将根据上述方式双重许可,而不附加任何额外的条款或条件。

依赖项

~6–19MB
~275K SLoC