Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(dead_code, unused_variables)]
- use serde::Serialize;
- use std::io::Write;
- #[derive(Debug, Serialize)]
- pub struct LintMessage;
- pub struct LintPath;
- pub trait Linter {
- fn check_paths<'a>(&mut self, paths: impl Iterator<Item = &'a LintPath>);
- }
- pub trait Output {
- fn write(&mut self, msg: LintMessage);
- }
- impl<T: ?Sized + Output> Output for &'_ mut T {
- fn write(&mut self, msg: LintMessage) {
- (**self).write(msg);
- }
- }
- // Useful for tests.
- impl Output for Vec<LintMessage> {
- fn write(&mut self, msg: LintMessage) {
- self.push(msg);
- }
- }
- struct PrintToStdout;
- impl Output for PrintToStdout {
- fn write(&mut self, msg: LintMessage) {
- println!("{:?}", msg);
- }
- }
- // Stream JSON.
- impl<W: Write> Output for serde_json::Serializer<W> {
- fn write(&mut self, msg: LintMessage) {
- let _ = msg.serialize(self);
- }
- }
- pub struct SignedSourceLinter<'a> {
- config: (/* ... */),
- out: Box<dyn Output + 'a>,
- }
- impl Linter for SignedSourceLinter<'_> {
- fn check_paths<'a>(&mut self, paths: impl Iterator<Item = &'a LintPath>) {
- for path in paths {
- // TODO
- self.out.write(LintMessage);
- }
- }
- }
- fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement