#data-stream #blockchain

fuel-streams-macros

Macros for implementing traits and deriving functionality in the fuel-streams crate

19 releases

new 0.0.24 Feb 4, 2025
0.0.23 Jan 28, 2025
0.0.16 Dec 28, 2024
0.0.13 Nov 28, 2024
0.0.6 Aug 29, 2024

#82 in Magic Beans

Download history 146/week @ 2024-10-15 4/week @ 2024-10-22 5/week @ 2024-10-29 7/week @ 2024-11-05 158/week @ 2024-11-19 175/week @ 2024-11-26 10/week @ 2024-12-03 33/week @ 2024-12-10 392/week @ 2024-12-24 4/week @ 2024-12-31 2/week @ 2025-01-07 449/week @ 2025-01-21 167/week @ 2025-01-28

619 downloads per month
Used in 6 crates (3 directly)

Apache-2.0

12KB
140 lines


Logo

Fuel Streams Macros

Macros for implementing traits and deriving functionality in the fuel-streams ecosystem

CI Coverage Crates.io MSRV crates.io docs

📚 Documentation   🐛 Report Bug   ✨ Request Feature

📝 About The Project

Provides macros for implementing traits and deriving functionality in the fuel-streams ecosystem.

[!NOTE] This crate is specifically modeled for the Fuel Data Systems project, and is not intended for general use outside of the project.

🚀 Usage

The Subject derive macro allows you to easily implement the Subject trait for your structs. It generates methods for parsing, building, and creating subjectsfor your subject.

Example:

use fuel_streams_macros::subject::*;

#[derive(Subject, Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[subject(id = "test")]
#[subject(entity = "Test")]
#[subject(query_all = "test.>")]
#[subject(format = "test.{field1}.{field2}")]
struct TestSubject {
    field1: Option<String>,
    field2: Option<u32>,
}

// Create a new TestSubject
let subject = TestSubject {
    field1: Some("foo".to_string()),
    field2: Some(55),
};

// Parse the subject
assert_eq!(subject.parse(), "test.foo.55");

// Create a subject string
assert_eq!(TestSubject::build_string(None, Some(10)), "test.*.10");

// Create using the build method
let subject = TestSubject::build(Some("foo".into()), Some(55));
assert_eq!(subject.parse(), "test.foo.55");

// Create a new TestSubject with the builder pattern
let subject = TestSubject::new()
    .with_field1(Some("foo".to_string()))
    .with_field2(Some(55));
assert_eq!(subject.parse(), "test.foo.55");

// Convert to a string
assert_eq!(&subject.to_string(), "test.foo.55");

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

For more information on contributing, please see the CONTRIBUTING.md file in the root of the repository.

📜 License

This repo is licensed under the Apache-2.0 license. See LICENSE for more information.

Dependencies

~1.5–2.6MB
~50K SLoC