fuse-rust-derive 0.1.0

Derive macro for the Fuseable trait from the fuse-rust crate.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 11.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 39.6 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Blakeinstein/fuse-rust
    30 3 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Blakeinstein

fuse-rust-derive

Derive macro for the Fuseable trait of fuse-rust.

You normally do not depend on this crate directly. Enable the derive feature of fuse-rust instead, which re-exports the macro:

[dependencies]
fuse-rust = { version = "0.4", features = ["derive"] }

Usage

Mark each searchable field with #[fuse]. Fields without the attribute are ignored, so a struct may hold ids, counts or anything else non-textual.

use fuse_rust::{Fuse, Fuseable};

#[derive(Fuseable)]
struct Book {
    #[fuse(weight = 0.3)]
    title: String,
    #[fuse(weight = 0.7)]
    author: String,
    isbn: u64, // not searched
}

let books = [
    Book { title: "Old Man's War fiction".into(), author: "John X".into(), isbn: 1 },
    Book { title: "Right Ho Jeeves".into(), author: "P.D. Mans".into(), isbn: 2 },
];

let results = Fuse::default().search_text_in_fuse_list("man", &books);

A bare #[fuse] uses the default weight of 1.0:

# use fuse_rust::Fuseable;
#[derive(Fuseable)]
struct Tag {
    #[fuse]
    name: String,
}

Rules

  • Only structs with named fields are supported. Tuple structs have no field names to look up, and enums have no single set of fields.
  • At least one field must be marked #[fuse].
  • weight must be greater than 0.0 and at most 1.0. Weights are combined as 1.0 - weight, so values outside that range score nonsensically.
  • Every marked field must be usable as a &str; String and &str both work.
  • Generic parameters and lifetimes on the struct are carried through to the impl.

License

MIT, same as fuse-rust.