Brick

Struct Brick 

Source
pub struct Brick {
    pub id: Option<usize>,
    pub asset: BrickType,
    pub owner_index: Option<usize>,
    pub position: Position,
    pub rotation: Rotation,
    pub direction: Direction,
    pub collision: Collision,
    pub visible: bool,
    pub color: Color,
    pub material: BString,
    pub material_intensity: u8,
    pub components: Vec<Box<dyn BrdbComponent>>,
}

Fields§

§id: Option<usize>

An internal ID for linking bricks in the database.

§asset: BrickType§owner_index: Option<usize>§position: Position§rotation: Rotation§direction: Direction§collision: Collision§visible: bool§color: Color§material: BString§material_intensity: u8§components: Vec<Box<dyn BrdbComponent>>

Implementations§

Source§

impl Brick

Source

pub fn get_id(&self) -> Option<usize>

Returns the ID of the brick if it has one.

Source

pub fn with_id(self) -> Self

Sets the ID of the brick to a new value if it does not already have one.

Source

pub fn with_id_split(self) -> (Self, usize)

Sets the ID of the brick to a new value if it does not already have one.

Examples found in repository?
examples/write_wire.rs (line 20)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let path = PathBuf::from("./example_wire.brdb");
7
8    // Ensures the memory db can be created without errors
9    let db = Brdb::new(&path)?.into_reader();
10    let mut world = World::new();
11    world.meta.bundle.description = "Example World".to_string();
12
13    let (a, a_id) = Brick {
14        position: (0, 0, 1).into(),
15        color: (255, 0, 0).into(),
16        asset: assets::bricks::B_REROUTE,
17        ..Default::default()
18    }
19    .with_component(assets::components::Rerouter)
20    .with_id_split();
21    let (b, b_id) = Brick {
22        position: (15, 0, 1).into(),
23        color: (255, 0, 0).into(),
24        asset: assets::components::LogicGate::BoolNot.brick(),
25        ..Default::default()
26    }
27    .with_component(assets::components::LogicGate::BoolNot.component())
28    .with_id_split();
29
30    world.add_bricks([a, b]);
31    world.add_wire_connection(
32        assets::components::LogicGate::BoolNot.output_of(b_id),
33        assets::components::Rerouter::input_of(a_id),
34    );
35
36    db.save("example world", &world)?;
37
38    println!("{}", db.get_fs()?.render());
39
40    Ok(())
41}
Source

pub fn add_id(&mut self) -> usize

Adds an ID to the brick if it does not already have one.

Source

pub fn add_component(&mut self, component: impl BrdbComponent + 'static)

Adds a component to the brick. The component must implement the BrdbComponent trait.

Source

pub fn add_component_box(&mut self, component: Box<dyn BrdbComponent>)

Adds a component to the brick. The component must implement the BrdbComponent trait.

Source

pub fn add_components( &mut self, components: impl IntoIterator<Item = Box<dyn BrdbComponent>>, )

Adds multiple components to the brick. The components must implement the BrdbComponent trait.

Source

pub fn with_component(self, component: impl BrdbComponent + 'static) -> Self

Adds a component to the brick. The component must implement the BrdbComponent trait.

Examples found in repository?
examples/write_wire.rs (line 19)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let path = PathBuf::from("./example_wire.brdb");
7
8    // Ensures the memory db can be created without errors
9    let db = Brdb::new(&path)?.into_reader();
10    let mut world = World::new();
11    world.meta.bundle.description = "Example World".to_string();
12
13    let (a, a_id) = Brick {
14        position: (0, 0, 1).into(),
15        color: (255, 0, 0).into(),
16        asset: assets::bricks::B_REROUTE,
17        ..Default::default()
18    }
19    .with_component(assets::components::Rerouter)
20    .with_id_split();
21    let (b, b_id) = Brick {
22        position: (15, 0, 1).into(),
23        color: (255, 0, 0).into(),
24        asset: assets::components::LogicGate::BoolNot.brick(),
25        ..Default::default()
26    }
27    .with_component(assets::components::LogicGate::BoolNot.component())
28    .with_id_split();
29
30    world.add_bricks([a, b]);
31    world.add_wire_connection(
32        assets::components::LogicGate::BoolNot.output_of(b_id),
33        assets::components::Rerouter::input_of(a_id),
34    );
35
36    db.save("example world", &world)?;
37
38    println!("{}", db.get_fs()?.render());
39
40    Ok(())
41}
Source

pub fn with_component_box(self, component: Box<dyn BrdbComponent>) -> Self

Adds a component to the brick. The component must implement the BrdbComponent trait.

Source

pub fn with_components( self, components: impl IntoIterator<Item = Box<dyn BrdbComponent>>, ) -> Self

Adds multiple components to the brick. The components must implement the BrdbComponent trait.

Source

pub fn cmp(&self, other: &Self) -> Ordering

Source

pub fn set_material(&mut self, material: impl Into<BString>)

Sets the material of the brick.

Source

pub fn with_material(self, material: impl Into<BString>) -> Self

Sets the material of the brick.

Trait Implementations§

Source§

impl Clone for Brick

Source§

fn clone(&self) -> Self

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

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

Performs copy-assignment from source. Read more
Source§

impl Default for Brick

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Brick

§

impl !RefUnwindSafe for Brick

§

impl !Send for Brick

§

impl !Sync for Brick

§

impl Unpin for Brick

§

impl !UnwindSafe for Brick

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.