Struct SplitedCode

Source
pub struct SplitedCode { /* private fields */ }
Expand description

A code that has been split into lines and characters for processing

§Example

use trees_lang::compile::{SplitedCode, split_code, CharWidthMode, CompileConfig, CodeCharacter};

// Split each character
let mut splited_code: SplitedCode = split_code(
  &vec![" ┌─".to_owned()],
  &CompileConfig {
    char_width: CharWidthMode::Mono
  }
);

// Get each characters' position
// (It is useful if char_width is not Mono)
assert_eq!(splited_code.enumurate_x(0).collect::<Vec<_>>(), vec![0, 1, 2]);

// Get char of target position
assert_eq!(splited_code.get(1, 0), Some(CodeCharacter {
  char: "┌".to_owned(), x: 1, len: 1
}));

Implementations§

Source§

impl SplitedCode

Source

pub fn get(&self, x: usize, y: usize) -> Option<CodeCharacter>

Retrieves a specific character at position (x, y) from the split code.

If the position is out of bounds or does not contain a character, returns None.

Source

pub fn get_slice_of_line( &self, x_min_exclusive: usize, x_max_exclusive: usize, y: usize, ) -> Option<String>

Retrieves a slice of characters from the specified line between x_min_exclusive and x_max_exclusive.

If the range is invalid or out of bounds, returns None.

Source

pub fn left_x(&self, x: usize, y: usize) -> Option<usize>

Retrieves the position of the character to the left of the given (x, y) position.

If there is no character to the left, returns None.

Source

pub fn right_x(&self, x: usize, y: usize) -> Option<usize>

Retrieves the position of the character to the right of the given (x, y) position.

If there is no character to the right, returns None.

Source

pub fn len_y(&self) -> usize

Returns the number of lines in the SplitedCode.

Source

pub fn enumurate_x(&self, y: usize) -> Box<dyn Iterator<Item = usize> + '_>

Enumerates the x-positions of all characters in the given line y.\

Trait Implementations§

Source§

impl Clone for SplitedCode

Source§

fn clone(&self) -> SplitedCode

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 Debug for SplitedCode

Source§

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

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

impl PartialEq for SplitedCode

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for SplitedCode

Source§

impl StructuralPartialEq for SplitedCode

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