Trait fuse_rust::Fuseable

source ·
pub trait Fuseable {
    // Required methods
    fn properties(&self) -> Vec<FuseProperty>;
    fn lookup(&self, key: &str) -> Option<&str>;
}
Expand description

Implementable trait for user defined structs, requires two methods to me implemented. A properties method that should return a list of FuseProperties. and a lookup method which should return the value of field, provided the field name.

Examples:

Usage:

use fuse_rust::{ Fuse, Fuseable, FuseProperty };
struct Book<'a> {
    title: &'a str,
    author: &'a str,
}

impl Fuseable for Book<'_>{
    fn properties(&self) -> Vec<FuseProperty> {
        return vec!(
            FuseProperty{value: String::from("title"), weight: 0.3},
            FuseProperty{value: String::from("author"), weight: 0.7},
        )
    }
    fn lookup(&self, key: &str) -> Option<&str> {
        return match key {
            "title" => Some(self.title),
            "author" => Some(self.author),
            _ => None
        }
    }
}

Required Methods§

source

fn properties(&self) -> Vec<FuseProperty>

Returns a list of FuseProperty that contains the field name and its corresponding weight

source

fn lookup(&self, key: &str) -> Option<&str>

Provided a field name as argument, returns the value of the field. eg book.loopkup(“author”) === book.author

Implementors§