pub struct CreateBuilder { /* private fields */ }Expand description
Build a create mutation. Writes a new .md file under folder with
name name (the .md extension is appended automatically).
Frontmatter is composed in three layers, in order of precedence:
- Template — if
template(path)is set, the template’s frontmatter is parsed as the base. Template body is preserved. --setoverrides — anything set viaset()overrides matching template fields.- Schema defaults — when
with_schema(schema)is supplied, everydefault:/default_expr:whose field isn’t already set by the template or--setis applied.
After composition, schema’s required: list is checked. Missing
required fields surface as MutationErrors in the report, with the
file NOT written.
Implementations§
Source§impl CreateBuilder
impl CreateBuilder
pub fn new(folder: impl Into<String>, name: impl Into<String>) -> Self
Sourcepub fn body(self, text: impl Into<String>) -> Self
pub fn body(self, text: impl Into<String>) -> Self
Set the body content. Overrides the template’s body (if any) and
the default # {name} placeholder. Written verbatim.
Sourcepub fn template(self, path: impl Into<String>) -> Self
pub fn template(self, path: impl Into<String>) -> Self
Path to a template file, relative to the vault root. The template’s frontmatter forms the base of the new note; its body is preserved.
Sourcepub fn set(self, field: impl Into<String>, value: Value) -> Self
pub fn set(self, field: impl Into<String>, value: Value) -> Self
Set (or override) a frontmatter field. Layered on top of the template; layered under schema defaults.
Sourcepub fn with_schema(self, schema: CollectionSchema) -> Self
pub fn with_schema(self, schema: CollectionSchema) -> Self
Attach a single collection schema. Convenience wrapper that
builds a one-collection [VaultSchema] and forwards to
Self::with_vault_schema. The compute path is identical —
applicable_collections will pick this collection iff its
folder is == or ancestor of the builder’s target folder
and the filter (if any) matches the projected record.
Sourcepub fn with_vault_schema(self, schema: VaultSchema) -> Self
pub fn with_vault_schema(self, schema: VaultSchema) -> Self
Attach the vault-wide schema. Every collection whose folder
covers (== or is an ancestor of) the builder’s target folder
AND whose filter: matches the projected record contributes:
its default: / default_expr: fields layer in shallowest-
folder first (deeper folders override), and the post-defaults
record must satisfy all applicable collections — strict mode.
pub fn write_options(self, opts: WriteOptions) -> Self
pub fn fsync(self, yes: bool) -> Self
Sourcepub fn plan(&self, vault: &Vault) -> Result<MutationReport>
pub fn plan(&self, vault: &Vault) -> Result<MutationReport>
Compute the planned change without writing.
Sourcepub fn plan_with_content(
&self,
vault: &Vault,
) -> Result<(MutationReport, Option<String>)>
pub fn plan_with_content( &self, vault: &Vault, ) -> Result<(MutationReport, Option<String>)>
Plan and also return the file content that would be written.
Used by the CLI’s --dry-run for create — the post-defaults
frontmatter is the value of the preview.
Sourcepub fn execute(self, vault: &Vault) -> Result<MutationReport>
pub fn execute(self, vault: &Vault) -> Result<MutationReport>
Plan, then write the file atomically. Holds the vault-scoped lock so concurrent creates against the same vault serialise cleanly.
Trait Implementations§
Source§impl Clone for CreateBuilder
impl Clone for CreateBuilder
Source§fn clone(&self) -> CreateBuilder
fn clone(&self) -> CreateBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more