Skip to content

Commit

Permalink
Break serializers into common and platform-specific
Browse files Browse the repository at this point in the history
  • Loading branch information
marti4d committed Jan 8, 2025
1 parent e661a78 commit d764aa7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 37 deletions.
1 change: 1 addition & 0 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod minidump_writer;
pub mod module_reader;
pub mod ptrace_dumper;
pub(crate) mod sections;
mod serializers;
pub mod thread_info;

pub use maps_reader::LINUX_GATE_LIBRARY_NAME;
Expand Down
2 changes: 1 addition & 1 deletion src/linux/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
super::ptrace_dumper::InitError,
super::{ptrace_dumper::InitError, serializers::*},
crate::{
dir_section::FileWriterError, maps_reader::MappingInfo, mem_writer::MemoryWriterError,
serializers::*, Pid,
Expand Down
1 change: 1 addition & 0 deletions src/linux/ptrace_dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
super::{
auxv::AuxvError,
errors::{AndroidError, MapsReaderError},
serializers::*,
},
crate::{
linux::{
Expand Down
40 changes: 40 additions & 0 deletions src/linux/serializers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Functions used by Serde to serialize types that we don't own (and thus can't implement
//! [Serialize] for)
use {crate::serializers::*, serde::Serializer};

/// Serialize [goblin::error::Error]
pub fn serialize_goblin_error<S: Serializer>(
error: &goblin::error::Error,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [nix::Error]
pub fn serialize_nix_error<S: Serializer>(
error: &nix::Error,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [procfs_core::ProcError]
pub fn serialize_proc_error<S: Serializer>(
error: &procfs_core::ProcError,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [std::string::FromUtf8Error]
pub fn serialize_from_utf8_error<S: Serializer>(
error: &std::string::FromUtf8Error,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [std::time::SystemTimeError]
pub fn serialize_system_time_error<S: Serializer>(
error: &std::time::SystemTimeError,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
37 changes: 1 addition & 36 deletions src/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use serde::Serializer;
/// Useful for types that implement [Error][std::error::Error] and don't need any special
/// treatment.
fn serialize_generic_error<S: Serializer, E: std::error::Error>(
pub fn serialize_generic_error<S: Serializer, E: std::error::Error>(
error: &E,
serializer: S,
) -> Result<S::Ok, S::Error> {
Expand All @@ -21,41 +21,6 @@ pub fn serialize_io_error<S: Serializer>(
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [goblin::error::Error]
pub fn serialize_goblin_error<S: Serializer>(
error: &goblin::error::Error,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [nix::Error]
pub fn serialize_nix_error<S: Serializer>(
error: &nix::Error,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [procfs_core::ProcError]
pub fn serialize_proc_error<S: Serializer>(
error: &procfs_core::ProcError,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [std::string::FromUtf8Error]
pub fn serialize_from_utf8_error<S: Serializer>(
error: &std::string::FromUtf8Error,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [std::time::SystemTimeError]
pub fn serialize_system_time_error<S: Serializer>(
error: &std::time::SystemTimeError,
serializer: S,
) -> Result<S::Ok, S::Error> {
serialize_generic_error(error, serializer)
}
/// Serialize [scroll::Error]
pub fn serialize_scroll_error<S: Serializer>(
error: &scroll::Error,
Expand Down

0 comments on commit d764aa7

Please sign in to comment.