Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod ser;

pub use crate::de::{deserialize, Deserializer};
pub use crate::error::{Error, Result};
pub use crate::ser::{serialize, Serialize, Serializer};
pub use crate::ser::{convert_ser_error, serialize, Serialize, Serializer};

// Not public API.
#[doc(hidden)]
Expand Down
19 changes: 19 additions & 0 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ mod erase {
_ => unreachable!(),
}
}

/// Takes the stored result of the erased serializer after serializing.
pub fn result(self) -> Result<S::Ok, S::Error> {
match self {
Serializer::Complete(ok) => Ok(ok),
Serializer::Error(err) => Err(err),
_ => panic!("Tried to take result of serializer before serializing or finished serializing an object.")
}
}
}
}

Expand Down Expand Up @@ -688,6 +697,16 @@ where
}
}

/// Converts the result from a Serializer::erase_xxx function into a public-api result.
pub fn convert_ser_error(err: ErrorImpl) -> crate::Error {
match err {
ErrorImpl::ShortCircuit => {
serde::ser::Error::custom("Call `serializer::result()` to find out the error.")
}
ErrorImpl::Custom(msg) => serde::ser::Error::custom(msg),
}
}

serialize_trait_object!(Serialize);

struct MakeSerializer<TraitObject>(TraitObject);
Expand Down