pub enum Format {
Toml,
Json,
Unknown,
}Expand description
Supported configuration file formats.
Each variant corresponds to a specific file format and provides parsing capabilities.
Variants§
Toml
TOML format (requires toml feature).
Json
JSON format (requires json feature).
Unknown
Unknown or unsupported format.
Implementations§
Source§impl Format
impl Format
Sourcepub const fn alternate_extensions(&self) -> &'static [&'static str]
pub const fn alternate_extensions(&self) -> &'static [&'static str]
Get additional file extensions for this format.
Sourcepub fn from_extension(ext: &str) -> Option<Self>
pub fn from_extension(ext: &str) -> Option<Self>
Sourcepub fn from_content(content: &str) -> Option<Self>
pub fn from_content(content: &str) -> Option<Self>
Sourcepub fn parse(&self, content: &str) -> Result<ParsedContent>
pub fn parse(&self, content: &str) -> Result<ParsedContent>
Parse content string into a generic value.
§Errors
Returns a SourceError::ParseFailed if parsing fails.
§Example
ⓘ
use cfgmatic_source::domain::Format;
let content = r#"host = "localhost""#;
let parsed = Format::Toml.parse(content)?;Sourcepub fn parse_as<T: DeserializeOwned>(&self, content: &str) -> Result<T>
pub fn parse_as<T: DeserializeOwned>(&self, content: &str) -> Result<T>
Parse content into a specific type.
§Errors
Returns a SourceError::ParseFailed if parsing or deserialization fails.
§Example
ⓘ
use cfgmatic_source::domain::Format;
use serde::Deserialize;
#[derive(Deserialize)]
struct Config {
host: String,
}
let content = r#"host = "localhost""#;
let config: Config = Format::Toml.parse_as(content)?;Trait Implementations§
Source§impl<'de> Deserialize<'de> for Format
impl<'de> Deserialize<'de> for Format
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Format
impl Eq for Format
impl StructuralPartialEq for Format
Auto Trait Implementations§
impl Freeze for Format
impl RefUnwindSafe for Format
impl Send for Format
impl Sync for Format
impl Unpin for Format
impl UnsafeUnpin for Format
impl UnwindSafe 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