Skip to main content

LayerEdit

Struct LayerEdit 

Source
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<'_>

Source

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.

Source

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.

Source

pub fn prim_mut( &mut self, path: impl IntoPath, ) -> Result<Option<PrimSpecMut<'_>>, PathParseError>

Mutably look up the prim spec at path.

Source

pub fn attribute_mut( &mut self, path: impl IntoPath, ) -> Result<Option<AttributeSpecMut<'_>>, PathParseError>

Mutably look up the attribute spec at a property path.

Source

pub fn relationship_mut( &mut self, path: impl IntoPath, ) -> Result<Option<RelationshipSpecMut<'_>>, PathParseError>

Mutably look up the relationship spec at a property path.

Source

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.

Source

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.

Source

pub fn clear_default_prim(&mut self) -> Result<(), AuthoringError>

Remove the layer’s defaultPrim metadata. No-op when no pseudo-root spec exists.

Source

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.

Source

pub fn clear_relocates(&mut self) -> Result<(), AuthoringError>

Clear the layer’s relocates opinion. No-op when no pseudo-root spec exists.

Source

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).

Source

pub fn clear_expression_variables(&mut self) -> Result<(), AuthoringError>

Clear the layer’s expressionVariables opinion. No-op when no pseudo-root spec exists.

Source

pub fn set_start_time_code(&mut self, time: f64) -> Result<(), AuthoringError>

Set the layer’s startTimeCode.

Source

pub fn clear_start_time_code(&mut self) -> Result<(), AuthoringError>

Clear the layer’s startTimeCode opinion. No-op when no pseudo-root spec exists.

Source

pub fn set_end_time_code(&mut self, time: f64) -> Result<(), AuthoringError>

Set the layer’s endTimeCode.

Source

pub fn clear_end_time_code(&mut self) -> Result<(), AuthoringError>

Clear the layer’s endTimeCode opinion. No-op when no pseudo-root spec exists.

Source

pub fn set_time_codes_per_second( &mut self, rate: f64, ) -> Result<(), AuthoringError>

Set the layer’s timeCodesPerSecond.

Source

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.

Source

pub fn set_frames_per_second(&mut self, rate: f64) -> Result<(), AuthoringError>

Set the layer’s framesPerSecond.

Source

pub fn clear_frames_per_second(&mut self) -> Result<(), AuthoringError>

Clear the layer’s framesPerSecond opinion. No-op when no pseudo-root spec exists.

Source

pub fn set_frame_precision( &mut self, precision: i32, ) -> Result<(), AuthoringError>

Set the layer’s framePrecision.

Source

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>§

Source

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.

Source

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.

Source

pub fn identifier(&self) -> &str

The layer’s resolved, canonical identifier.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn attribute( &self, path: impl IntoPath, ) -> Result<Option<AttributeSpecRef<'_>>, PathParseError>

Look up an attribute spec at a property path.

Source

pub fn relationship( &self, path: impl IntoPath, ) -> Result<Option<RelationshipSpecRef<'_>>, PathParseError>

Look up a relationship spec at a property path.

Source

pub fn pseudo_root(&self) -> Option<PseudoRootSpecRef<'_>>

View this layer’s root pseudo-spec, which carries layer-wide metadata (defaultPrim, subLayers, time codes, …).

Source

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.

Source

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.

Source

pub fn start_time_code(&self) -> f64

The layer’s startTimeCode, or 0.0 when unauthored. Mirrors C++ SdfLayer::GetStartTimeCode.

Source

pub fn has_start_time_code(&self) -> bool

Whether this layer authors a startTimeCode opinion. Mirrors C++ SdfLayer::HasStartTimeCode.

Source

pub fn end_time_code(&self) -> f64

The layer’s endTimeCode, or 0.0 when unauthored. Mirrors C++ SdfLayer::GetEndTimeCode.

Source

pub fn has_end_time_code(&self) -> bool

Whether this layer authors an endTimeCode opinion. Mirrors C++ SdfLayer::HasEndTimeCode.

Source

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.

Source

pub fn has_time_codes_per_second(&self) -> bool

Whether this layer authors a timeCodesPerSecond opinion. Mirrors C++ SdfLayer::HasTimeCodesPerSecond.

Source

pub fn frames_per_second(&self) -> f64

The layer’s framesPerSecond, or 24.0 when unauthored. Mirrors C++ SdfLayer::GetFramesPerSecond.

Source

pub fn has_frames_per_second(&self) -> bool

Whether this layer authors a framesPerSecond opinion. Mirrors C++ SdfLayer::HasFramesPerSecond.

Source

pub fn frame_precision(&self) -> i32

The layer’s framePrecision, or 3 when unauthored. Mirrors C++ SdfLayer::GetFramePrecision.

Source

pub fn has_frame_precision(&self) -> bool

Whether this layer authors a framePrecision opinion. Mirrors C++ SdfLayer::HasFramePrecision.

Trait Implementations§

Source§

impl Deref for LayerEdit<'_>

Source§

type Target = Layer

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Layer

Dereferences the value.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for LayerEdit<'a>

§

impl<'a> !Send for LayerEdit<'a>

§

impl<'a> !Sync for LayerEdit<'a>

§

impl<'a> !UnwindSafe for LayerEdit<'a>

§

impl<'a> Freeze for LayerEdit<'a>

§

impl<'a> Unpin for LayerEdit<'a>

§

impl<'a> UnsafeUnpin for LayerEdit<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.