Struct life_backend::format::PlaintextBuilder
source · pub struct PlaintextBuilder<Name = PlaintextBuilderNoName, Comment = PlaintextBuilderNoComment>where
Name: PlaintextBuilderName,
Comment: PlaintextBuilderComment,{ /* private fields */ }Expand description
A builder of Plaintext.
Examples
Creates a builder via collect() with live cell positions, set a name via name(), then builds Plaintext via build():
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(2, 0), Position(0, 1), Position(1, 1), Position(1, 2)];
let target = pattern.iter().collect::<PlaintextBuilder>().name("R-pentomino").build()?;
let expected = "\
!Name: R-pentomino\n\
.OO\n\
OO.\n\
.O.\n\
";
assert_eq!(format!("{target}"), expected);Creates an empty builder via new(), set a name via name(), injects live cell positions via extend(), then builds Plaintext via build():
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(2, 0), Position(0, 1), Position(1, 1), Position(1, 2)];
let mut builder = PlaintextBuilder::new().name("R-pentomino");
builder.extend(pattern.iter());
let target = builder.build()?;
let expected = "\
!Name: R-pentomino\n\
.OO\n\
OO.\n\
.O.\n\
";
assert_eq!(format!("{target}"), expected);Implementations§
source§impl PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
impl PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
source§impl<Name, Comment> PlaintextBuilder<Name, Comment>where
Name: PlaintextBuilderName,
Comment: PlaintextBuilderComment,
impl<Name, Comment> PlaintextBuilder<Name, Comment>where Name: PlaintextBuilderName, Comment: PlaintextBuilderComment,
source§impl<Comment> PlaintextBuilder<PlaintextBuilderNoName, Comment>where
Comment: PlaintextBuilderComment,
impl<Comment> PlaintextBuilder<PlaintextBuilderNoName, Comment>where Comment: PlaintextBuilderComment,
sourcepub fn name(
self,
str: &str
) -> PlaintextBuilder<PlaintextBuilderWithName, Comment>
pub fn name( self, str: &str ) -> PlaintextBuilder<PlaintextBuilderWithName, Comment>
Set the name.
Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
.iter()
.collect::<PlaintextBuilder>()
.name("foo")
.build()?;
assert_eq!(target.name(), Some("foo".to_string()));Errors
Code that calls name() twice or more will fail at compile time. For example:
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
.iter()
.collect::<PlaintextBuilder>()
.name("foo")
.name("bar") // Compile error
.build()?;build() returns an error if the string passed by name() includes multiple lines. For example:
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
.iter()
.collect::<PlaintextBuilder>()
.name("foo\nbar")
.build()?; // Should failsource§impl<Name> PlaintextBuilder<Name, PlaintextBuilderNoComment>where
Name: PlaintextBuilderName,
impl<Name> PlaintextBuilder<Name, PlaintextBuilderNoComment>where Name: PlaintextBuilderName,
sourcepub fn comment(
self,
str: &str
) -> PlaintextBuilder<Name, PlaintextBuilderWithComment>
pub fn comment( self, str: &str ) -> PlaintextBuilder<Name, PlaintextBuilderWithComment>
Set the comment.
If the argument includes newlines, the instance of Plaintext built by build() includes multiple comment lines.
Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
.iter()
.collect::<PlaintextBuilder>()
.comment("comment0\ncomment1")
.build()?;
assert_eq!(target.comments().len(), 2);
assert_eq!(target.comments()[0], "comment0");
assert_eq!(target.comments()[1], "comment1");Errors
Code that calls comment() twice or more will fail at compile time. For example:
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
.iter()
.collect::<PlaintextBuilder>()
.comment("comment0")
.comment("comment1") // Compile error
.build()?;Trait Implementations§
source§impl<Name, Comment> Clone for PlaintextBuilder<Name, Comment>where
Name: PlaintextBuilderName + Clone,
Comment: PlaintextBuilderComment + Clone,
impl<Name, Comment> Clone for PlaintextBuilder<Name, Comment>where Name: PlaintextBuilderName + Clone, Comment: PlaintextBuilderComment + Clone,
source§fn clone(&self) -> PlaintextBuilder<Name, Comment>
fn clone(&self) -> PlaintextBuilder<Name, Comment>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<Name, Comment> Debug for PlaintextBuilder<Name, Comment>where
Name: PlaintextBuilderName + Debug,
Comment: PlaintextBuilderComment + Debug,
impl<Name, Comment> Debug for PlaintextBuilder<Name, Comment>where Name: PlaintextBuilderName + Debug, Comment: PlaintextBuilderComment + Debug,
source§impl Default for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
impl Default for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
source§impl<'a, Name, Comment> Extend<&'a Position<usize>> for PlaintextBuilder<Name, Comment>where
Name: PlaintextBuilderName,
Comment: PlaintextBuilderComment,
impl<'a, Name, Comment> Extend<&'a Position<usize>> for PlaintextBuilder<Name, Comment>where Name: PlaintextBuilderName, Comment: PlaintextBuilderComment,
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = &'a Position<usize>>,
fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = &'a Position<usize>>,
Extends the builder with the contents of the specified non-owning iterator over the series of &Position<usize>.
Each item in the series represents an immutable reference of a live cell position.
Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.iter();
let mut builder = PlaintextBuilder::new();
builder.extend(iter);source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl<Name, Comment> Extend<Position<usize>> for PlaintextBuilder<Name, Comment>where
Name: PlaintextBuilderName,
Comment: PlaintextBuilderComment,
impl<Name, Comment> Extend<Position<usize>> for PlaintextBuilder<Name, Comment>where Name: PlaintextBuilderName, Comment: PlaintextBuilderComment,
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = Position<usize>>,
fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = Position<usize>>,
Extends the builder with the contents of the specified owning iterator over the series of Position<usize>.
Each item in the series represents a moved live cell position.
Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.into_iter();
let mut builder = PlaintextBuilder::new();
builder.extend(iter);source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl<'a> FromIterator<&'a Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
impl<'a> FromIterator<&'a Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = &'a Position<usize>>,
fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = &'a Position<usize>>,
Creates a value from a non-owning iterator over a series of &Position<usize>.
Each item in the series represents an immutable reference of a live cell position.
Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.iter();
let builder: PlaintextBuilder = iter.collect();source§impl FromIterator<Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
impl FromIterator<Position<usize>> for PlaintextBuilder<PlaintextBuilderNoName, PlaintextBuilderNoComment>
source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = Position<usize>>,
fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = Position<usize>>,
Creates a value from an owning iterator over a series of Position<usize>.
Each item in the series represents a moved live cell position.
Examples
use life_backend::format::PlaintextBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.into_iter();
let builder: PlaintextBuilder = iter.collect();