Normalizing Interface

Firstly, thank you for implementing this library! I'm eager for it to get into https://crates.io so I can update https://git.jacky.wtf/indieweb/rust to be published with it. It'll implicitly get used in a few other projects I have and plan to share publicly soon. I have some thoughts on the interface exposed by this library.

  • Using the term Item to represent all of the types of objects we can use in Microformats in a data format instead of the explicit Microformat
  • Using something like microformats::parser::from_html_string, microformats::parser::from_json_string for quick parser stuff (example #1 (closed))
  • Leaning on a more generic approach of representing items (example #2 (closed))

Example 1

use microformats;

let items = microformats::parser::html(r#"
  <div class="h-entry">
    <a href="/" class="u-url">/a>
    <p class="e-content">Awesome</p>
  </div>
"); // would return something like `microformats::Result<Vec<microformats::Item>>`

Example 2

pub struct Item<Properties> {
  #[serde(flatten)]
  // A generic representation of properties.
  properties: Properties,

  // The HTML "id" value associated with this element, if any.
  id: Option<String>,

  // The computed value of this (useful for cards)
  value: Option<String>
};

impl Item<Properties> {
  pub fn property<Item>(&self, prop: &str) -> Option<Item> { }
}

trait ItemEntryType { fn type(&self) -> String }

type Entry = Item<EntryProperties>;

impl ItemEntryType for Entry {
  pub fn type(&self) -> String { "entry".to_owned() }
}

type Card = Item<CardProperties>;

impl ItemEntryType for Card {
  pub fn type(&self) -> String { "card".to_owned() }
}

type Event = Item<EventProperties>;

impl ItemEntryType for Event {
  pub fn type(&self) -> String { "event".to_owned() }
}