extern crate alloc;
use crate::ParseError;
use alloc::collections::VecDeque;
use facet_reflect::Span;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SavePoint(pub u64);
impl SavePoint {
pub fn new(id: u64) -> Self {
Self(id)
}
}
pub trait FormatParser<'de> {
fn next_event(&mut self) -> Result<Option<crate::ParseEvent<'de>>, ParseError>;
fn next_events(
&mut self,
buf: &mut VecDeque<crate::ParseEvent<'de>>,
limit: usize,
) -> Result<usize, ParseError> {
let mut count = 0;
while count < limit {
match self.next_event()? {
Some(event) => {
buf.push_back(event);
count += 1;
}
None => break,
}
}
Ok(count)
}
fn peek_event(&mut self) -> Result<Option<crate::ParseEvent<'de>>, ParseError>;
fn skip_value(&mut self) -> Result<(), ParseError>;
fn save(&mut self) -> SavePoint;
fn restore(&mut self, save_point: SavePoint);
fn capture_raw(&mut self) -> Result<Option<&'de str>, ParseError> {
self.skip_value()?;
Ok(None)
}
fn input(&self) -> Option<&'de [u8]> {
None
}
fn raw_capture_shape(&self) -> Option<&'static facet_core::Shape> {
None
}
fn is_self_describing(&self) -> bool {
true }
fn hint_struct_fields(&mut self, _num_fields: usize) {
}
fn hint_scalar_type(&mut self, _hint: ScalarTypeHint) {
}
fn hint_sequence(&mut self) {
}
fn hint_byte_sequence(&mut self) -> bool {
false
}
fn hint_remaining_byte_sequence(&mut self) -> bool {
false
}
fn hint_array(&mut self, _len: usize) {
}
fn hint_option(&mut self) {
}
fn hint_map(&mut self) {
}
fn hint_dynamic_value(&mut self) {
}
fn hint_enum(&mut self, _variants: &[EnumVariantHint]) {
}
fn hint_opaque_scalar(
&mut self,
_type_identifier: &'static str,
_shape: &'static facet_core::Shape,
) -> bool {
false
}
fn current_span(&self) -> Option<Span> {
None
}
fn format_namespace(&self) -> Option<&'static str> {
None
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EnumVariantHint {
pub name: &'static str,
pub kind: facet_core::StructKind,
pub field_count: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ScalarTypeHint {
Bool,
U8,
U16,
U32,
U64,
U128,
Usize,
I8,
I16,
I32,
I64,
I128,
Isize,
F32,
F64,
String,
Bytes,
Char,
}
#[cfg(feature = "jit")]
pub trait FormatJitParser<'de>: FormatParser<'de> {
type FormatJit: crate::jit::JitFormat;
fn jit_input(&self) -> &'de [u8];
fn jit_pos(&self) -> Option<usize>;
fn jit_set_pos(&mut self, pos: usize);
fn jit_format(&self) -> Self::FormatJit;
fn jit_max_collection_elements(&self) -> Option<u64> {
None
}
fn jit_error(&self, input: &'de [u8], error_pos: usize, error_code: i32) -> ParseError;
}