Skip to content

Commit

Permalink
Merge pull request #68 from axodotdev/toml_edit_export
Browse files Browse the repository at this point in the history
chore: reexport toml_edit::Document
  • Loading branch information
mistydemeo authored Oct 31, 2023
2 parents ff57102 + 913b6fc commit a785bdc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tar = { version = "0.4.38", optional = true }
zip = { version = "0.6.4", optional = true }
flate2 = { version = "1.0.25", optional = true }
xz2 = { version = "0.1.7", optional = true }
toml_edit = { version = "0.19.9", optional = true }
toml_edit = { version = "0.20.7", optional = true }
walkdir = "2.3.3"

[dev-dependencies]
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ use error::Result;
pub use local::LocalAsset;
#[cfg(feature = "remote")]
pub use remote::RemoteAsset;
#[cfg(feature = "json-serde")]
pub use serde_json;
pub use source::SourceFile;
pub use spanned::Spanned;
#[cfg(feature = "toml-serde")]
pub use toml;
#[cfg(feature = "toml-edit")]
pub use toml_edit;

/// An asset can either be a local asset, which is designated by a path on the
/// local file system, or a remote asset, which is designated by an http or
Expand Down
27 changes: 15 additions & 12 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ use miette::{MietteSpanContents, SourceCode, SourceSpan};

use crate::{error::*, LocalAsset};

#[cfg(feature = "toml-edit")]
use crate::toml_edit::Document;

#[cfg(feature = "json-serde")]
use crate::serde_json;

/// The inner contents of a [`SourceFile`][].
#[derive(Eq, PartialEq)]
struct SourceFileInner {
Expand Down Expand Up @@ -112,18 +118,15 @@ impl SourceFile {

/// Try to deserialize the contents of the SourceFile as a toml_edit Document
#[cfg(feature = "toml-edit")]
pub fn deserialize_toml_edit(&self) -> Result<toml_edit::Document> {
let toml = self
.contents()
.parse::<toml_edit::Document>()
.map_err(|details| {
let span = details.span().map(SourceSpan::from);
AxoassetError::TomlEdit {
source: self.clone(),
span,
details,
}
})?;
pub fn deserialize_toml_edit(&self) -> Result<Document> {
let toml = self.contents().parse::<Document>().map_err(|details| {
let span = details.span().map(SourceSpan::from);
AxoassetError::TomlEdit {
source: self.clone(),
span,
details,
}
})?;
Ok(toml)
}

Expand Down

0 comments on commit a785bdc

Please sign in to comment.