[][src]Struct ca_formats::rle::Rle

pub struct Rle<I: Input> { /* fields omitted */ }

A parser for Golly's Extended RLE format.

The format is basically the same as the original RLE format, except that it supports up to 256 states, and a #CXRLE line.

As an iterator, it iterates over the living cells.

Examples

Reading from a string:

use ca_formats::rle::Rle;

const GLIDER: &str = r"#N Glider
#O Richard K. Guy
#C The smallest, most common, and first discovered spaceship. Diagonal, has period 4 and speed c/4.
#C www.conwaylife.com/wiki/index.php?title=Glider
x = 3, y = 3, rule = B3/S23
bob$2bo$3o!";

let glider = Rle::new(GLIDER).unwrap();
assert_eq!(glider.header_data().unwrap().x, 3);
assert_eq!(glider.header_data().unwrap().y, 3);
assert_eq!(glider.header_data().unwrap().rule, Some(String::from("B3/S23")));

let cells = glider.map(|cell| cell.unwrap().position).collect::<Vec<_>>();
assert_eq!(cells, vec![(1, 0), (2, 1), (0, 2), (1, 2), (2, 2)]);

Reading from a file:

use std::fs::File;
use ca_formats::rle::Rle;

let file = File::open("tests/sirrobin.rle").unwrap();
let sirrobin = Rle::new_from_file(file).unwrap();

assert_eq!(sirrobin.count(), 282);

Implementations

impl<I: Input> Rle<I>[src]

pub fn new(input: I) -> Result<Self, Error>[src]

Create a new parser instance from input, and try to read the header and the #CXRLE line.

If there are multiple header lines / CXRLE lines, only the last one will be taken.

pub fn cxrle_data(&self) -> Option<&CxrleData>[src]

Data from the #CXRLE line.

pub fn header_data(&self) -> Option<&HeaderData>[src]

Data from the header line.

impl<R: Read> Rle<BufReader<R>>[src]

pub fn new_from_file(file: R) -> Result<Self, Error>[src]

Creates a new parser instance from something that implements Read trait, e.g., a File.

Trait Implementations

impl<I: Input> Clone for Rle<I> where
    I::Lines: Clone,
    I::Bytes: Clone
[src]

impl<I: Debug + Input> Debug for Rle<I> where
    I::Lines: Debug,
    I::Bytes: Debug
[src]

impl<I: Input> Iterator for Rle<I>[src]

An iterator over living cells in an RLE file.

type Item = Result<CellData, Error>

The type of the elements being iterated over.

Auto Trait Implementations

impl<I> RefUnwindSafe for Rle<I> where
    <I as Input>::Bytes: RefUnwindSafe,
    <I as Input>::Lines: RefUnwindSafe

impl<I> Send for Rle<I> where
    <I as Input>::Bytes: Send,
    <I as Input>::Lines: Send

impl<I> Sync for Rle<I> where
    <I as Input>::Bytes: Sync,
    <I as Input>::Lines: Sync

impl<I> Unpin for Rle<I> where
    <I as Input>::Bytes: Unpin,
    <I as Input>::Lines: Unpin

impl<I> UnwindSafe for Rle<I> where
    <I as Input>::Bytes: UnwindSafe,
    <I as Input>::Lines: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.