pub trait BarcodeEncoder {
type Input: ?Sized;
// Required methods
fn encode_into(
input: &Self::Input,
buf: &mut [bool],
) -> Result<Encoded, EncodeError>;
fn symbology_name() -> &'static str;
// Provided method
fn encode(input: &Self::Input) -> Result<BarcodeOutput, EncodeError> { ... }
}Expand description
A trait implemented by every barcode symbology encoder.
The required method encode_into is allocation-free:
it writes the symbol’s modules into a caller-provided &mut [bool] buffer.
With the alloc feature the provided encode method offers
an owned-output convenience on top of it.
§Example (zero-allocation)
use barcodes::common::traits::BarcodeEncoder;
use barcodes::common::types::Encoded;
use barcodes::ean_upc::ean13::Ean13;
let mut buf = [false; 128];
let Encoded::Linear { len, .. } = Ean13::encode_into("5901234123457", &mut buf).unwrap()
else { panic!("linear") };
let bars = &buf[..len];
assert_eq!(bars.len(), 95);Required Associated Types§
Required Methods§
Sourcefn encode_into(
input: &Self::Input,
buf: &mut [bool],
) -> Result<Encoded, EncodeError>
fn encode_into( input: &Self::Input, buf: &mut [bool], ) -> Result<Encoded, EncodeError>
Encode input, writing the modules into buf and returning an
Encoded describing the written region.
§Errors
Returns EncodeError::BufferTooSmall if buf cannot hold the symbol,
or another EncodeError variant when the input is invalid.
Sourcefn symbology_name() -> &'static str
fn symbology_name() -> &'static str
Return the human-readable name of this symbology (e.g. "EAN-13").
Provided Methods§
Sourcefn encode(input: &Self::Input) -> Result<BarcodeOutput, EncodeError>
fn encode(input: &Self::Input) -> Result<BarcodeOutput, EncodeError>
Encode input into an owned BarcodeOutput.
This is a convenience wrapper over encode_into
that grows a heap buffer as needed; it requires the alloc feature.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".