#api-wrapper #synchronous #client #hybrid #rich #paste #mystb

myust

丰富且混合的 mystb.in API 包装器,适用于 Rust 🦀

17 个版本 (10 个稳定版)

1.0.9 2023 年 4 月 29 日
1.0.4 2023 年 4 月 27 日
0.1.6 2023 年 4 月 24 日

578Web 编程

Download history 2/week @ 2024-03-11 106/week @ 2024-04-01

每月 151 次下载

MIT 许可证

50KB
988

myust: 📋=>🌐=>🦀

crates.io Documentation MIT

简介

myust 是一个旨在实现用户灵活性的丰富且混合的 mystb.in API 的 Rust 包装器。

myust 支持 hybrid 客户端

⚠️ 同步客户端仅在 sync 功能下可用。

身份验证

您可以使用 auth 方法通过您的 mystb.in 进行身份验证,例如

use myust::{Client, SyncClient};

let client = Client::new().auth("YOUR_MYSTBIN_TOKEN").await;
// or using synchronous client,
let client = SyncClient::new().auth("YOUR_MYSTBIN_TOKEN");

如果提供的令牌无效,将引发 panic。

安装

myust = "1.0" 添加到您的 Cargo.toml 文件中。

[dependencies]
myust = "1.0"
tokio = "1.0"

如果您想使用同步客户端,请添加 sync 功能。

[dependencies]
myust = { version = "1.0", features = ["sync"] }

使用示例

异步创建具有明天到期日期的粘贴,并带有错误处理

use myust::{Client, Expiry};

#[tokio::main]
async fn main() {
   let client = Client::new();
   let tomorrow = Expiry {
       days: 1,
       ..Default::default()
   }; // other fields default to 0
   let result = client
       .create_paste(|p| {
           p.filename("myust.txt")
               .content("Hello from myust!")
               .expires(tomorrow)
       })
       .await;
   match result {
       Ok(_) => {
           let paste = result.unwrap();
           println!("{paste:#?}");
           let url = format!("https://mystb.in/{}", paste.id);
           println!("Result: {}", url)
       }
       Err(_) => {
           println!("Error code: {}", result.unwrap_err().code)
       }
   }
}

异步删除粘贴(您必须拥有该粘贴)

use myust::AuthClient;

#[tokio::main]
async fn main() {
    let client = AuthClient::new()
        .auth(std::env::var("MYSTBIN_TOKEN").unwrap())
        .await;
    let result = client.delete_paste("EquipmentMovingExpensive").await; // The paste ID to delete
    match result {
        Ok(_) => println!("Successfully deleted the paste."),
        Err(_) => {
            println!("Error code: {}", result.unwrap_err().code)
        }
    }
}

同步创建具有密码的多文件粘贴(您必须启用 sync 功能)

use myust::SyncClient;

fn main() {
    let client = SyncClient::new();
    let paste = client
        .create_multifile_paste(|p| {
            p.file(|f| {
                f.filename("myust1.txt")
                    .content("first file")
                    .password("myust")
            }); // set the password on the first file only, same for expiration date
            p.file(|f| f.filename("myust2.txt").content("second file"))
        })
        .unwrap();
    let url = format!("https://mystb.in/{}", paste.id);
    println!("Result: {}", url)
}

您可以在 测试文件夹 中检查其他示例片段。

帮助 & 贡献

如果您需要有关 myust 的任何帮助,请随时打开有关您问题的 issue,并随时提交代码改进、修复错误等的 pull request。

依赖项

~5–20MB
~271K SLoC