pub struct Model { /* private fields */ }
Expand description
A model used to generate images.
Implementations§
Source§impl Model
impl Model
Sourcepub fn parts(&self) -> &[ModelPart]
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()),
]);
Sourcepub fn write<W: Write>(
&self,
writer: &mut W,
args: &[Argument<'_>],
) -> Result<()>
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!");
Sourcepub fn generate(&self, args: &[Argument<'_>]) -> Result<Image, usize>
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<T: Into<Box<[ModelPart]>>> From<T> for Model
impl<T: Into<Box<[ModelPart]>>> From<T> for Model
Source§fn from(parts: T) -> Self
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 Readable for Model
impl Readable for Model
Source§type ParseError = ()
type ParseError = ()
There is no parsing error.
Source§fn load<R: Read>(reader: &mut R) -> Result<Self, ReadError<Self::ParseError>>
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()),
]);
impl Eq for Model
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more