pub struct SsabResource { /* private fields */ }Expand description
A thread-safe, shared resource containing SSAB data and its parsed metadata.
This is a self-referential structure: resource holds borrows into data’s
buffer. The 'static lifetime stored internally is fictitious — the actual
lifetime is bound to &self. The resource() accessor restores the correct
lifetime, so external code never observes the unsound 'static form.
Invariants (must hold for soundness):
- Fields are private so
datacannot be mutated or replaced after construction. - Field declaration order ensures
resourceis dropped beforedata. - An owned
SsabDatakeeps itsVec<u8>buffer at a stable heap address; a borrowed one requires the caller to keep the memory valid (documented onSsabData::load_borrow).
Implementations§
Source§impl SsabResource
impl SsabResource
Sourcepub unsafe fn new(data: SsabData) -> Arc<Self> ⓘ
pub unsafe fn new(data: SsabData) -> Arc<Self> ⓘ
Parses data into a shareable resource. On failure the resource holds no
animation and Self::parse_error says why.
§Safety
The bytes must be a valid .ssab. They are read through FlatBuffers accessors that do not
bounds-check in release builds, so any other bytes are undefined behaviour (out-of-bounds
reads). A pack the converter wrote is valid; for any other, run the FlatBuffers verifier
first (the ssab crate’s checked root_as_ss_anime_binary).
Sourcepub fn parse_error(&self) -> Option<&SSRuntimeError>
pub fn parse_error(&self) -> Option<&SSRuntimeError>
Why Self::resource is None, or None when the parse succeeded.
Sourcepub fn resource(&self) -> Option<&AnimationResource<'_>>
pub fn resource(&self) -> Option<&AnimationResource<'_>>
Returns the parsed animation resource, with its lifetime tied to &self.
Sourcepub fn resource_static_ptr(&self) -> *const AnimationResource<'static>
pub fn resource_static_ptr(&self) -> *const AnimationResource<'static>
Returns a raw pointer to the parsed resource (or null if parsing failed),
detached from self’s borrow scope.
This is intended for FFI/WASM bindings that need to extend the resource
reference into a 'static context while transferring ownership of the
surrounding Arc<SsabResource> to a long-lived holder. Using a raw
pointer breaks the borrow chain so the Arc can be moved into its
holder before the pointer is dereferenced.
Obtaining the pointer is safe; dereferencing it is unsafe and the
caller must uphold the obligations below.
§Caller obligations when dereferencing
- Keep some
Arc<SsabResource>pointing at this allocation alive for the entire duration the pointer (or any borrow derived from it) is in use. - Do not dereference after the last
Arcreferencing this allocation is dropped — doing so is undefined behaviour.