pub struct Format {
pub name: String,
pub read: Arc<ReadFn>,
pub write: Arc<WriteFn>,
pub check: Option<Arc<CheckFn>>,
}Expand description
A registered format: a name plus read/write callables and an
optional check. Mirrors Python’s Format NamedTuple (name, read, write, check); a plugin registered with Format::new alone has no
check, and crate::document::Doc::check_format errors cleanly (not
a panic) if invoked on it – matching
test_plugin_without_check_raises_on_check_format.
Fields§
§name: StringRegistered format name (e.g. "json").
read: Arc<ReadFn>Text to Doc reader callable.
write: Arc<WriteFn>Doc to text writer callable.
check: Option<Arc<CheckFn>>Optional Doc write simulation callable.
Implementations§
Source§impl Format
impl Format
Sourcepub fn new(
name: impl Into<String>,
read: impl Fn(&str) -> Result<Doc, OmnistError> + Send + Sync + 'static,
write: impl Fn(&Doc) -> Result<String, OmnistError> + Send + Sync + 'static,
) -> Self
pub fn new( name: impl Into<String>, read: impl Fn(&str) -> Result<Doc, OmnistError> + Send + Sync + 'static, write: impl Fn(&Doc) -> Result<String, OmnistError> + Send + Sync + 'static, ) -> Self
Build a Format with no check callable. Use Format::with_check
to attach one.
Sourcepub fn with_check(
self,
check: impl Fn(&Doc) -> WriteReport + Send + Sync + 'static,
) -> Self
pub fn with_check( self, check: impl Fn(&Doc) -> WriteReport + Send + Sync + 'static, ) -> Self
Attach a check callable, returning self for chaining.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Format
impl !UnwindSafe for Format
impl Freeze for Format
impl Send for Format
impl Sync for Format
impl Unpin for Format
impl UnsafeUnpin for Format
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