pub struct LayerEdit<'a> { /* private fields */ }Expand description
The authoring view of a Layer handed to an edit closure
— the only surface through which a layer is mutated.
Derefs to the Layer for reads, and exposes the layer’s authoring
operations directly. A layer’s commit and rollback are deliberately absent:
the edit commits when the closure returns and rolls back on its error or a
panic, so an edit can never be left staged-but-uncommitted, and a multi-layer
edit stays atomic across its layers.
Implementations§
Source§impl LayerEdit<'_>
impl LayerEdit<'_>
Sourcepub fn data_mut(&mut self) -> &mut dyn AbstractData
pub fn data_mut(&mut self) -> &mut dyn AbstractData
Borrow the layer’s backing data mutably for authoring; the write stages in
the copy-on-write overlay and commits with the enclosing edit. The typed
spec constructors (PrimSpec::new and friends)
write through this.
Sourcepub fn remove_spec(&mut self, path: &Path) -> Result<bool, AuthoringError>
pub fn remove_spec(&mut self, path: &Path) -> Result<bool, AuthoringError>
Remove the spec at path. Removing a prim also erases its descendant specs
and drops the leaf name from the owning prim’s child-name list. Returns
Ok(true) when a spec was present and removed.
Sourcepub fn prim_mut(
&mut self,
path: impl IntoPath,
) -> Result<Option<PrimSpecMut<'_>>, PathParseError>
pub fn prim_mut( &mut self, path: impl IntoPath, ) -> Result<Option<PrimSpecMut<'_>>, PathParseError>
Mutably look up the prim spec at path.
Sourcepub fn attribute_mut(
&mut self,
path: impl IntoPath,
) -> Result<Option<AttributeSpecMut<'_>>, PathParseError>
pub fn attribute_mut( &mut self, path: impl IntoPath, ) -> Result<Option<AttributeSpecMut<'_>>, PathParseError>
Mutably look up the attribute spec at a property path.
Sourcepub fn relationship_mut(
&mut self,
path: impl IntoPath,
) -> Result<Option<RelationshipSpecMut<'_>>, PathParseError>
pub fn relationship_mut( &mut self, path: impl IntoPath, ) -> Result<Option<RelationshipSpecMut<'_>>, PathParseError>
Mutably look up the relationship spec at a property path.
Sourcepub fn pseudo_root_mut(
&mut self,
) -> Result<PseudoRootSpecMut<'_>, AuthoringError>
pub fn pseudo_root_mut( &mut self, ) -> Result<PseudoRootSpecMut<'_>, AuthoringError>
Mutably view the root pseudo-spec, which carries layer-wide metadata
(defaultPrim, subLayers, time codes, …). The spec is created on first
access if missing.
Sourcepub fn set_default_prim(
&mut self,
name: impl Into<String>,
) -> Result<(), AuthoringError>
pub fn set_default_prim( &mut self, name: impl Into<String>, ) -> Result<(), AuthoringError>
Set the layer’s defaultPrim metadata to name — a prim identifier, a
nested prim path, or either spelled absolutely ("World",
"World/Char", "/World/Char"). The token is stored as given;
default_prim_path reads both spellings.
This is a checked authoring API, which is a deliberate divergence: C++
SdfLayer::SetDefaultPrim stores any token and defers every check to
GetDefaultPrimAsPath. Rejecting here keeps a value that names no prim
out of the layer in the first place; the spec-tier
PseudoRootSpecMut::set_default_prim remains the unvalidated escape
hatch for round-tripping data verbatim.
Sourcepub fn clear_default_prim(&mut self) -> Result<(), AuthoringError>
pub fn clear_default_prim(&mut self) -> Result<(), AuthoringError>
Remove the layer’s defaultPrim metadata. No-op when no pseudo-root spec
exists.
Sourcepub fn set_relocates(
&mut self,
relocates: RelocateList,
) -> Result<(), AuthoringError>
pub fn set_relocates( &mut self, relocates: RelocateList, ) -> Result<(), AuthoringError>
Set the layer’s entire list of namespace relocations. An empty list authors
an explicit “no relocates” opinion; use clear_relocates
to remove the opinion entirely.
Sourcepub fn clear_relocates(&mut self) -> Result<(), AuthoringError>
pub fn clear_relocates(&mut self) -> Result<(), AuthoringError>
Clear the layer’s relocates opinion. No-op when no pseudo-root spec exists.
Sourcepub fn set_expression_variables(
&mut self,
vars: HashMap<String, Value>,
) -> Result<(), AuthoringError>
pub fn set_expression_variables( &mut self, vars: HashMap<String, Value>, ) -> Result<(), AuthoringError>
Replace the layer’s expressionVariables dictionary, the values an
${VAR} expression resolves against (see
PseudoRootSpec::set_expression_variables).
Sourcepub fn clear_expression_variables(&mut self) -> Result<(), AuthoringError>
pub fn clear_expression_variables(&mut self) -> Result<(), AuthoringError>
Clear the layer’s expressionVariables opinion. No-op when no pseudo-root spec exists.
Sourcepub fn set_start_time_code(&mut self, time: f64) -> Result<(), AuthoringError>
pub fn set_start_time_code(&mut self, time: f64) -> Result<(), AuthoringError>
Set the layer’s startTimeCode.
Sourcepub fn clear_start_time_code(&mut self) -> Result<(), AuthoringError>
pub fn clear_start_time_code(&mut self) -> Result<(), AuthoringError>
Clear the layer’s startTimeCode opinion. No-op when no pseudo-root spec exists.
Sourcepub fn set_end_time_code(&mut self, time: f64) -> Result<(), AuthoringError>
pub fn set_end_time_code(&mut self, time: f64) -> Result<(), AuthoringError>
Set the layer’s endTimeCode.
Sourcepub fn clear_end_time_code(&mut self) -> Result<(), AuthoringError>
pub fn clear_end_time_code(&mut self) -> Result<(), AuthoringError>
Clear the layer’s endTimeCode opinion. No-op when no pseudo-root spec exists.
Sourcepub fn set_time_codes_per_second(
&mut self,
rate: f64,
) -> Result<(), AuthoringError>
pub fn set_time_codes_per_second( &mut self, rate: f64, ) -> Result<(), AuthoringError>
Set the layer’s timeCodesPerSecond.
Sourcepub fn clear_time_codes_per_second(&mut self) -> Result<(), AuthoringError>
pub fn clear_time_codes_per_second(&mut self) -> Result<(), AuthoringError>
Clear the layer’s timeCodesPerSecond opinion. No-op when no pseudo-root spec exists.
Sourcepub fn set_frames_per_second(&mut self, rate: f64) -> Result<(), AuthoringError>
pub fn set_frames_per_second(&mut self, rate: f64) -> Result<(), AuthoringError>
Set the layer’s framesPerSecond.
Sourcepub fn clear_frames_per_second(&mut self) -> Result<(), AuthoringError>
pub fn clear_frames_per_second(&mut self) -> Result<(), AuthoringError>
Clear the layer’s framesPerSecond opinion. No-op when no pseudo-root spec exists.
Sourcepub fn set_frame_precision(
&mut self,
precision: i32,
) -> Result<(), AuthoringError>
pub fn set_frame_precision( &mut self, precision: i32, ) -> Result<(), AuthoringError>
Set the layer’s framePrecision.
Sourcepub fn clear_frame_precision(&mut self) -> Result<(), AuthoringError>
pub fn clear_frame_precision(&mut self) -> Result<(), AuthoringError>
Clear the layer’s framePrecision opinion. No-op when no pseudo-root spec exists.
Methods from Deref<Target = Layer>§
Sourcepub fn data(&self) -> &dyn AbstractData
pub fn data(&self) -> &dyn AbstractData
Borrow the layer’s data as a read-only AbstractData. Reads see the
staged-over-base view, so edits staged but not yet flushed are visible.
Sourcepub fn is_dirty(&self) -> bool
pub fn is_dirty(&self) -> bool
Whether the layer has edits staged in its overlay but not yet committed.
Mirrors C++ SdfLayer::IsDirty for the in-flight-edit case.
Conservative about staged content: any uncommitted overlay write counts, including an idempotent edit (a field re-set to the value the base already holds) whose commit would derive no composition change.
Sourcepub fn identifier(&self) -> &str
pub fn identifier(&self) -> &str
The layer’s resolved, canonical identifier.
Sourcepub fn resolved_path(&self) -> Option<&str>
pub fn resolved_path(&self) -> Option<&str>
Where the layer was found, or None for an anonymous layer, which was
never read from anywhere (C++ SdfLayer::GetRealPath, empty for one).
This is the identifier except for a package, whose location is its package-relative default layer, and a layer found through a resolver search directory, whose identifier is the bare search path it was asked for.
Sourcepub fn export(&self, filename: impl AsRef<str>) -> Result<(), ExportError>
pub fn export(&self, filename: impl AsRef<str>) -> Result<(), ExportError>
Write this layer to filename, choosing the format from the filename’s
extension (C++ SdfLayer::Export). This writes a copy; the layer’s own
identifier is unchanged.
.usda writes text, .usdc writes the binary crate, .usd writes
binary (the C++ USD_WRITE_NEW_USD_FILES_AS_BINARY default), and
.usdz writes an archive wrapping one crate-encoded layer. The reader
auto-detects the format regardless of extension, so text written to a
.usd path still reads back correctly.
The file is written beside the destination and renamed over it once
complete, keeping the destination’s permissions. The destination is
therefore never a half-written file, and a file a layer reads from is
never written into. A destination this layer
itself reads from is written through save, which also
rebinds the layer to what it wrote.
Sourcepub fn export_to_string(&self) -> Result<String, ExportError>
pub fn export_to_string(&self) -> Result<String, ExportError>
Serialize this layer to a usda text string (C++ ExportToString).
Always emits text, the canonical human-readable form, regardless of the
layer’s on-disk format. Named to avoid confusion with the infallible
ToString::to_string.
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Whether this layer’s identifier is anonymous (the anon: prefix minted
by new_anonymous). Mirrors C++
SdfLayer::IsAnonymous; an anonymous layer has no asset-resolvable
location.
Sourcepub fn prim(
&self,
path: impl IntoPath,
) -> Result<Option<PrimSpecRef<'_>>, PathParseError>
pub fn prim( &self, path: impl IntoPath, ) -> Result<Option<PrimSpecRef<'_>>, PathParseError>
Look up a prim spec at path. Ok(None) when no spec exists there or
the spec is not a prim; Err when path fails to parse.
Sourcepub fn attribute(
&self,
path: impl IntoPath,
) -> Result<Option<AttributeSpecRef<'_>>, PathParseError>
pub fn attribute( &self, path: impl IntoPath, ) -> Result<Option<AttributeSpecRef<'_>>, PathParseError>
Look up an attribute spec at a property path.
Sourcepub fn relationship(
&self,
path: impl IntoPath,
) -> Result<Option<RelationshipSpecRef<'_>>, PathParseError>
pub fn relationship( &self, path: impl IntoPath, ) -> Result<Option<RelationshipSpecRef<'_>>, PathParseError>
Look up a relationship spec at a property path.
Sourcepub fn pseudo_root(&self) -> Option<PseudoRootSpecRef<'_>>
pub fn pseudo_root(&self) -> Option<PseudoRootSpecRef<'_>>
View this layer’s root pseudo-spec, which carries layer-wide metadata
(defaultPrim, subLayers, time codes, …).
Sourcepub fn relocates(&self) -> RelocateList
pub fn relocates(&self) -> RelocateList
The list of namespace relocations authored in this layer’s metadata,
or an empty list when none are authored. Mirrors C++
SdfLayer::GetRelocates. Reads through the backing AbstractData, so
it works on both in-memory and file-loaded layers.
Sourcepub fn has_relocates(&self) -> bool
pub fn has_relocates(&self) -> bool
Whether this layer’s metadata carries any relocates opinion, including
an explicit empty list (an opinion that there should be no relocates).
Mirrors C++ SdfLayer::HasRelocates.
Sourcepub fn start_time_code(&self) -> f64
pub fn start_time_code(&self) -> f64
The layer’s startTimeCode, or 0.0 when unauthored. Mirrors C++
SdfLayer::GetStartTimeCode.
Sourcepub fn has_start_time_code(&self) -> bool
pub fn has_start_time_code(&self) -> bool
Whether this layer authors a startTimeCode opinion. Mirrors C++
SdfLayer::HasStartTimeCode.
Sourcepub fn end_time_code(&self) -> f64
pub fn end_time_code(&self) -> f64
The layer’s endTimeCode, or 0.0 when unauthored. Mirrors C++
SdfLayer::GetEndTimeCode.
Sourcepub fn has_end_time_code(&self) -> bool
pub fn has_end_time_code(&self) -> bool
Whether this layer authors an endTimeCode opinion. Mirrors C++
SdfLayer::HasEndTimeCode.
Sourcepub fn time_codes_per_second(&self) -> f64
pub fn time_codes_per_second(&self) -> f64
The layer’s timeCodesPerSecond. Falls back to the authored
framesPerSecond, then to 24.0, when unauthored. Mirrors C++
SdfLayer::GetTimeCodesPerSecond.
Sourcepub fn has_time_codes_per_second(&self) -> bool
pub fn has_time_codes_per_second(&self) -> bool
Whether this layer authors a timeCodesPerSecond opinion. Mirrors C++
SdfLayer::HasTimeCodesPerSecond.
Sourcepub fn frames_per_second(&self) -> f64
pub fn frames_per_second(&self) -> f64
The layer’s framesPerSecond, or 24.0 when unauthored. Mirrors C++
SdfLayer::GetFramesPerSecond.
Sourcepub fn has_frames_per_second(&self) -> bool
pub fn has_frames_per_second(&self) -> bool
Whether this layer authors a framesPerSecond opinion. Mirrors C++
SdfLayer::HasFramesPerSecond.
Sourcepub fn frame_precision(&self) -> i32
pub fn frame_precision(&self) -> i32
The layer’s framePrecision, or 3 when unauthored. Mirrors C++
SdfLayer::GetFramePrecision.
Sourcepub fn has_frame_precision(&self) -> bool
pub fn has_frame_precision(&self) -> bool
Whether this layer authors a framePrecision opinion. Mirrors C++
SdfLayer::HasFramePrecision.