[−][src]Struct sejong::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]
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(), "아");
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
Auto Trait Implementations
impl RefUnwindSafe for Buffer
[src]
impl Send for Buffer
[src]
impl Sync for Buffer
[src]
impl Unpin for Buffer
[src]
impl UnwindSafe for Buffer
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,