pub struct Plaintext { /* private fields */ }
Expand description
A representation for Plaintext file format.
The detail of this format is described in:
§Examples
Parses the given Plaintext file, and checks live cells included in it:
use std::fs::File;
use life_backend::format::Plaintext;
use life_backend::Position;
let file = File::open("patterns/rpentomino.cells")?;
let parser = Plaintext::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 Plaintext format:
use life_backend::format::Plaintext;
use life_backend::Position;
let pattern = "\
!Name: R-pentomino\n\
.OO\n\
OO.\n\
.O.\n\
";
let parser = pattern.parse::<Plaintext>()?;
assert!(parser.live_cells().eq([Position(1, 0), Position(2, 0), Position(0, 1), Position(1, 1), Position(1, 2)]));
Implementations§
Source§impl Plaintext
impl Plaintext
Sourcepub fn name(&self) -> Option<String>
pub fn name(&self) -> Option<String>
Returns the name of the pattern.
§Examples
use life_backend::format::Plaintext;
let pattern = "\
!Name: T-tetromino\n\
OOO\n\
.O.\n\
";
let parser = Plaintext::new(pattern.as_bytes())?;
assert_eq!(parser.name(), Some("T-tetromino".to_string()));
Sourcepub const fn comments(&self) -> &Vec<String>
pub const fn comments(&self) -> &Vec<String>
Returns comments of the pattern.
§Examples
use life_backend::format::Plaintext;
let pattern = "\
!Name: T-tetromino\n\
!comment0\n\
!comment1\n\
OOO\n\
.O.\n\
";
let parser = Plaintext::new(pattern.as_bytes())?;
assert_eq!(parser.comments().len(), 2);
assert_eq!(parser.comments()[0], "comment0");
assert_eq!(parser.comments()[1], "comment1");
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::Plaintext;
use life_backend::Position;
let pattern = "\
!Name: T-tetromino\n\
OOO\n\
.O.\n\
";
let parser = Plaintext::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 Freeze for Plaintext
impl RefUnwindSafe for Plaintext
impl Send for Plaintext
impl Sync for Plaintext
impl Unpin for Plaintext
impl UnwindSafe for Plaintext
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