From 853e22e63e032d54547aed3106617734d7a6c6d5 Mon Sep 17 00:00:00 2001 From: Asger Hautop Drewsen Date: Wed, 25 Jun 2025 14:13:51 +0200 Subject: [PATCH 1/2] Implement FromStr for Uuid --- src/uuid.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/uuid.rs b/src/uuid.rs index 70560361..1b56cdc5 100644 --- a/src/uuid.rs +++ b/src/uuid.rs @@ -135,13 +135,15 @@ #[cfg(test)] mod test; -use std::fmt::{self, Display}; +use std::{ + fmt::{self, Display}, + str::FromStr, +}; use crate::{ error::{Error, Result}, spec::BinarySubtype, - Binary, - Bson, + Binary, Bson, }; /// Special type name used in the [`Uuid`] serialization implementation to indicate a BSON @@ -210,6 +212,14 @@ impl Default for Uuid { } } +impl FromStr for Uuid { + type Err = Error; + + fn from_str(s: &str) -> std::result::Result { + Self::parse_str(s) + } +} + #[cfg(feature = "uuid-1")] #[cfg_attr(docsrs, doc(cfg(feature = "uuid-1")))] impl Uuid { From 79ab8b3dfe5de810c70c8091de721f223e175031 Mon Sep 17 00:00:00 2001 From: Asger Hautop Drewsen Date: Wed, 25 Jun 2025 17:03:07 +0200 Subject: [PATCH 2/2] Run rustfmt Co-authored-by: Abraham Egnor --- src/uuid.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uuid.rs b/src/uuid.rs index 1b56cdc5..c747fffb 100644 --- a/src/uuid.rs +++ b/src/uuid.rs @@ -143,7 +143,8 @@ use std::{ use crate::{ error::{Error, Result}, spec::BinarySubtype, - Binary, Bson, + Binary, + Bson, }; /// Special type name used in the [`Uuid`] serialization implementation to indicate a BSON