Guest User

Untitled

a guest
Sep 18th, 2019
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #![allow(dead_code, unused_variables)]
  2.  
  3. use serde::Serialize;
  4. use std::io::Write;
  5.  
  6. #[derive(Debug, Serialize)]
  7. pub struct LintMessage;
  8. pub struct LintPath;
  9.  
  10. pub trait Linter {
  11. fn check_paths<'a>(&mut self, paths: impl Iterator<Item = &'a LintPath>);
  12. }
  13.  
  14. pub trait Output {
  15. fn write(&mut self, msg: LintMessage);
  16. }
  17.  
  18. impl<T: ?Sized + Output> Output for &'_ mut T {
  19. fn write(&mut self, msg: LintMessage) {
  20. (**self).write(msg);
  21. }
  22. }
  23.  
  24. // Useful for tests.
  25. impl Output for Vec<LintMessage> {
  26. fn write(&mut self, msg: LintMessage) {
  27. self.push(msg);
  28. }
  29. }
  30.  
  31. struct PrintToStdout;
  32. impl Output for PrintToStdout {
  33. fn write(&mut self, msg: LintMessage) {
  34. println!("{:?}", msg);
  35. }
  36. }
  37.  
  38. // Stream JSON.
  39. impl<W: Write> Output for serde_json::Serializer<W> {
  40. fn write(&mut self, msg: LintMessage) {
  41. let _ = msg.serialize(self);
  42. }
  43. }
  44.  
  45. pub struct SignedSourceLinter<'a> {
  46. config: (/* ... */),
  47. out: Box<dyn Output + 'a>,
  48. }
  49.  
  50. impl Linter for SignedSourceLinter<'_> {
  51. fn check_paths<'a>(&mut self, paths: impl Iterator<Item = &'a LintPath>) {
  52. for path in paths {
  53. // TODO
  54. self.out.write(LintMessage);
  55. }
  56. }
  57. }
  58.  
  59. fn main() {}
RAW Paste Data