Struct life_backend::format::Rle
source · pub struct Rle { /* private fields */ }Expand description
A representation for RLE file format.
The detail of this format is described in:
Examples
Parses the given RLE file, and checks live cells included in it:
use std::fs::File;
use life_backend::format::Rle;
use life_backend::Position;
let file = File::open("patterns/rpentomino.rle")?;
let parser = Rle::new(file)?;
assert!(parser.live_cells().eq([Position(1, 0), Position(2, 0), Position(0, 1), Position(1, 1), Position(1, 2)]));Parses the given string in RLE format:
use life_backend::format::Rle;
use life_backend::Position;
let pattern = "\
#N R-pentomino\n\
x = 3, y = 3\n\
b2o$2o$bo!\n\
";
let parser = pattern.parse::<Rle>()?;
assert!(parser.live_cells().eq([Position(1, 0), Position(2, 0), Position(0, 1), Position(1, 1), Position(1, 2)]));Implementations§
source§impl Rle
impl Rle
sourcepub const fn width(&self) -> usize
pub const fn width(&self) -> usize
Returns the width written in the pattern.
Examples
use life_backend::format::Rle;
let pattern = "\
#N T-tetromino\n\
x = 3, y = 2\n\
3o$bo!\n\
";
let parser = Rle::new(pattern.as_bytes())?;
assert_eq!(parser.width(), 3);sourcepub const fn height(&self) -> usize
pub const fn height(&self) -> usize
Returns the height written in the pattern.
Examples
use life_backend::format::Rle;
let pattern = "\
#N T-tetromino\n\
x = 3, y = 2\n\
3o$bo!\n\
";
let parser = Rle::new(pattern.as_bytes())?;
assert_eq!(parser.height(), 2);sourcepub const fn rule(&self) -> &Rule
pub const fn rule(&self) -> &Rule
Returns the rule.
Examples
use life_backend::format::Rle;
use life_backend::Rule;
let pattern = "\
#N T-tetromino\n\
x = 3, y = 2, rule = B3/S23\n\
3o$bo!\n\
";
let parser = Rle::new(pattern.as_bytes())?;
assert_eq!(parser.rule(), &Rule::conways_life());sourcepub const fn comments(&self) -> &Vec<String>
pub const fn comments(&self) -> &Vec<String>
Returns comments of the pattern.
Examples
use life_backend::format::Rle;
let pattern = "\
#N T-tetromino\n\
x = 3, y = 2\n\
3o$bo!\n\
";
let parser = Rle::new(pattern.as_bytes())?;
assert_eq!(parser.comments().len(), 1);
assert_eq!(parser.comments()[0], "#N T-tetromino");sourcepub fn live_cells(&self) -> impl Iterator<Item = Position<usize>> + '_
pub fn live_cells(&self) -> impl Iterator<Item = Position<usize>> + '_
Creates an owning iterator over the series of live cell positions in ascending order.
Examples
use life_backend::format::Rle;
use life_backend::Position;
let pattern = "\
#N T-tetromino\n\
x = 3, y = 2\n\
3o$bo!\n\
";
let parser = Rle::new(pattern.as_bytes())?;
assert!(parser.live_cells().eq([Position(0, 0), Position(1, 0), Position(2, 0), Position(1, 1)]));Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Rle
impl Send for Rle
impl Sync for Rle
impl Unpin for Rle
impl UnwindSafe for Rle
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