Enum Instruction

Source
pub enum Instruction {
    Compound {
        instructions: Vec<Instruction>,
    },
    Command {
        command: Command,
    },
    VSpace {
        lines: u8,
    },
    Text {
        content: String,
        markdown: bool,
        font: Font,
        justification: Justification,
        replacements: Option<HashSet<String>>,
    },
    DuoTable {
        name: String,
        header: (String, String),
        font: Font,
    },
    TrioTable {
        name: String,
        header: (String, String, String),
    },
    QuadTable {
        name: String,
        header: (String, String, String),
    },
    Image {
        image: EscposImage,
    },
    QRCode {
        name: String,
    },
    Cut,
}
Expand description

Templates for recurrent prints

The Instruction structure allows the creation of template prints, which could contain certain data that should change between prints (be it text, tables, or even qr codes).

It is not adviced to construct the variants of the enum manually, read the available functions to guarantee a predictable outcome.

Variants§

§

Compound

Compound instruction, composed of multiple instructions that must be executed sequentially

Fields

§instructions: Vec<Instruction>
§

Command

An instruction consisting of a single esc/pos command

Fields

§command: Command
§

VSpace

Short for jumping a specified number of lines

Fields

§lines: u8
§

Text

Raw text

Fields

§content: String

Content to be printed

§markdown: bool

Indicates if markdown translation should be applied

§font: Font

Font to be used with this text

§justification: Justification

Justification of the content

§replacements: Option<HashSet<String>>

Maps a string to be replaced, to a description of the string

§

DuoTable

2 column table

Fields

§name: String

Name of the table. Required for attaching tuples for printing

§header: (String, String)

Header to be displayed on the table

§font: Font

Font used for the table

§

TrioTable

Table with three columns. Might be to tight for 50mm printers

Fields

§name: String
§header: (String, String, String)
§

QuadTable

Fancy table for really detailed prints

Fields

§name: String
§header: (String, String, String)
§

Image

Contains a static image, that is, does not change with different printing mechanisms

Fields

§image: EscposImage

Inner image

§

QRCode

Prints a QR Code. This field is dynamic

Fields

§name: String

Name of the QR code, to be searched in the qr code content list

§

Cut

Cuts the paper in place. Only for supported printers

Implementations§

Source§

impl Instruction

Source

pub fn is_compound(&self) -> bool

Returns true if the instruction is compund

Source

pub fn is_text(&self) -> bool

Returns true if the instruction is text

Source

pub fn text<A: Into<String>>( content: A, font: Font, justification: Justification, replacements: Option<HashSet<String>>, ) -> Instruction

Sends simple text to the printer.

Straightfoward text printing. The replacements set specifies which contents of the string should be replaced in a per-impresion basis.

Source

pub fn markdown( content: String, font: Font, justification: Justification, replacements: Option<HashSet<String>>, ) -> Instruction

Sends markdown text to the printer

Allows markdown to be sent to the printer. Not everything is supported, so far the following list works (if the printer supports the corresponding fonts)

  • Bold font, with **
  • Italics, with _
Source

pub fn image(image: EscposImage) -> Result<Instruction, Error>

Prints an image

For a more precise control of position in the image, it is easier to edit the input image beforehand.

Source

pub fn qr_code(content: String) -> Result<Instruction, Error>

Creates a new QR code that does not change through different print steps

Source

pub fn dynamic_qr_code<A: Into<String>>(name: A) -> Instruction

Creates a dynamic qr code instruction, which requires a string at printing time

Source

pub fn command(command: Command) -> Instruction

Executes a raw escpos command.

Source

pub fn duo_table<A: Into<String>, B: Into<String>, C: Into<String>>( name: A, header: (B, C), font: Font, ) -> Instruction

Creates a table with two columns.

Source

pub fn trio_table<A: Into<String>, B: Into<String>, C: Into<String>, D: Into<String>>( name: A, header: (B, C, D), ) -> Instruction

Creates a table with three columns

Source

pub fn quad_table<A: Into<String>, B: Into<String>, C: Into<String>, D: Into<String>>( name: A, header: (B, C, D), ) -> Instruction

Creates a table with four columns

Tables with four columns can be quite tight in 80mm printers, and unthinkable in 58mm ones or smaller. Use with caution!

Source

pub fn cut() -> Instruction

Cuts the paper (if supported)

Source

pub fn vspace(lines: u8) -> Instruction

Moves the paper a certain amount of vertical spaces

Trait Implementations§

Source§

impl Add for Instruction

Instruction addition

Source§

type Output = Instruction

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Instruction) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Instruction

Mutable addition for instructions

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl Clone for Instruction

Source§

fn clone(&self) -> Instruction

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Instruction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Instruction

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromIterator<Instruction> for Option<Instruction>

From iterator operation for a vector of instructions

Source§

fn from_iter<I: IntoIterator<Item = Instruction>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Serialize for Instruction

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,