You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.rs 760B

12345678910111213141516171819202122232425262728293031323334
  1. use pulldown_cmark::{html, Options, Parser};
  2. use serde::Serializer;
  3. use serde::{
  4. de::{Deserialize, Deserializer},
  5. Serialize,
  6. };
  7. pub fn generate_html(s: &str) -> String {
  8. let options = Options::all();
  9. let parser = Parser::new_ext(s, options);
  10. let mut html_output = String::new();
  11. html::push_html(&mut html_output, parser);
  12. html_output
  13. }
  14. pub fn bool_from_int<'de, D>(deserializer: D) -> Result<bool, D::Error>
  15. where
  16. D: Deserializer<'de>,
  17. {
  18. match u8::deserialize(deserializer)? {
  19. 1 => Ok(true),
  20. _ => Ok(false),
  21. }
  22. }
  23. pub fn int_from_bool<S>(value: &bool, s: S) -> Result<S::Ok, S::Error>
  24. where
  25. S: Serializer,
  26. {
  27. match value {
  28. true => 1.serialize(s),
  29. false => 0.serialize(s),
  30. }
  31. }