Clean up serialization code nits
This commit is contained in:
parent
86b9550811
commit
a68ac32de5
@ -132,13 +132,16 @@ pub(crate) struct RenderType {
|
|||||||
|
|
||||||
impl RenderType {
|
impl RenderType {
|
||||||
pub fn write_to_string(&self, string: &mut String) {
|
pub fn write_to_string(&self, string: &mut String) {
|
||||||
if self.generics.is_some() || self.bindings.is_some() {
|
fn write_optional_id(id: Option<RenderTypeId>, string: &mut String) {
|
||||||
string.push('{');
|
|
||||||
// 0 is a sentinel, everything else is one-indexed
|
// 0 is a sentinel, everything else is one-indexed
|
||||||
match self.id {
|
match id {
|
||||||
Some(id) => id.write_to_string(string),
|
Some(id) => id.write_to_string(string),
|
||||||
None => string.push('`'),
|
None => string.push('`'),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if self.generics.is_some() || self.bindings.is_some() {
|
||||||
|
string.push('{');
|
||||||
|
write_optional_id(self.id, string);
|
||||||
string.push('{');
|
string.push('{');
|
||||||
for generic in &self.generics.as_ref().map(Vec::as_slice).unwrap_or_default()[..] {
|
for generic in &self.generics.as_ref().map(Vec::as_slice).unwrap_or_default()[..] {
|
||||||
generic.write_to_string(string);
|
generic.write_to_string(string);
|
||||||
@ -153,18 +156,13 @@ impl RenderType {
|
|||||||
for constraint in &binding.1[..] {
|
for constraint in &binding.1[..] {
|
||||||
constraint.write_to_string(string);
|
constraint.write_to_string(string);
|
||||||
}
|
}
|
||||||
string.push('}');
|
string.push_str("}}");
|
||||||
string.push('}');
|
|
||||||
}
|
}
|
||||||
string.push('}');
|
string.push('}');
|
||||||
}
|
}
|
||||||
string.push('}');
|
string.push('}');
|
||||||
} else {
|
} else {
|
||||||
// 0 is a sentinel, everything else is one-indexed
|
write_optional_id(self.id, string);
|
||||||
match self.id {
|
|
||||||
Some(id) => id.write_to_string(string),
|
|
||||||
None => string.push('`'),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,6 +189,7 @@ impl RenderTypeId {
|
|||||||
// zig-zag notation
|
// zig-zag notation
|
||||||
let value: u32 = (id << 1) | (if sign { 1 } else { 0 });
|
let value: u32 = (id << 1) | (if sign { 1 } else { 0 });
|
||||||
// encode
|
// encode
|
||||||
|
// Documented in https://rust-lang.github.io/rustc-dev-guide/rustdoc-internals/search.html
|
||||||
let mut shift: u32 = 28;
|
let mut shift: u32 = 28;
|
||||||
let mut mask: u32 = 0xF0_00_00_00;
|
let mut mask: u32 = 0xF0_00_00_00;
|
||||||
while shift < 32 {
|
while shift < 32 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user