diff options
author | Genny <gen@nyble.dev> | 2021-10-10 14:04:56 -0500 |
---|---|---|
committer | Genny <gen@nyble.dev> | 2021-10-10 14:04:56 -0500 |
commit | 9fc5f0b1259fff2b999347f9ea326d13c222a16e (patch) | |
tree | f8194e57c86caa3b6519e30a84a0d5919c9ad5a0 /src/gif.rs | |
parent | a4c967c5bd132d2bf9f2b151ee2ca1f4aa05f4a4 (diff) | |
download | gifed-9fc5f0b1259fff2b999347f9ea326d13c222a16e.tar.gz gifed-9fc5f0b1259fff2b999347f9ea326d13c222a16e.zip |
Fix builder api, add save method
Diffstat (limited to 'src/gif.rs')
-rw-r--r-- | src/gif.rs | 20 |
1 files changed, 13 insertions, 7 deletions
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<P: AsRef<Path>>(&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") |