Skip to main content

HangulBlock

Struct HangulBlock 

Source
pub struct HangulBlock {
    pub initial: Jamo,
    pub vowel: Jamo,
    pub final_optional: Option<Jamo>,
}
Expand description

A struct representing a composed Hangul syllable block, consisting of an initial Jamo, a vowel Jamo, and an optional final Jamo.

API:

use hangul_cd::block::{HangulBlock, HangulBlockDecompositionOptions};
use hangul_cd::jamo::{
    Jamo,
    JamoConsonantSingular,
    JamoVowelSingular,
    JamoUnicodeType,
};

// `HangulBlock`s can be directly constructed; to ensure validity,
// use a `BlockComposer` to build them instead. See `BlockComposer`
// documentation for more details.
let block = HangulBlock {
    initial: Jamo::from_compatibility_jamo('ㄱ').unwrap(),
    vowel: Jamo::from_compatibility_jamo('ㅏ').unwrap(),
    final_optional: None,
};

// Convert the block to a Hangul syllable character
let syllable = block.to_char().unwrap();
assert_eq!(syllable, '가');

// Decompose the block into its constituent Jamo characters as a tuple
assert_eq!(
    block.decomposed_tuple().unwrap(),
   (Some(Jamo::Consonant(JamoConsonantSingular::Giyeok)),
    None,
    Some(Jamo::Vowel(JamoVowelSingular::A)),
    None,
    None,
    None)
);

// Decompose the block into its constituent Jamo characters as a vector
let options = HangulBlockDecompositionOptions {
   decompose_composites: false,
   jamo_era: JamoUnicodeType::Modern,
};
let decomposed_vec = block.decomposed_vec(&options).unwrap();
assert_eq!(decomposed_vec, vec!['ᄀ', 'ᅡ']);

Fields§

§initial: Jamo§vowel: Jamo§final_optional: Option<Jamo>

Implementations§

Source§

impl HangulBlock

Source

pub fn to_char(&self) -> Result<char, BlockError>

Converts the HangulBlock into a composed Hangul syllable unicode character. Assumes all chars are valid Jamo.

Source

pub fn from_char(c: char) -> Result<Self, BlockError>

Creates a HangulBlock from a composed Hangul syllable unicode character.

Source

pub fn decomposed_tuple(&self) -> Result<DecomposedTuple, BlockError>

Decomposes the HangulBlock into its constituent Jamo characters. Returns a tuple containing six Option<Jamo> values representing the decomposed characters:

  • First initial consonant
  • Second initial consonant (if composite)
  • First vowel
  • Second vowel (if composite)
  • First final consonant (if any)
  • Second final consonant (if composite)
Source

pub fn decomposed_vec( &self, options: &HangulBlockDecompositionOptions, ) -> Result<Vec<char>, BlockError>

Decomposes the HangulBlock into its constituent Jamo characters as a vector of chars, according to the specified decomposition options.

Trait Implementations§

Source§

impl Debug for HangulBlock

Source§

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

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

impl Eq for HangulBlock

Source§

impl PartialEq for HangulBlock

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for HangulBlock

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