mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 22:59:58 -07:00
bindex: contained fjall code
This commit is contained in:
11
struct_iterable/struct_iterable_internal/Cargo.toml
Normal file
11
struct_iterable/struct_iterable_internal/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "struct_iterable_internal"
|
||||
version = "0.1.1"
|
||||
authors = ["André de Moraes <deco.moraes@icloud.com>"]
|
||||
edition = "2021"
|
||||
description = "An internal crate for struct_iterable"
|
||||
license = "MIT"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
7
struct_iterable/struct_iterable_internal/README.md
Normal file
7
struct_iterable/struct_iterable_internal/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Struct Iterable Internal
|
||||
|
||||
This crate is a supporting library for the `struct_iterable` crate. It provides the `Iterable` trait which is used in conjunction with the `struct_iterable_derive` crate to provide an easy way to make a struct iterable in Rust.
|
||||
|
||||
**Please note:** This crate is not intended to be used directly. If you want to make your structs iterable, please use the `struct_iterable` crate instead.
|
||||
|
||||
Please visit the [`struct_iterable` crate on crates.io](https://crates.io/crates/struct_iterable) for more information and usage examples.
|
||||
58
struct_iterable/struct_iterable_internal/src/lib.rs
Normal file
58
struct_iterable/struct_iterable_internal/src/lib.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
/// The `Iterable` trait.
|
||||
///
|
||||
/// This trait is implemented for structs that derive the `Iterable` proc macro.
|
||||
/// It provides the `iter` method which returns an iterator over the struct's fields as tuples, containing the field name as a static string and a reference to the field's value as `dyn Any`.
|
||||
///
|
||||
/// You usually don't need to implement this trait manually, as it is automatically derived when using the `#[derive(Iterable)]` proc macro.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use struct_iterable::Iterable;
|
||||
///
|
||||
/// #[derive(Iterable)]
|
||||
/// struct MyStruct {
|
||||
/// field1: i32,
|
||||
/// field2: String,
|
||||
/// }
|
||||
///
|
||||
/// let my_instance = MyStruct {
|
||||
/// field1: 42,
|
||||
/// field2: "Hello, world!".to_string(),
|
||||
/// };
|
||||
///
|
||||
/// // Iterate over the fields of `my_instance`:
|
||||
/// for (field_name, field_value) in my_instance.iter() {
|
||||
/// println!("{}: {:?}", field_name, field_value);
|
||||
/// }
|
||||
/// ```
|
||||
pub trait Iterable {
|
||||
/// Returns an iterator over the struct's fields as tuples.
|
||||
///
|
||||
/// Each tuple contains a field's name as a static string and a reference to the field's value as `dyn Any`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use struct_iterable::Iterable;
|
||||
///
|
||||
/// #[derive(Iterable)]
|
||||
/// struct MyStruct {
|
||||
/// field1: i32,
|
||||
/// field2: String,
|
||||
/// }
|
||||
///
|
||||
/// let my_instance = MyStruct {
|
||||
/// field1: 42,
|
||||
/// field2: "Hello, world!".to_string(),
|
||||
/// };
|
||||
///
|
||||
/// // Iterate over the fields of `my_instance`:
|
||||
/// for (field_name, field_value) in my_instance.iter() {
|
||||
/// println!("{}: {:?}", field_name, field_value);
|
||||
/// }
|
||||
/// ```
|
||||
fn iter(&self) -> std::vec::IntoIter<(&'static str, &'_ dyn std::any::Any)>;
|
||||
|
||||
fn iter_mut(&mut self) -> std::vec::IntoIter<(&'static str, &'_ mut dyn std::any::Any)>;
|
||||
}
|
||||
Reference in New Issue
Block a user