toml icon indicating copy to clipboard operation
toml copied to clipboard

Allow to create `Decor` instances with optional prefix or suffix

Open oxcabe opened this issue 9 months ago • 0 comments

Description

Having more flexible ways to instantiate Decor could be a good thing. I think it's handy to partially instantiate Decor with either the prefix or the suffix.

Example

I want to do this:

let key = Key::new("hello").with_leaf_decor(Decor::new(None, "world")); // "hello" key with "world" decor suffix

Or even something similar to this:

let key = Key::new("hello").with_leaf_decor(Decor::new_suffix("world")); // "hello" key with "world" decor suffix

But instead, I have to do this:

let mut decor = Decor::new();
decor.set_suffix("world");

let key = Key::new("hello").with_leaf_decor(decor); // "hello" key with "world" decor suffix

Or this (which is possibly wrong but may work sometimes):

let key = Key::new("hello").with_leaf_decor(Decor::new("", "world")); // "hello" key with "world" decor suffix

oxcabe avatar May 10 '24 11:05 oxcabe