Skip to content

Commit

Permalink
Merge branch 'master' into binary-heap-ta
Browse files Browse the repository at this point in the history
  • Loading branch information
yanchith committed Jun 9, 2023
2 parents e450f70 + a43616f commit 3ac8c69
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@
//! fn node_id(&'a self, n: &Nd) -> dot::Id<'a> {
//! dot::Id::new(format!("N{}", n)).unwrap()
//! }
//! fn node_label<'b>(&'b self, n: &Nd) -> dot::LabelText<'b> {
//! fn node_label(&self, n: &Nd) -> dot::LabelText<'_> {
//! dot::LabelText::LabelStr(self.nodes[*n].into())
//! }
//! fn edge_label<'b>(&'b self, _: &Ed) -> dot::LabelText<'b> {
//! fn edge_label(&self, _: &Ed<'_>) -> dot::LabelText<'_> {
//! dot::LabelText::LabelStr("&sube;".into())
//! }
//! }
Expand All @@ -177,8 +177,8 @@
//! type Edge = Ed<'a>;
//! fn nodes(&self) -> dot::Nodes<'a,Nd> { (0..self.nodes.len()).collect() }
//! fn edges(&'a self) -> dot::Edges<'a,Ed<'a>> { self.edges.iter().collect() }
//! fn source(&self, e: &Ed) -> Nd { let & &(s,_) = e; s }
//! fn target(&self, e: &Ed) -> Nd { let & &(_,t) = e; t }
//! fn source(&self, e: &Ed<'_>) -> Nd { let & &(s,_) = e; s }
//! fn target(&self, e: &Ed<'_>) -> Nd { let & &(_,t) = e; t }
//! }
//!
//! # pub fn main() { render_to(&mut Vec::new()) }
Expand Down Expand Up @@ -226,11 +226,11 @@
//! fn node_id(&'a self, n: &Nd<'a>) -> dot::Id<'a> {
//! dot::Id::new(format!("N{}", n.0)).unwrap()
//! }
//! fn node_label<'b>(&'b self, n: &Nd<'b>) -> dot::LabelText<'b> {
//! fn node_label(&self, n: &Nd<'_>) -> dot::LabelText<'_> {
//! let &(i, _) = n;
//! dot::LabelText::LabelStr(self.nodes[i].into())
//! }
//! fn edge_label<'b>(&'b self, _: &Ed<'b>) -> dot::LabelText<'b> {
//! fn edge_label(&self, _: &Ed<'_>) -> dot::LabelText<'_> {
//! dot::LabelText::LabelStr("&sube;".into())
//! }
//! }
Expand Down Expand Up @@ -273,6 +273,8 @@
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
test(attr(allow(unused_variables), deny(warnings)))
)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

use LabelText::*;

Expand Down Expand Up @@ -408,7 +410,7 @@ impl<'a> Id<'a> {
}

pub fn as_slice(&'a self) -> &'a str {
&*self.name
&self.name
}
}

Expand Down Expand Up @@ -469,7 +471,11 @@ pub trait Labeller<'a> {
/// Escape tags in such a way that it is suitable for inclusion in a
/// Graphviz HTML label.
pub fn escape_html(s: &str) -> String {
s.replace('&', "&amp;").replace('\"', "&quot;").replace('<', "&lt;").replace('>', "&gt;")
s.replace('&', "&amp;")
.replace('\"', "&quot;")
.replace('<', "&lt;")
.replace('>', "&gt;")
.replace('\n', "<br align=\"left\"/>")
}

impl<'a> LabelText<'a> {
Expand Down Expand Up @@ -509,8 +515,8 @@ impl<'a> LabelText<'a> {
pub fn to_dot_string(&self) -> String {
match *self {
LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
HtmlStr(ref s) => format!("<{}>", s),
EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(s)),
HtmlStr(ref s) => format!("<{s}>"),
}
}

Expand All @@ -523,7 +529,7 @@ impl<'a> LabelText<'a> {
EscStr(s) => s,
LabelStr(s) => {
if s.contains('\\') {
(&*s).escape_default().to_string().into()
s.escape_default().to_string().into()
} else {
s
}
Expand Down Expand Up @@ -616,7 +622,7 @@ where
if let Some(fontname) = options.iter().find_map(|option| {
if let RenderOption::Fontname(fontname) = option { Some(fontname) } else { None }
}) {
font = format!(r#"fontname="{}""#, fontname);
font = format!(r#"fontname="{fontname}""#);
graph_attrs.push(&font[..]);
content_attrs.push(&font[..]);
}
Expand All @@ -629,8 +635,8 @@ where
if !(graph_attrs.is_empty() && content_attrs.is_empty()) {
writeln!(w, r#" graph[{}];"#, graph_attrs.join(" "))?;
let content_attrs_str = content_attrs.join(" ");
writeln!(w, r#" node[{}];"#, content_attrs_str)?;
writeln!(w, r#" edge[{}];"#, content_attrs_str)?;
writeln!(w, r#" node[{content_attrs_str}];"#)?;
writeln!(w, r#" edge[{content_attrs_str}];"#)?;
}

let mut text = Vec::new();
Expand All @@ -643,7 +649,7 @@ where
write!(text, "{}", id.as_slice()).unwrap();

if !options.contains(&RenderOption::NoNodeLabels) {
write!(text, "[label={}]", escaped).unwrap();
write!(text, "[label={escaped}]").unwrap();
}

let style = g.node_style(n);
Expand Down Expand Up @@ -672,7 +678,7 @@ where
write!(text, "{} -> {}", source_id.as_slice(), target_id.as_slice()).unwrap();

if !options.contains(&RenderOption::NoEdgeLabels) {
write!(text, "[label={}]", escaped_label).unwrap();
write!(text, "[label={escaped_label}]").unwrap();
}

let style = g.edge_style(e);
Expand Down

0 comments on commit 3ac8c69

Please sign in to comment.