From 9fc5f0b1259fff2b999347f9ea326d13c222a16e Mon Sep 17 00:00:00 2001 From: Genny Date: Sun, 10 Oct 2021 14:04:56 -0500 Subject: Fix builder api, add save method --- src/gif.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/gif.rs') diff --git a/src/gif.rs b/src/gif.rs index 36e64dd..5b58ed1 100644 --- a/src/gif.rs +++ b/src/gif.rs @@ -1,4 +1,9 @@ -use crate::{block::{extension::Extension, Block, ColorTable, ScreenDescriptor, Version}, writer::GifBuilder}; +use std::{fs::File, io::Write, path::Path}; + +use crate::{ + block::{extension::Extension, Block, ColorTable, ScreenDescriptor, Version}, + writer::GifBuilder, +}; pub struct Gif { pub header: Version, pub screen_descriptor: ScreenDescriptor, @@ -49,6 +54,10 @@ impl Gif { out } + + pub fn save>(&self, path: P) -> std::io::Result<()> { + File::create(path.as_ref())?.write_all(&self.to_vec()) + } } /*struct FrameIterator { @@ -150,11 +159,9 @@ pub mod gif { .palette(colortable.try_into().unwrap()) .indicies(&indicies), ) - .unwrap() - .image(ImageBuilder::new(4, 4).indicies(&indicies)) - .unwrap(); + .image(ImageBuilder::new(4, 4).indicies(&indicies)); - let bytes = actual.build().to_vec(); + let bytes = actual.build().unwrap().to_vec(); assert_eq!(bytes, expected_out); } @@ -179,10 +186,9 @@ pub mod gif { .disposal_method(DisposalMethod::RestoreBackground) .delay(64), ) - .unwrap() .image(ImageBuilder::new(4, 4).indicies(&indicies)) - .unwrap() .build() + .unwrap() .to_vec(); std::fs::File::create("ah.gif") -- cgit 1.4.1-3-g733a5