Env trait defines the interface for platform-specific operations in Stremio Core. Implementations of this trait provide access to storage, networking, analytics, and other system-level functionality.
Overview
The Env trait abstracts platform differences, allowing Stremio Core to work across:- Web (WebAssembly)
- Desktop (Native)
- Mobile (Native)
Trait Definition
Required Methods
fetch
Performs an HTTP request with serialization/deserialization.IN- Request body type (must be serializable)OUT- Response body type (must be deserializable)
request- HTTP request with typed body
EnvError
Example:
get_storage
Retrieves a value from persistent storage.T- Type of the stored value
key- Storage key
None if not found
Example:
set_storage
Stores or removes a value from persistent storage.T- Type of the value to store
key- Storage keyvalue- Value to store, orNoneto remove
EnvError
Example:
exec_concurrent
Executes a future concurrently (fire and forget).F- Future type that returns()
future- The future to execute
exec_sequential
Executes a future sequentially (queued execution).F- Future type that returns()
future- The future to execute
now
Returns the current UTC timestamp.flush_analytics
Flushes any pending analytics data.analytics_context
Creates analytics context for tracking.ctx- Current context (profile, library, etc.)streaming_server- Streaming server statepath- Current navigation path
log (Debug Only)
Logs a message (only available in debug builds).message- Message to log
Provided Methods
addon_transport
Creates an addon transport for the given URL.transport_url- URL of the addon
migrate_storage_schema
Migrates storage schema to the latest version.EnvError
This method automatically handles schema version upgrades from v0 to the current version.
EnvError
Errors returned by Env operations.message() -> String- Returns human-readable error messagecode() -> u32- Returns error code
