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 fail
Source§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>
impl<Name, Comment> Clone for PlaintextBuilder<Name, Comment>
Source§fn clone(&self) -> PlaintextBuilder<Name, Comment>
fn clone(&self) -> PlaintextBuilder<Name, Comment>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<Name, Comment> Debug for PlaintextBuilder<Name, Comment>
impl<Name, Comment> Debug for PlaintextBuilder<Name, Comment>
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)
fn extend<T>(&mut self, iter: T)
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)
fn extend<T>(&mut self, iter: T)
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) -> Self
fn from_iter<T>(iter: T) -> Self
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) -> Self
fn from_iter<T>(iter: T) -> Self
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();