Model

Struct Model 

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

A model used to generate images.

Implementations§

Source§

impl Model

Source

pub fn parts(&self) -> &[ModelPart]

Returns the parts of the model.

§Examples
use svggen::{Model, ModelPart};
 
let model = Model::from(vec![
    ModelPart::from("Hello ".as_bytes()),
    ModelPart::Argument(0),
    ModelPart::from("!".as_bytes()),
]);
 
assert_eq!(model.parts(), &[
    ModelPart::Text(b"Hello ".to_vec().into()),
    ModelPart::Argument(0),
    ModelPart::Text(b"!".to_vec().into()),
]);
Source

pub fn write<W: Write>( &self, writer: &mut W, args: &[Argument<'_>], ) -> Result<()>

Write the model to a writer.

§Arguments
  • writer - The writer to write the model to.
  • args - The arguments to use.
§Examples
use rutil::read::Readable;
use svggen::{Model, ModelPart, Image, Argument};
 
let model = Model::from(vec![
    ModelPart::from("Hello ".as_bytes()),
    ModelPart::Argument(0),
    ModelPart::from("!".as_bytes()),
]);
 
let image = Image::from("World".as_bytes());
let args = [Argument::Image(&image)];
 
let mut buffer: Vec<u8> = Vec::new();
 
// buffer implements `io::Write` so we can use it as a writer
model.write(&mut buffer, &args).unwrap();
 
assert_eq!(buffer, b"Hello World!");
Source

pub fn generate(&self, args: &[Argument<'_>]) -> Result<Image, usize>

Creates an image from the model.

§Arguments
  • args - The arguments to use.
§Examples
use rutil::read::Readable;
use svggen::{Model, ModelPart, Image, Argument};
 
let model = Model::from(vec![
    ModelPart::from("Hello ".as_bytes()),
    ModelPart::Argument(0),
    ModelPart::from("!".as_bytes()),
]);
 
let image = Image::from("World".as_bytes());
let args = [Argument::Image(&image)];
 
let image = model.generate(&args).unwrap();
 
assert_eq!(image.content(), b"Hello World!");

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Model

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Model

Source§

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

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

impl<T: Into<Box<[ModelPart]>>> From<T> for Model

Source§

fn from(parts: T) -> Self

Creates a new model from the given parts.

§Arguments
  • parts - The parts of the model.
§Examples
use svggen::{Model, ModelPart};
 
let model = Model::from(vec![
    ModelPart::from("Hello ".as_bytes()),
    ModelPart::Argument(0),
    ModelPart::from("!".as_bytes()),
]);
 
assert_eq!(model.parts(), &[
    ModelPart::Text(b"Hello ".to_vec().into()),
    ModelPart::Argument(0),
    ModelPart::Text(b"!".to_vec().into()),
]);
Source§

impl PartialEq for Model

Source§

fn eq(&self, other: &Model) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Readable for Model

Source§

type ParseError = ()

There is no parsing error.

Source§

fn load<R: Read>(reader: &mut R) -> Result<Self, ReadError<Self::ParseError>>

Creates a new model from a reader.

§Arguments
  • reader - The reader to read the model from.
§Examples
use rutil::read::Readable;
use svggen::{Model, ModelPart, Image, Argument};
 
let mut data = "<svg>\n#GET 0\n</svg>".as_bytes();
 
// data implements `io::Read` so we can use it as a reader
let model = Model::load(&mut data).unwrap();
 
assert_eq!(model.parts(), &[
    ModelPart::Text(b"<svg>\n".to_vec().into()),
    ModelPart::Argument(0),
    ModelPart::Text(b"\n</svg>".to_vec().into()),
]);
Source§

fn load_file<P>(path: P) -> Result<Self, ReadError<Self::ParseError>>
where P: AsRef<Path>,

Create a new object from a file. Read more
Source§

fn load_all<P>(path: P) -> HashMap<String, Self>
where P: AsRef<Path>,

Get all objects from a directory (one object per file). Read more
Source§

impl Eq for Model

Source§

impl StructuralPartialEq for Model

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnwindSafe for Model

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