Struct dapol::Height

source ·
pub struct Height(/* private fields */);
Expand description

Abstraction for the height of the tree.

Example:

use dapol::Height;
use std::str::FromStr;

let height = Height::default();
let height = Height::expect_from(8u8);
let height = Height::from_str("8");

Implementations§

source§

impl Height

source

pub fn expect_from(int: u8) -> Self

Create a Height object from int.

panics if int is greater than MAX_HEIGHT or less than MIN_HEIGHT.

Note that if we try to implement the From trait then we have a collision.

source

pub fn from_y_coord(y_coord: u8) -> Self

Return the height for the given y-coord.

Why the offset? y starts from 0 but height starts from 1. See [crate][binary_tree][Coordinate] for more details.

source

pub fn as_y_coord(&self) -> u8

Return the y-coord for the given height.

Why the offset? y starts from 0 but height starts from 1. See [crate][binary_tree][Coordinate] for more details.

source

pub fn as_u8(&self) -> u8

Return the underlying integer value.

source

pub fn as_usize(&self) -> usize

Return the underlying integer value as type usize.

source

pub fn as_u32(&self) -> u32

Return the underlying integer value as type u32.

source

pub fn as_u64(&self) -> u64

Return the underlying integer value as type u64.

source

pub fn as_f64(&self) -> f64

Return the underlying integer value as type f64.

source

pub fn max_bottom_layer_nodes(&self) -> u64

The maximum number of leaf nodes on the bottom layer of the binary tree.

$$\text{max} = 2^{\text{height}-1}$$

Trait Implementations§

source§

impl Clone for Height

source§

fn clone(&self) -> Height

Returns a copy 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 Debug for Height

source§

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

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

impl Default for Height

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Height

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Height> for OsStr

source§

fn from(height: Height) -> OsStr

Converts to this type from the input type.
source§

impl FromStr for Height

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Constructor that takes in a string slice. If the length of the str is greater than the max then Err is returned.

§

type Err = HeightError

The associated error which can be returned from parsing.
source§

impl PartialEq for Height

source§

fn eq(&self, other: &Height) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Height

source§

fn partial_cmp(&self, other: &Height) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Height

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<u8> for Height

Create a Height object from int.

Returns an error if int is greater than MAX_HEIGHT or less than MIN_HEIGHT.

§

type Error = HeightError

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

fn try_from(int: u8) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Height

source§

impl StructuralPartialEq for Height

Auto Trait Implementations§

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
§

impl<T> Clear for T
where T: InitializableFromZeroed + ?Sized,

§

fn clear(&mut self)

Completely overwrites this value.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> InitializableFromZeroed for T
where T: Default,

§

unsafe fn initialize(place: *mut T)

Called to initialize a place to a valid value, after it is set to all-bits-zero. Read more
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.

§

impl<I> IntoResettable<OsStr> for I
where I: Into<OsStr>,

§

fn into_resettable(self) -> Resettable<OsStr>

Convert to the intended resettable type
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,