Crates.io | myust |
lib.rs | myust |
version | 1.0.9 |
source | src |
created_at | 2023-04-24 04:20:08.456919 |
updated_at | 2023-04-29 09:42:49.567032 |
description | A rich and hybrid mystb.in API wrapper for Rust 🦀 |
homepage | |
repository | https://github.com/danrfq/myust |
max_upload_size | |
id | 847032 |
size | 55,109 |
myust is a rich and hybrid Rust wrapper for the mystb.in API that aims for user-flexibility.
myust supports hybrid clients:
⚠️ Synchronous clients are only available on the sync feature.
You can authenticate with the API using the auth
method with your
mystb.in, example:
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");
It will panic if the provided token is invalid.
Add myust = "1.0"
to your Cargo.toml
file.
[dependencies]
myust = "1.0"
tokio = "1.0"
If you want to use synchronous clients, add the sync
feature.
[dependencies]
myust = { version = "1.0", features = ["sync"] }
Asynchronously creating a paste with tomorrow expiration date, with error handling:
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)
}
}
}
Asynchronously deleting a paste (you must own the paste):
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)
}
}
}
Synchronously creating a multifile paste with a password (you must have the sync
feature enabled):
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)
}
You can check for another example snippets in the test folder.
If you need any help regarding myust, feel free to open an issue about your problem, and feel free to make a pull request for code improvements, bugfixing, etc.