[][src]Struct sejong::Buffer

pub struct Buffer(_);

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

Implementations

impl Buffer[src]

pub fn with_capacity(cap: usize) -> Self[src]

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

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

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(), "아");

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

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());

pub fn out(&mut self) -> String[src]

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(), "");

pub fn to_string(&self) -> String[src]

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

impl Clone for Buffer[src]

impl Default for Buffer[src]

impl Into<String> for Buffer[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

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.