Crates.io | anki_bridge |
lib.rs | anki_bridge |
version | 0.8.0 |
source | src |
created_at | 2023-06-29 19:44:29.578725 |
updated_at | 2024-03-16 21:11:16.430691 |
description | AnkiBridge is a Rust library that provides a bridge between your Rust code and the Anki application, enabling HTTP communication and seamless data transmission. |
homepage | |
repository | https://gitlab.com/kerkmann/anki_bridge |
max_upload_size | |
id | 903615 |
size | 197,751 |
AnkiBridge is a Rust library that serves as a bridge between your Rust code and the Anki application, leveraging the AnkiConnect add-on to establish an HTTP connection. This library enables seamless transmission of data and facilitates interaction with Anki through Rust.
AnkiBridge provides the following features:
To use AnkiBridge in your Rust project, add the following line to your Cargo.toml
file:
[dependencies]
anki_bridge = { version = "0.7", features = ["ureq_blocking"] }
Additionally, ensure that you have the Anki application installed on your system and that the AnkiConnect add-on is installed within Anki.
Please note that Anki must be opened and running on your computer for AnkiBridge to establish a connection successfully.
To establish a connection and perform actions with Anki, you can utilize the functions and structs provided by the AnkiBridge library in your Rust code. Here's a basic example:
use std::collections::HashMap;
use anki_bridge::prelude::*;
fn main() {
let client = AnkiClient::default();
let decks: Vec<String> = client.request(DeckNamesRequest {}).unwrap();
println!("{decks:#?}");
let deck_stats: HashMap<usize, GetDeckStatsResponse> =
client.request(GetDeckStatsRequest { decks }).unwrap();
println!("{deck_stats:#?}");
}
use anki_bridge::{mock::*, prelude::*};
let client = MockAnkiClient::<FindCardsRequest, _>::new_mock(|params| {
Ok(vec![123, params.query.len()])
});
let response = client.request(FindCardsRequest {
query: "Card Deck Name".to_string(),
});
assert_eq!(
vec![123, "Card Deck Name".len()],
response.unwrap()
);
AnkiBridge is an ongoing project with planned future developments. Here are the upcoming items on the to-do list:
Contributions to AnkiBridge are welcome. Feel free to contribute by opening issues or submitting pull requests on the GitLab repository.
The entire changelog can be found in the CHANGELOG.md file.
Thanks to VaiTon for having the idea to just implement a trait, instead of writing a function. That helped me to write a mockable client and clean everything up. You can find his implementation of the AnkiConnect bridge on GitHub. :)
AnkiBridge is distributed under the MIT License. For more information, see the LICENSE file.
For any questions or inquiries, please contact the project maintainer at daniel@kerkmann.dev.