Struct genanki_rs::Package

source ·
pub struct Package { /* private fields */ }
Expand description

Package to pack Decks and media_files and write them to a .apkg file

Example:

use genanki_rs::{Package, Deck, Note, Model, Field, Template};

let model = Model::new(
    1607392319,
    "Simple Model",
    vec![
        Field::new("Question"),
        Field::new("Answer"),
        Field::new("MyMedia"),
    ],
    vec![Template::new("Card 1")
        .qfmt("{{Question}}{{Question}}<br>{{MyMedia}}")
        .afmt(r#"{{FrontSide}}<hr id="answer">{{Answer}}"#)],
);

let mut deck = Deck::new(1234, "Example Deck", "Example Deck with media");
deck.add_note(Note::new(model.clone(), vec!["What is the capital of France?", "Paris", "[sound:sound.mp3]"])?);
deck.add_note(Note::new(model.clone(), vec!["What is the capital of France?", "Paris", r#"<img src="image.jpg">"#])?);

let mut package = Package::new(vec![my_deck], vec!["sound.mp3", "images/image.jpg"])?;
package.write_to_file("output.apkg")?;

Implementations§

source§

impl Package

source

pub fn new(decks: Vec<Deck>, media_files: Vec<&str>) -> Result<Self, Error>

Create a new package with decks and media_files

Returns Err if media_files are invalid

source

pub fn write<W: Write + Seek>(&mut self, writer: W) -> Result<(), Error>

Writes the package to any writer that implements Write and Seek

source

pub fn write_timestamp<W: Write + Seek>( &mut self, writer: W, timestamp: f64 ) -> Result<(), Error>

Writes the package to any writer that implements Write and Seek using a timestamp

source

pub fn write_to_file(&mut self, file: &str) -> Result<(), Error>

Writes the package to a file

Returns Err if the file cannot be created

source

pub fn write_to_file_timestamp( &mut self, file: &str, timestamp: f64 ) -> Result<(), Error>

Writes the package to a file using a timestamp

Returns Err if the file cannot be created

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.