diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-14 00:14:30 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-14 00:14:30 +0800 |
| commit | 1f2462ae53446c37c6cfe53a57ea86f695c4ef0a (patch) | |
| tree | 9d54a4dcbaf1dc6fe36ecaf98253cbc521ddc8b0 /mingling_core/src/asset/metadata.rs | |
| parent | 47aa95b2c65473950e089beac6ac986a3240608e (diff) | |
docs: expand trait and type documentation with examples
Diffstat (limited to 'mingling_core/src/asset/metadata.rs')
| -rw-r--r-- | mingling_core/src/asset/metadata.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/mingling_core/src/asset/metadata.rs b/mingling_core/src/asset/metadata.rs index 996b34c..4ac758b 100644 --- a/mingling_core/src/asset/metadata.rs +++ b/mingling_core/src/asset/metadata.rs @@ -3,12 +3,35 @@ /// Any type can be attached to an Entry as metadata, allowing the program to /// carry compile-time-typed, arbitrary description data alongside each /// registered entry. The [`Metadata`] trait bridges an Entry type (`Self`) to -/// an arbitrary metadata type `B`. +/// an arbitrary metadata type `DataType`. +/// +/// # Manual impl /// /// It is recommended to use the `#[metadata(Entry)]` attribute macro from /// [mingling_macros](https://crates.io/crates/mingling_macros) to implement this /// trait and register the entry via `register_metadata!`. -pub trait Metadata<B> { - /// Initializes and returns the metadata value of type `B` for this entry. - fn init_metadata() -> B; +/// +/// If you need to implement it manually, you can refer to the following +/// example: +/// +/// ``` +/// # use mingling_core::MockProgramCollect as ThisProgram; +/// # use mingling_core::Metadata; +/// struct EntryGreet; +/// struct MyInformation { +/// name: String +/// } +/// +/// impl Metadata<MyInformation> for EntryGreet { +/// fn init_metadata() -> MyInformation { +/// MyInformation { name: "Greeting".into() } +/// } +/// } +/// +/// // Register the MyInformation metadata for EntryGreet using `register_metadata!`. +/// // mingling::macros::register_metadata!(EntryGreet, MyInformation); +/// ``` +pub trait Metadata<DataType> { + /// Initializes and returns the metadata value of type `DataType` for this entry. + fn init_metadata() -> DataType; } |
