-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #73767 - P1n3appl3:rustdoc-formats, r=tmandry
Refactor librustdoc html backend This PR moves several types out of the librustdoc::html module so that they can be used by a future json backend. These changes are a re-implementation of [some work done 6 months ago](master...GuillaumeGomez:multiple-output-formats) by @GuillaumeGomez. I'm currently working on said json backend and will put up an RFC soon with the proposed implementation. There are a couple of changes that are more substantial than relocating structs to a different module: 1. The `Cache` is no longer part of the `html::render::Context` type and therefor it needs to be explicitly passed to any functions that access it. 2. The driving function `html::render::run` has been rewritten to use the `FormatRenderer` trait which should allow different backends to re-use the driving code. r? @GuillaumeGomez cc @tmandry @betamos
- Loading branch information
Showing
15 changed files
with
1,203 additions
and
1,072 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::error; | ||
use std::fmt::{self, Formatter}; | ||
use std::path::{Path, PathBuf}; | ||
|
||
use crate::docfs::PathError; | ||
|
||
#[derive(Debug)] | ||
pub struct Error { | ||
pub file: PathBuf, | ||
pub error: String, | ||
} | ||
|
||
impl error::Error for Error {} | ||
|
||
impl std::fmt::Display for Error { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
let file = self.file.display().to_string(); | ||
if file.is_empty() { | ||
write!(f, "{}", self.error) | ||
} else { | ||
write!(f, "\"{}\": {}", self.file.display(), self.error) | ||
} | ||
} | ||
} | ||
|
||
impl PathError for Error { | ||
fn new<S, P: AsRef<Path>>(e: S, path: P) -> Error | ||
where | ||
S: ToString + Sized, | ||
{ | ||
Error { file: path.as_ref().to_path_buf(), error: e.to_string() } | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! try_none { | ||
($e:expr, $file:expr) => {{ | ||
use std::io; | ||
match $e { | ||
Some(e) => e, | ||
None => { | ||
return Err(Error::new(io::Error::new(io::ErrorKind::Other, "not found"), $file)); | ||
} | ||
} | ||
}}; | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! try_err { | ||
($e:expr, $file:expr) => {{ | ||
match $e { | ||
Ok(e) => e, | ||
Err(e) => return Err(Error::new(e, $file)), | ||
} | ||
}}; | ||
} |
Oops, something went wrong.