Expand description
A catch all for project-wide macros and general-purpose functions that are not directly related to Perspective.
Modules below crate::utils strive to be single-responsibility, but some
reference other crate::utils modules when it helps reduce boiler-plate.
Structs§
- Debounce
Mutex - An async
Mutextype specialized for Perspective’s rendering, which debounces calls in addition to providing exclusivity. Callingdebouncewith a cancellableFuturewill resolve only after at least one complete evaluation of a call awaiting the lock. - PubSub
- A pub/sub struct which allows many listeners to subscribe to many publishers, without leaking callbacks as listeners are dropped.
- Subscriber
- Like a
PubSubwithoutPubSub::emit; the reciprocal ofPubSub::callback.Subscriberdoes not keep the parentPubSubalive. - Subscription
- Manages the lifetime of a listener registered to a
PubSub<T>by deregistering the associated listener when dropped. - Weak
Scope - A mutable reference for capturing the
Scopeprops arguments, a useful function for tests.
Enums§
Traits§
- AddListener
- An extension trait for
AddListener::add_listener, which we want to take a variety of function-like arguments for readability. - AsBlob
- An extension method for converting various
js_sysandweb_systypes toweb_sys::Blob. - Caret
Position - Utilities for caret position. DOM elements have different APIs for this
but
Derefmakes them fall through, so it is important that this method be called on the correct struct type! - Custom
Element Metadata - A trait which allows the
define_web_componentmethod to create a Custom Element (which must by definition inherit fromHTMLElement) from a[wasm_bindgen]annotated Rust struct (for which this trait is implemented). - u32Ext
- Trait for the
u32::to_formatted_stringmethod.
Functions§
- await_
dom_ loaded - An
asyncwhich awaits the browser’sloadevent, which is automatically bypassed ifdocument.readyStateindicates this has already occurred. - await_
queue_ microtask - An
asyncversion ofqueueMicrotask(), curiously absent fromweb_sys. - define_
web_ component - Register the Custom Element globally.
- download
- Given a blob, invoke the Browser’s download popup.
- posix_
to_ utc_ str - Convert POSIX timestamp to a formatted string.
- request_
animation_ frame - An
asyncversion ofrequestAnimationFrame(), which resolves on the next animation frame. - set_
timeout - An
asyncversion ofset_timeout, which resolves intimeoutmilliseconds - str_
to_ utc_ posix - Convert a
Stringdatetime representation to a POSIX timestamp. - use_
async_ callback - Just like
use_callback, except convenient for an async result body.