Template

Struct Template 

Source
pub struct Template { /* private fields */ }
Expand description

A Template holds information about a number of JPEG images, and serves as an input to ImageGenerator.

Use Template::from_input or Template::from_inputs if you know your inputs ahead of time, otherwise create an empty template with Template::default and fill it up with Template::learn or Template::learn_many.

§Examples

use fakejpeg::Template;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let images = [
      // images come here...
    ];
    let template = Template::from_inputs(&images)?;

    // Do something with `template`, maybe generate new fakes from it!

    Ok(())
}

Implementations§

Source§

impl Template

Source

pub fn from_input<I: AsRef<[u8]>>(input: I) -> Result<Self, ParseError>

Parses and learns the structure of a single JPEG images, returning a Template.

§Errors

Returns ParseError when parsing fails.

Source

pub fn from_inputs<A, I>(inputs: I) -> Result<Self, ParseError>
where A: AsRef<[u8]>, I: IntoIterator<Item = A>,

Parses and learns the structure of multiple JPEG images, returning a Template.

Similar to Template::from_input, but rather than taking parsing and learning a single JPEG image, it does so over multiple of them.

§Errors

Returns ParseError when parsing fails.

Source

pub fn learn<A: AsRef<[u8]>>(&mut self, input: A) -> Result<(), ParseError>

Parse and learn the structure of a single JPEG image.

This parses the JPEG, and extracts the parts required to generate randomized fakes, and updates the template.

§Errors

Returns ParseError when parsing fails.

Source

pub fn learn_many<A, I>(&mut self, inputs: I) -> Result<(), ParseError>
where A: AsRef<[u8]>, I: IntoIterator<Item = A>,

Parses and learns the structure of multiple JPEG images.

Similar to Template::learn, but rather than taking parsing and learning a single JPEG image, it does so over multiple of them.

§Errors

Returns ParseError when parsing fails.

Trait Implementations§

Source§

impl Debug for Template

Source§

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

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

impl Default for Template

Source§

fn default() -> Template

Returns the “default value” for a type. Read more
Source§

impl<'t> From<&'t Template> for ImageGenerator<'t>

Source§

fn from(template: &'t Template) -> Self

Convert a Template reference to an ImageGenerator.

Source§

impl TryFrom<&[u8]> for Template

Source§

fn try_from(input: &[u8]) -> Result<Self, ParseError>

Try and convert a slice of bytes to a Template.

Source§

type Error = ParseError

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

impl TryFrom<&Vec<u8>> for Template

Source§

fn try_from(input: &Vec<u8>) -> Result<Self, ParseError>

Try and convert a reference to a Vec of bytes to a Template.

Source§

type Error = ParseError

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

impl TryFrom<Vec<u8>> for Template

Source§

fn try_from(input: Vec<u8>) -> Result<Self, ParseError>

Try and convert a Vec of bytes to a Template.

Source§

type Error = ParseError

The type returned in the event of a conversion error.

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> 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V