Struct RleBuilder

Source
pub struct RleBuilder<Name = RleBuilderNoName, Created = RleBuilderNoCreated, Comment = RleBuilderNoComment, Rule = RleBuilderNoRule>
where Name: RleBuilderName, Created: RleBuilderCreated, Comment: RleBuilderComment, Rule: RleBuilderRule,
{ /* private fields */ }
Expand description

A builder of Rle.

§Examples

Creates a builder via collect() with live cell positions, set a name via name(), then builds Rle via build():

use life_backend::format::RleBuilder;
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::<RleBuilder>().name("R-pentomino").build()?;
let expected = "\
    #N R-pentomino\n\
    x = 3, y = 3, rule = B3/S23\n\
    b2o$2o$bo!\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 Rle via build():

use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(2, 0), Position(0, 1), Position(1, 1), Position(1, 2)];
let mut builder = RleBuilder::new().name("R-pentomino");
builder.extend(pattern.iter());
let target = builder.build()?;
let expected = "\
    #N R-pentomino\n\
    x = 3, y = 3, rule = B3/S23\n\
    b2o$2o$bo!\n\
";
assert_eq!(format!("{target}"), expected);

Implementations§

Source§

impl RleBuilder<RleBuilderNoName, RleBuilderNoCreated, RleBuilderNoComment, RleBuilderNoRule>

Source

pub fn new() -> Self

Creates a builder that contains no live cells.

§Examples
use life_backend::format::RleBuilder;
let builder = RleBuilder::new();
Source§

impl<Name, Created, Comment, RuleSpec> RleBuilder<Name, Created, Comment, RuleSpec>
where Name: RleBuilderName, Created: RleBuilderCreated, Comment: RleBuilderComment, RuleSpec: RleBuilderRule,

Source

pub fn build(self) -> Result<Rle>

Builds the Rle value.

§Examples
use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let builder: RleBuilder = pattern.iter().collect();
let target = builder.build()?;
Source§

impl<Created, Comment, Rule> RleBuilder<RleBuilderNoName, Created, Comment, Rule>
where Created: RleBuilderCreated, Comment: RleBuilderComment, Rule: RleBuilderRule,

Source

pub fn name( self, str: &str, ) -> RleBuilder<RleBuilderWithName, Created, Comment, Rule>

Set the name.

§Examples
use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
    .iter()
    .collect::<RleBuilder>()
    .name("foo")
    .build()?;
assert_eq!(target.comments().len(), 1);
assert_eq!(target.comments()[0], "#N foo".to_string());
§Errors

Code that calls name() twice or more will fail at compile time. For example:

use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
    .iter()
    .collect::<RleBuilder>()
    .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::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
    .iter()
    .collect::<RleBuilder>()
    .name("foo\nbar")
    .build()?; // Should fail
Source§

impl<Name, Comment, Rule> RleBuilder<Name, RleBuilderNoCreated, Comment, Rule>
where Name: RleBuilderName, Comment: RleBuilderComment, Rule: RleBuilderRule,

Source

pub fn created( self, str: &str, ) -> RleBuilder<Name, RleBuilderWithCreated, Comment, Rule>

Set the information when and by whom the pattern was created. If the argument includes newlines, the instance of Rle built by build() includes multiple comment lines.

§Examples
use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
    .iter()
    .collect::<RleBuilder>()
    .created("foo")
    .build()?;
assert_eq!(target.comments().len(), 1);
assert_eq!(target.comments()[0], "#O foo".to_string());
§Errors

Code that calls created() twice or more will fail at compile time. For example:

use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
    .iter()
    .collect::<RleBuilder>()
    .created("foo")
    .created("bar") // Compile error
    .build()?;
Source§

impl<Name, Created, Rule> RleBuilder<Name, Created, RleBuilderNoComment, Rule>
where Name: RleBuilderName, Created: RleBuilderCreated, Rule: RleBuilderRule,

Source

pub fn comment( self, str: &str, ) -> RleBuilder<Name, Created, RleBuilderWithComment, Rule>

Set the comment. If the argument includes newlines, the instance of Rle built by build() includes multiple comment lines.

§Examples
use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
    .iter()
    .collect::<RleBuilder>()
    .comment("comment0\ncomment1")
    .build()?;
assert_eq!(target.comments().len(), 2);
assert_eq!(target.comments()[0], "#C comment0".to_string());
assert_eq!(target.comments()[1], "#C comment1".to_string());
§Errors

Code that calls comment() twice or more will fail at compile time. For example:

use life_backend::format::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
    .iter()
    .collect::<RleBuilder>()
    .comment("comment0")
    .comment("comment1")
    .build()?; // Compile error
Source§

impl<Name, Created, Comment> RleBuilder<Name, Created, Comment, RleBuilderNoRule>
where Name: RleBuilderName, Created: RleBuilderCreated, Comment: RleBuilderComment,

Source

pub fn rule( self, rule: Rule, ) -> RleBuilder<Name, Created, Comment, RleBuilderWithRule>

Set the rule.

§Examples
use life_backend::format::RleBuilder;
use life_backend::{Position, Rule};
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
    .iter()
    .collect::<RleBuilder>()
    .rule(Rule::conways_life())
    .build()?;
assert_eq!(*target.rule(), Rule::conways_life());
§Errors

Code that calls rule() twice or more will fail at compile time. For example:

use life_backend::format::RleBuilder;
use life_backend::{Position, Rule};
let pattern = [Position(1, 0), Position(0, 1)];
let target = pattern
    .iter()
    .collect::<RleBuilder>()
    .rule(Rule::conways_life())
    .rule(Rule::conways_life()) // Compile error
    .build()?;

Trait Implementations§

Source§

impl<Name, Created, Comment, Rule> Clone for RleBuilder<Name, Created, Comment, Rule>
where Name: RleBuilderName + Clone, Created: RleBuilderCreated + Clone, Comment: RleBuilderComment + Clone, Rule: RleBuilderRule + Clone,

Source§

fn clone(&self) -> RleBuilder<Name, Created, Comment, Rule>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Name, Created, Comment, Rule> Debug for RleBuilder<Name, Created, Comment, Rule>
where Name: RleBuilderName + Debug, Created: RleBuilderCreated + Debug, Comment: RleBuilderComment + Debug, Rule: RleBuilderRule + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RleBuilder<RleBuilderNoName, RleBuilderNoCreated, RleBuilderNoComment, RleBuilderNoRule>

Source§

fn default() -> Self

Returns the default value of the type, same as the return value of new().

Source§

impl<'a, Name, Created, Comment, RuleSpec> Extend<&'a Position<usize>> for RleBuilder<Name, Created, Comment, RuleSpec>
where Name: RleBuilderName, Created: RleBuilderCreated, Comment: RleBuilderComment, RuleSpec: RleBuilderRule,

Source§

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::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.iter();
let mut builder = RleBuilder::new();
builder.extend(iter);
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<Name, Created, Comment, RuleSpec> Extend<Position<usize>> for RleBuilder<Name, Created, Comment, RuleSpec>
where Name: RleBuilderName, Created: RleBuilderCreated, Comment: RleBuilderComment, RuleSpec: RleBuilderRule,

Source§

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::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.into_iter();
let mut builder = RleBuilder::new();
builder.extend(iter);
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a> FromIterator<&'a Position<usize>> for RleBuilder<RleBuilderNoName, RleBuilderNoCreated, RleBuilderNoComment, RleBuilderNoRule>

Source§

fn from_iter<T>(iter: T) -> Self
where 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::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.iter();
let builder: RleBuilder = iter.collect();
Source§

impl FromIterator<Position<usize>> for RleBuilder<RleBuilderNoName, RleBuilderNoCreated, RleBuilderNoComment, RleBuilderNoRule>

Source§

fn from_iter<T>(iter: T) -> Self
where 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::RleBuilder;
use life_backend::Position;
let pattern = [Position(1, 0), Position(0, 1)];
let iter = pattern.into_iter();
let builder: RleBuilder = iter.collect();

Auto Trait Implementations§

§

impl<Name, Created, Comment, Rule> Freeze for RleBuilder<Name, Created, Comment, Rule>
where Name: Freeze, Created: Freeze, Comment: Freeze, Rule: Freeze,

§

impl<Name, Created, Comment, Rule> RefUnwindSafe for RleBuilder<Name, Created, Comment, Rule>
where Name: RefUnwindSafe, Created: RefUnwindSafe, Comment: RefUnwindSafe, Rule: RefUnwindSafe,

§

impl<Name, Created, Comment, Rule> Send for RleBuilder<Name, Created, Comment, Rule>
where Name: Send, Created: Send, Comment: Send, Rule: Send,

§

impl<Name, Created, Comment, Rule> Sync for RleBuilder<Name, Created, Comment, Rule>
where Name: Sync, Created: Sync, Comment: Sync, Rule: Sync,

§

impl<Name, Created, Comment, Rule> Unpin for RleBuilder<Name, Created, Comment, Rule>
where Name: Unpin, Created: Unpin, Comment: Unpin, Rule: Unpin,

§

impl<Name, Created, Comment, Rule> UnwindSafe for RleBuilder<Name, Created, Comment, Rule>
where Name: UnwindSafe, Created: UnwindSafe, Comment: UnwindSafe, Rule: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.