split_propertied

Function split_propertied 

Source
pub fn split_propertied(
    s: &str,
    separators: Separators,
) -> (&str, impl Iterator<Item = (&str, Option<&str>)> + DoubleEndedIterator + FusedIterator + Clone + Debug)
Expand description

A convenience function to split a key that is followed by properties.

In keeping with this library in general, this is deliberately very simple and consequently not able to express all possible values; for example, if you use space as the separator between properties, you can’t use space in property values; and this doesn’t guard against empty keys or property names in any way.

use human_string_filler::{Separators, split_propertied};

let (key, properties) = split_propertied("key:prop1,prop2=value2,prop3=4+5=9", Separators {
    between_key_and_properties: ':',
    between_properties: ',',
    between_property_name_and_value: '=',
});

assert_eq!(key, "key");
assert_eq!(properties.collect::<Vec<_>>(),
           vec![("prop1", None), ("prop2", Some("value2")), ("prop3", Some("4+5=9"))]);

This method consumes exactly one character for the separators; if space is your between-properties separator, for example, multiple spaces will not be combined, but you’ll get ("", None) properties instead. As I say, this is deliberately simple.