pub struct Streamer { /* private fields */ }Expand description
스트리밍 변환기.
조각을 넣으면 지금 안전하게 내보낼 수 있는 만큼만 돌려준다.
경계에 걸린 마크업(**굵 에서 끊긴 것)은 안에 남겨 두고 다음 조각을 기다린다.
이것이 이 라이브러리의 핵심이다 — 완성본 변환은 이미 남들이 푼 문제고,
경계 문제는 스트리밍을 하는 한 채널과 무관하게 생긴다.
§예
use mdwire::{Channel, Streamer};
let mut s = Streamer::new(Channel::TelegramHtml);
let mut out = String::new();
// 조각 경계가 `**` 한가운데를 지나가도 반쪽으로 나가지 않는다.
out.push_str(s.push("앞말 **굵"));
out.push_str(s.push("게** 뒷말"));
out.push_str(s.finish());
assert_eq!(out, "앞말 <b>굵게</b> 뒷말");Implementations§
Source§impl Streamer
impl Streamer
pub fn new(channel: Channel) -> Self
Sourcepub fn with_options(channel: Channel, options: Options) -> Self
pub fn with_options(channel: Channel, options: Options) -> Self
옵션을 주고 만든다 — 입력 방언 따위.
Sourcepub fn push(&mut self, chunk: &str) -> &str
pub fn push(&mut self, chunk: &str) -> &str
조각을 밀어 넣고, 지금 내보낼 수 있는 출력을 받는다.
돌려주는 슬라이스는 다음 호출 전까지만 유효하다. 할당을 아예 없애려면
Streamer::push_into 를 쓴다 — 둘은 같은 코드를 부른다(SPEC.md 5절).
Sourcepub fn push_into(&mut self, chunk: &str, out: &mut String)
pub fn push_into(&mut self, chunk: &str, out: &mut String)
호출자 버퍼에 직접 쓴다. 정본 서명 — 조각당 할당이 0 이다.
Sourcepub fn finish_into(&mut self, out: &mut String)
pub fn finish_into(&mut self, out: &mut String)
Streamer::finish 의 무할당 판.
Sourcepub fn close_open(&self, out: &mut String)
pub fn close_open(&self, out: &mut String)
지금까지 받은 것을 그대로 보내도 되게 만든다. 상태는 건드리지 않으므로 붙인 뒤에도 스트리밍은 이어진다.
강조는 짝이 맞을 때까지 안에 붙들려 있어 이미 균형이 맞지만, 블록의 여는
마크업(<blockquote>·<pre>·헤딩의 <b>)은 블록이 끝나기 전에 나간다 —
코드블록이 끝날 때까지 출력을 멈추면 스트리밍이 아니기 때문이다. 누적본을
중간에 채널로 보내는 쪽(토큰이 오는 대로 메시지를 편집하는 경우)은 보내기
직전에 이걸 덧붙인다. 누적본 자체에는 넣지 않는다 — 다음 조각이 이어진다.
use mdwire::{Channel, Streamer};
let mut s = Streamer::new(Channel::TelegramHtml);
let mut acc = String::new();
s.push_into("> 인용이 시작되고", &mut acc);
let mut snapshot = acc.clone();
s.close_open(&mut snapshot); // 지금 보내도 되는 모양
assert_eq!(snapshot, "<blockquote>인용이 시작되고</blockquote>");
s.push_into("\n> 이어진다\n", &mut acc); // 누적본은 그대로 이어진다
s.finish_into(&mut acc);
assert_eq!(acc, "<blockquote>인용이 시작되고\n이어진다</blockquote>");Auto Trait Implementations§
impl Freeze for Streamer
impl RefUnwindSafe for Streamer
impl Send for Streamer
impl Sync for Streamer
impl Unpin for Streamer
impl UnsafeUnpin for Streamer
impl UnwindSafe for Streamer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more