Struct analog_literals::Cuboid[][src]

pub struct Cuboid {
    pub w: usize,
    pub h: usize,
    pub l: usize,
}
Expand description

A 3D Cuboid with a certain width, height, and length.

Example

Say you’re trying to solve the packing problem for fitting the largest number of dogecoin mining rigs in your 1.5 bedroom SF “apartment”. A 1x programmer would probably just use a couple of boring ’ol cOnStAnTs to define the length, width, and height of their dogecoin miners. Of course, you’re not a 10x programmer, so you use a 3D analog literal to visually represent the dimensions of your mining rigs:

const MINING_RIG: Cuboid = analog_literal! {
                     +------------------------------------------+
                    /                                          /|
                   /                                          / +
                  /                   /**/                   / /
                 /                   /**/                   / /
                /                   /**/                   / /
               /                                          / /
              /                                          / /
             /                                          / /
            /                                          / /
           /                                          / /
          /                                          / /
         /                                          / /
        /                                          / /
       /                                          / /
      /                                          / /
     /                                          / /
    +------------------------------------------+ /
    | /* -= dogecoin one =- */         /*(o)*/ |/
    +------------------------------------------+
};

assert_eq!(MINING_RIG.w, 21);
assert_eq!(MINING_RIG.h, 1);
assert_eq!(MINING_RIG.l, 16);

Fields

w: usize

Width of the literal (counts how many -- wide the analog literal is)

h: usize

Height of the literal (counts how many | tall the analog literal is)

l: usize

Length of the literal (counts how many / deep the analog literal is)

Implementations

impl Cuboid[src]

pub const fn volume(&self) -> usize[src]

Return the volume of the cuboid.

Note that Cuboid does not implement Eq nor Ord, as it would be rude to assume that two literals are the same just because they are rotationally transformed.

Just like Rectangle::area(), the underlying implementation of this method is highly complex and aggressively optimized. You could take a look, but you’ll be hard pressed to make heads or tails of it. You’ve been warned.

pub const fn top(&self) -> Rectangle[src]

Returns a Rectangle with the same dimensions as the top of the Cubiod.

Example


pub const CUBE_5_BY_2_BY_4: Cuboid = analog_literal! {
        +----------+
       /          /|
      /          / |
     /          /  +
    /          /  /
   +----------+  /
   |          | /
   |          |/
   +----------+
};
let top = analog_literal! {
    +----------+
    |          |
    |          |
    |          |
    |          |
    +----------+
};

assert_eq!(CUBE_5_BY_2_BY_4.top().w, top.w);
assert_eq!(CUBE_5_BY_2_BY_4.top().h, top.h);

pub const fn side(&self) -> Rectangle[src]

Returns a Rectangle with the same dimensions as the side of the Cubiod.

Example


pub const CUBE_5_BY_2_BY_4: Cuboid = analog_literal! {
        +----------+
       /          /|
      /          / |
     /          /  +
    /          /  /
   +----------+  /
   |          | /
   |          |/
   +----------+
};
let side = analog_literal! {
    +--------+
    |        |
    |        |
    +--------+
};

assert_eq!(CUBE_5_BY_2_BY_4.side().w, side.w);
assert_eq!(CUBE_5_BY_2_BY_4.side().h, side.h);

pub const fn front(&self) -> Rectangle[src]

Returns a Rectangle with the same dimensions as the front of the Cubiod.

Example


pub const CUBE_5_BY_2_BY_4: Cuboid = analog_literal! {
        +----------+
       /          /|
      /          / |
     /          /  +
    /          /  /
   +----------+  /
   |          | /
   |          |/
   +----------+
};
let front = analog_literal! {
    +----------+
    |          |
    |          |
    +----------+
};

assert_eq!(CUBE_5_BY_2_BY_4.front().w, front.w);
assert_eq!(CUBE_5_BY_2_BY_4.front().h, front.h);

Trait Implementations

impl Clone for Cuboid[src]

fn clone(&self) -> Cuboid[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Cuboid[src]

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

Formats the value using the given formatter. Read more

impl Copy for Cuboid[src]

Auto Trait Implementations

impl Send for Cuboid

impl Sync for Cuboid

impl Unpin for Cuboid

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.