pub struct FormatRegistry { /* private fields */ }Expand description
Implementations§
Source§impl FormatRegistry
impl FormatRegistry
Sourcepub fn register<F: Format + 'static>(&mut self, format: F)
pub fn register<F: Format + 'static>(&mut self, format: F)
Register a format
If a format with the same name already exists, it will be replaced.
Sourcepub fn list_formats(&self) -> Vec<String>
pub fn list_formats(&self) -> Vec<String>
List all available format names (sorted)
Sourcepub fn detect_format_from_filename(&self, filename: &str) -> Option<String>
pub fn detect_format_from_filename(&self, filename: &str) -> Option<String>
Detect format from filename based on file extension
Returns the format name if a matching extension is found, or None otherwise.
§Examples
ⓘ
let registry = FormatRegistry::default();
assert_eq!(registry.detect_format_from_filename("doc.lex"), Some("lex".to_string()));
assert_eq!(registry.detect_format_from_filename("doc.md"), Some("markdown".to_string()));
assert_eq!(registry.detect_format_from_filename("doc.unknown"), None);Sourcepub fn parse(&self, source: &str, format: &str) -> Result<Document, FormatError>
pub fn parse(&self, source: &str, format: &str) -> Result<Document, FormatError>
Parse source text using the specified format
Sourcepub fn serialize(
&self,
doc: &Document,
format: &str,
) -> Result<String, FormatError>
pub fn serialize( &self, doc: &Document, format: &str, ) -> Result<String, FormatError>
Serialize a document using the specified format
Sourcepub fn serialize_with_options(
&self,
doc: &Document,
format: &str,
options: &HashMap<String, String>,
) -> Result<SerializedDocument, FormatError>
pub fn serialize_with_options( &self, doc: &Document, format: &str, options: &HashMap<String, String>, ) -> Result<SerializedDocument, FormatError>
Serialize a document using the specified format and options
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a registry with default formats
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FormatRegistry
impl !RefUnwindSafe for FormatRegistry
impl Send for FormatRegistry
impl Sync for FormatRegistry
impl Unpin for FormatRegistry
impl UnsafeUnpin for FormatRegistry
impl !UnwindSafe for FormatRegistry
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more