|
@@ -20,6 +20,18 @@ pub enum IntegerType {
|
|
usize,
|
|
usize,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/// For `Walker::visit_std_type`, the std type encountered.
|
|
|
|
+#[cfg(feature = "std")]
|
|
|
|
+#[non_exhaustive]
|
|
|
|
+#[derive(Debug)]
|
|
|
|
+pub enum StdType {
|
|
|
|
+ Cell,
|
|
|
|
+ RefCell,
|
|
|
|
+ Rc,
|
|
|
|
+ Arc,
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
/// User-facing type.
|
|
/// User-facing type.
|
|
///
|
|
///
|
|
/// In the non-leaf functions (those that take a `Walkable` generic), if recursion
|
|
/// In the non-leaf functions (those that take a `Walkable` generic), if recursion
|
|
@@ -29,9 +41,16 @@ pub trait Walker {
|
|
fn visit_integer(&mut self, itype: IntegerType);
|
|
fn visit_integer(&mut self, itype: IntegerType);
|
|
fn visit_str(&mut self);
|
|
fn visit_str(&mut self);
|
|
|
|
|
|
|
|
+ fn visit_ref<W: Walkable>(&mut self);
|
|
fn visit_option<W: Walkable>(&mut self);
|
|
fn visit_option<W: Walkable>(&mut self);
|
|
fn visit_tuple<W: Walkable>(&mut self);
|
|
fn visit_tuple<W: Walkable>(&mut self);
|
|
fn visit_array<W: Walkable>(&mut self, length: usize);
|
|
fn visit_array<W: Walkable>(&mut self, length: usize);
|
|
|
|
+ fn visit_slice<W: Walkable>(&mut self);
|
|
|
|
+
|
|
|
|
+ #[cfg(feature = "std")]
|
|
|
|
+ fn visit_vec<W: Walkable>(&mut self);
|
|
|
|
+ #[cfg(feature = "std")]
|
|
|
|
+ fn visit_std_type<W: Walkable>(&mut self, std: StdType);
|
|
|
|
|
|
fn visit_struct<W: Walkable>(&mut self, struct_name: &'static str);
|
|
fn visit_struct<W: Walkable>(&mut self, struct_name: &'static str);
|
|
fn visit_field<W: Walkable>(&mut self, field_name: &'static str);
|
|
fn visit_field<W: Walkable>(&mut self, field_name: &'static str);
|
|
@@ -50,7 +69,7 @@ pub use sw::StringWalker;
|
|
|
|
|
|
#[cfg(feature = "std")]
|
|
#[cfg(feature = "std")]
|
|
mod sw {
|
|
mod sw {
|
|
- use crate::{IntegerType, Walkable, Walker};
|
|
|
|
|
|
+ use crate::{IntegerType, Walkable, Walker, StdType};
|
|
|
|
|
|
pub struct StringWalker {
|
|
pub struct StringWalker {
|
|
buffer: String,
|
|
buffer: String,
|
|
@@ -83,8 +102,16 @@ mod sw {
|
|
self.buffer += " str";
|
|
self.buffer += " str";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ fn visit_ref<W: Walkable>(&mut self) {
|
|
|
|
+ self.buffer += " (ref";
|
|
|
|
+ W::walk_with(self);
|
|
|
|
+ self.buffer += ")";
|
|
|
|
+ }
|
|
|
|
+
|
|
fn visit_option<W: Walkable>(&mut self) {
|
|
fn visit_option<W: Walkable>(&mut self) {
|
|
self.buffer += " (option";
|
|
self.buffer += " (option";
|
|
|
|
+ W::walk_with(self);
|
|
|
|
+ self.buffer += ")";
|
|
}
|
|
}
|
|
|
|
|
|
fn visit_tuple<W: Walkable>(&mut self) {
|
|
fn visit_tuple<W: Walkable>(&mut self) {
|
|
@@ -94,7 +121,25 @@ mod sw {
|
|
}
|
|
}
|
|
|
|
|
|
fn visit_array<W: Walkable>(&mut self, length: usize) {
|
|
fn visit_array<W: Walkable>(&mut self, length: usize) {
|
|
- self.buffer += format!(" (array:{} ", length).as_str();
|
|
|
|
|
|
+ self.buffer += format!(" (array:{}", length).as_str();
|
|
|
|
+ W::walk_with(self);
|
|
|
|
+ self.buffer += ")";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn visit_slice<W: Walkable>(&mut self) {
|
|
|
|
+ self.buffer += format!(" (slice").as_str();
|
|
|
|
+ W::walk_with(self);
|
|
|
|
+ self.buffer += ")";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn visit_vec<W: Walkable>(&mut self) {
|
|
|
|
+ self.buffer += format!(" (vec").as_str();
|
|
|
|
+ W::walk_with(self);
|
|
|
|
+ self.buffer += ")";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fn visit_std_type<W: Walkable>(&mut self, std: StdType) {
|
|
|
|
+ self.buffer += format!(" (std:{:?}", std).as_str();
|
|
W::walk_with(self);
|
|
W::walk_with(self);
|
|
self.buffer += ")";
|
|
self.buffer += ")";
|
|
}
|
|
}
|