pub struct ManifestDocument { /* private fields */ }Expand description
A lossless module.json document paired with its validated manifest view.
This value stays in memory until a caller writes Self::to_bytes back to
the exact module.json path chosen by super::ModuleProject. Each edit
preserves unrelated extension fields and keeps Self::manifest in step
with the document; an edit that cannot be represented fails before either
one changes.
use std::path::PathBuf;
use wdl_modules::dependency::DependencySource;
use wdl_modules::project::ManifestDocument;
let mut document = ManifestDocument::parse(
br#"{
"name": "spellbook",
"license": "MIT",
"x-extra": { "kept": true }
}"#,
)?;
document.insert_dependency(
"helpers",
&DependencySource::LocalPath {
path: PathBuf::from("../helpers"),
extra: serde_json::Map::new(),
},
)?;
let serialized = String::from_utf8(document.to_bytes()?)?;
assert!(serialized.contains(r#""helpers""#));
let dependency_name = "helpers".parse()?;
assert_eq!(
document.manifest().dependencies.get(&dependency_name),
Some(&DependencySource::LocalPath {
path: PathBuf::from("../helpers"),
extra: serde_json::Map::new(),
})
);Implementations§
Source§impl ManifestDocument
impl ManifestDocument
Sourcepub fn parse(bytes: &[u8]) -> Result<Self, ManifestDocumentError>
pub fn parse(bytes: &[u8]) -> Result<Self, ManifestDocumentError>
Parses raw module.json bytes without discarding unknown extension
fields.
Sourcepub fn manifest(&self) -> &Manifest
pub fn manifest(&self) -> &Manifest
Returns the validated manifest view for the latest accepted
module.json bytes.
Sourcepub fn insert_dependency(
&mut self,
name: &str,
source: &DependencySource,
) -> Result<(), ManifestDocumentError>
pub fn insert_dependency( &mut self, name: &str, source: &DependencySource, ) -> Result<(), ManifestDocumentError>
Inserts or replaces one dependency entry in module.json.
Unrelated manifest fields and dependency extension fields stay intact. The name is parsed and the source serialized before the document changes, so a rejected edit leaves both the document and the validated view untouched.
Sourcepub fn remove_dependency(
&mut self,
name: &str,
) -> Result<bool, ManifestDocumentError>
pub fn remove_dependency( &mut self, name: &str, ) -> Result<bool, ManifestDocumentError>
Removes a dependency from module.json when present.
Returns true when a dependency was removed, and leaves the document
untouched when the dependency is absent.
Trait Implementations§
Source§impl Clone for ManifestDocument
impl Clone for ManifestDocument
Source§fn clone(&self) -> ManifestDocument
fn clone(&self) -> ManifestDocument
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more