Struct Buffer

Source
pub struct Buffer(/* private fields */);
Expand description

It is simply a vector of Syllable(private struct). See its methods to find examples.

Implementations§

Source§

impl Buffer

Source

pub fn with_capacity(cap: usize) -> Self

Initialize the buffer with a capacity. Remember the capacity is for Syllable(private struct). It is a capacity for input like u8 and char.

Source

pub fn put<T>(&mut self, byte_candidate: T) -> Option<T>
where T: TryInto<Byte, Error = T>,

Put a byte(‘u8’) or a ‘char’ into the buffer. A valid byte_candidate should be meets all of the following requirements: 1. a valid English letter in ASCII chart. 2. this English letter must has a corresponding valid modern Hangul Jamo as in a standard Korean 2-set(QWERT) keyboard. When a byte_candidate is accepted by the buffer, this will return None. When a byte_candidate can’t be matched with a valid modern Hangul Jamo, this will return Some(byte_candidate).

§Example
use sejong::{Buffer, Byte};
let mut buf = Buffer::default();
assert!(buf.put(Byte::NG as u8).is_none());
assert!(buf.put('k').is_none());
assert_eq!(buf.put('M').unwrap(), 'M');
assert_eq!(buf.to_string(), "아");
Source

pub fn pop(&mut self) -> Option<()>

Removes the last single Jamo put. Returns Some(()) when it succeeds. Returns None when it fails. It fails when buffer is empty.

§Example
use sejong::{Buffer, Byte};
let mut buf = Buffer::default();
buf.put(Byte::NG as u8);
buf.put(Byte::A as u8);
buf.put(Byte::N as u8);
assert_eq!(buf.to_string(), "안");
assert_eq!(buf.pop().unwrap(), ());
assert_eq!(buf.to_string(), "아");
assert_eq!(buf.pop().unwrap(), ());
assert_eq!(buf.pop().unwrap(), ());
assert_eq!(buf.to_string(), "");
assert!(buf.pop().is_none());
Source

pub fn out(&mut self) -> String

Output the buffer as a UTF-32 string. Calling this method clears the buffer. If buffer needs to be preserved, use Buffer::to_string.

§Example
use sejong::{Buffer, Byte};
let mut buf = Buffer::default();
buf.put(Byte::NG as u8);
buf.put(Byte::A as u8);
buf.put(Byte::N as u8);
assert_eq!(buf.out(), "안");
assert_eq!(buf.to_string(), "");
Source

pub fn to_string(&self) -> String

Output the buffer as a UTF-32 string. It is very similar with Buffer::out. But to_string() doesn’t clear the buffer. It always reflect the current state of the buffer.

§Example
use sejong::{Buffer, Byte};
let mut buf = Buffer::default();
buf.put(Byte::NG as u8);
buf.put(Byte::A as u8);
buf.put(Byte::N as u8);
assert_eq!(buf.to_string(), "안");
assert_eq!(buf.to_string(), "안");

Trait Implementations§

Source§

impl Clone for Buffer

Source§

fn clone(&self) -> Buffer

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 Default for Buffer

Source§

fn default() -> Self

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

impl Into<String> for Buffer

Source§

fn into(self) -> String

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl Freeze for Buffer

§

impl RefUnwindSafe for Buffer

§

impl Send for Buffer

§

impl Sync for Buffer

§

impl Unpin for Buffer

§

impl UnwindSafe for Buffer

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.