Env trait is the core abstraction that allows Stremio Core to run on different platforms. It defines the interface for platform-specific operations like network requests, storage, and task execution.
Overview
TheEnv trait is defined in src/runtime/env.rs and provides a platform-agnostic interface for:
- HTTP requests (fetch)
- Persistent storage (get/set)
- Task execution (concurrent and sequential)
- Time operations
- Analytics
- Logging
- Add-on transport
- Storage schema migration
Core Methods
Network Operations
fetch
Storage Operations
get_storage
set_storage
None to delete the key.
Task Execution
exec_concurrent
exec_sequential
Time Operations
now
Analytics
flush_analytics
analytics_context
Debugging
log (debug builds only)
Default Implementations
addon_transport
migrate_storage_schema
Error Handling
TheEnvError enum defines all possible error types:
code() and message() methods.
Future Types
EnvFuture<'a, T>
The return type for async operations. Automatically handles platform differences:
- WASM (default): Uses
LocalBoxFuture(notSend) - Native (with
env-future-sendfeature): UsesBoxFuture(requiresSend)
ConditionalSend
A marker trait that is:
- Empty trait on WASM (all types implement it)
- Equivalent to
Sendon native platforms
Implementation Example
Here’s a minimal native implementation:Storage Keys
Stremio Core uses these storage keys (defined insrc/constants.rs):
SCHEMA_VERSION_STORAGE_KEY: Storage schema versionPROFILE_STORAGE_KEY: User profileLIBRARY_STORAGE_KEY: Library dataLIBRARY_RECENT_STORAGE_KEY: Recently watchedSTREAMS_STORAGE_KEY: Cached streamsSEARCH_HISTORY_STORAGE_KEY: Search historySTREAMING_SERVER_URLS_STORAGE_KEY: Streaming server URLsDISMISSED_EVENTS_STORAGE_KEY: Dismissed events
Do not modify these keys directly. Use the Context model’s methods instead.
Platform-Specific Considerations
WASM
- Cannot use
Sendtrait - Must use
LocalBoxFuture - See WASM Bindings for complete implementation
Native
- Can enable
env-future-sendfeature forSendfutures - Use async runtime like Tokio
- See Native Apps for complete guide
Next Steps
WASM Bindings
Learn how to use stremio-core-web package
Native Apps
Build native applications with stremio-core
