pub trait CustomRegistryValue:
CustomRegistryKind
+ Any
+ Send
+ Sync
+ Debug {
// Required methods
fn kind_name() -> &'static str
where Self: Sized;
fn to_value(&self) -> Result<Value, String>;
// Provided methods
fn from_value(_value: &Value) -> Result<Self, String>
where Self: Sized { ... }
fn from_bytes(_bytes: &[u8], format: &str) -> Result<Self, String>
where Self: Sized { ... }
fn from_path(path: &Path) -> Result<Self, String>
where Self: Sized { ... }
fn export_to_bytes(&self, format: &str) -> Result<Vec<u8>, String> { ... }
fn known_import_formats() -> Vec<ExtensionWithMime>
where Self: Sized { ... }
fn known_export_formats() -> Vec<ExtensionWithMime>
where Self: Sized { ... }
}Expand description
A registry handle type owned by a downstream crate.
Implement this, then a #[bind(handle)] argument or a #[register_binding(returns_handle)]
return of that type crosses the binding boundary as a registry id instead of being serialized
as JSON, the same treatment the built-in big types get but without an entry in the macro
crate’s list of them. Derive CustomRegistryEntity to accept it as a #[bind(handle)]
argument.
Registering the type with crate::register_custom_registry_kind! is optional and adds what
needs a name rather than a Rust type: RegistryItemKind::from_str
resolution, RegistryItem::load_from_path / RegistryItem::load_from_bytes, and the
format lists. Unregistered, a value still stores, resolves by id and exports.
Send + Sync are load-bearing: the registry lives in a static in the wasm hosts, so
AppState has to stay Sync.
Required Methods§
Sourcefn kind_name() -> &'static strwhere
Self: Sized,
fn kind_name() -> &'static strwhere
Self: Sized,
Name this kind is known by in ids, in x-registry-ref and in RegistryItemKind::Custom.
Provided Methods§
Sourcefn from_value(_value: &Value) -> Result<Self, String>where
Self: Sized,
fn from_value(_value: &Value) -> Result<Self, String>where
Self: Sized,
Rebuild the value from the JSON form CustomRegistryValue::to_value produces.
Sourcefn from_bytes(_bytes: &[u8], format: &str) -> Result<Self, String>where
Self: Sized,
fn from_bytes(_bytes: &[u8], format: &str) -> Result<Self, String>where
Self: Sized,
Read the value from bytes in the named format.
Sourcefn from_path(path: &Path) -> Result<Self, String>where
Self: Sized,
fn from_path(path: &Path) -> Result<Self, String>where
Self: Sized,
Read the value from a file, defaulting to CustomRegistryValue::from_bytes with the
format inferred from the extension.
Sourcefn export_to_bytes(&self, format: &str) -> Result<Vec<u8>, String>
fn export_to_bytes(&self, format: &str) -> Result<Vec<u8>, String>
Write the value out in the named format.
Sourcefn known_import_formats() -> Vec<ExtensionWithMime>where
Self: Sized,
fn known_import_formats() -> Vec<ExtensionWithMime>where
Self: Sized,
Formats CustomRegistryValue::from_bytes accepts.
Sourcefn known_export_formats() -> Vec<ExtensionWithMime>where
Self: Sized,
fn known_export_formats() -> Vec<ExtensionWithMime>where
Self: Sized,
Formats CustomRegistryValue::export_to_bytes produces.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".