use mongodb::bson::oid::ObjectId;
use mongodb::error;
pub(crate) fn parse_object_id(id: &str) -> Result<ObjectId, mongodb::error::Error> {
ObjectId::parse_str(id).map_err(|e| mongodb::error::Error::custom(e))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_object_id_valid() {
let result = parse_object_id("507f1f77bcf86cd799439011");
assert!(result.is_ok());
}
#[test]
fn test_parse_object_id_invalid() {
let result = parse_object_id("invalid");
assert!(result.is_err());
}
}
pub fn parse_object_ids(ids: &[String]) -> error::Result<Vec<ObjectId>> {
ids.iter()
.map(|id| ObjectId::parse_str(id).map_err(|e| mongodb::error::Error::custom(e)))
.collect()
}