#data-stream #blockchain

fuel-streams-macros

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

9 releases

new 0.0.12 Nov 21, 2024
0.0.11 Oct 15, 2024
0.0.10 Sep 27, 2024
0.0.6 Aug 29, 2024

#38 in Magic Beans

Download history 339/week @ 2024-08-23 139/week @ 2024-08-30 541/week @ 2024-09-06 41/week @ 2024-09-13 16/week @ 2024-09-20 192/week @ 2024-09-27 13/week @ 2024-10-04 125/week @ 2024-10-11 31/week @ 2024-10-18 2/week @ 2024-10-25 8/week @ 2024-11-01 3/week @ 2024-11-08 98/week @ 2024-11-15

114 downloads per month
Used in 2 crates (via fuel-streams-core)

Apache-2.0

8KB


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 wildcards for your subject.

Example:

use fuel_streams_macros::subject::{Subject, IntoSubject, SubjectBuildable};

#[derive(Subject, Debug, Clone, Default)]
#[subject_wildcard = "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 wildcard
assert_eq!(TestSubject::wildcard(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

~230–670KB
~16K SLoC