pub enum Feed<T> {
Complete {
entry: Entry,
value: T,
},
Incomplete,
Empty,
}Expand description
The outcome of feeding one line to a Session.
A host’s read loop matches on it: evaluate and print on Complete, show a
continuation prompt on Incomplete, and simply prompt again on Empty.
§Examples
use repl_lang::{Feed, Session, Status};
let mut session = Session::new();
let pipeline = |input: repl_lang::Input<'_>| {
let open = input.text().matches('{').count();
let close = input.text().matches('}').count();
if open > close { Status::Incomplete } else { Status::Complete(input.text().len()) }
};
let mut transcript = Vec::new();
for line in ["", "f {", " x", "}"] {
let prompt = if session.is_pending() { "... " } else { ">>> " };
match session.feed(line, pipeline)? {
Feed::Complete { entry, value } => {
transcript.push(format!("{prompt}{line} -> entry {} ({value} bytes)", entry.number()));
}
Feed::Incomplete => transcript.push(format!("{prompt}{line}")),
Feed::Empty => transcript.push(prompt.trim_end().to_owned()),
}
}
assert_eq!(transcript, [">>>", ">>> f {", "... x", "... } -> entry 1 (10 bytes)"]);Variants§
Complete
The pipeline accepted the entry. It is now committed to the session’s
source map, so diagnostics carrying its spans render against
Session::sources.
Fields
§
value: TWhat the pipeline returned in Status::Complete.
Incomplete
The pipeline needs more input. The line is kept, and the next one is appended to it.
Empty
The line was blank and no entry was in progress, so there was nothing to evaluate. The pipeline was not called and no entry number was used.
Trait Implementations§
impl<T: Copy> Copy for Feed<T>
impl<T: Eq> Eq for Feed<T>
impl<T: PartialEq> StructuralPartialEq for Feed<T>
Auto Trait Implementations§
impl<T> Forget for Feed<T>
impl<T> Freeze for Feed<T>where
T: Freeze,
impl<T> Move for Feed<T>
impl<T> RefUnwindSafe for Feed<T>where
T: RefUnwindSafe,
impl<T> Send for Feed<T>where
T: Send,
impl<T> Sync for Feed<T>where
T: Sync,
impl<T> Unpin for Feed<T>where
T: Unpin,
impl<T> UnsafeUnpin for Feed<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Feed<T>where
T: UnwindSafe,
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