uuid.rs


Overview

The [uuid.rs](/projects/287/67764) file provides an internal representation and serialization implementation for UUID (Universally Unique Identifier) objects, specifically tailored for integration with Python UUID objects via the `pyo3` FFI layer. The primary functionality centers around safely extracting a 128-bit UUID value from a Python UUID object, formatting it into its canonical hyphenated string representation, and serializing it using Serde.

This file acts as a bridge between Python UUID objects and Rust serialization infrastructure, enabling efficient and correct conversion and serialization of UUIDs in a Rust environment that interoperates with Python.


Detailed Documentation

Struct: UUID

#[repr(transparent)]
pub(crate) struct UUID {
    ptr: *mut pyo3_ffi::PyObject,
}

Implementation: UUID

new

pub fn new(ptr: *mut pyo3_ffi::PyObject) -> Self

write_buf

pub fn write_buf<B>(&self, buf: &mut B) 
where
    B: bytes::BufMut,

Trait Implementation: Serialize for UUID

impl Serialize for UUID {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
}

Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class UUID {
        -ptr: *mut PyObject
        +new(ptr: *mut PyObject) UUID
        +write_buf<B: BufMut>(&mut buf: B)
        +serialize<S: Serializer>(serializer: S) -> Result
    }
    UUID ..> pyo3_ffi::PyObject : uses (raw pointer)
    UUID ..> serde::Serialize : implements
    UUID ..> bytes::BufMut : writes to
    UUID ..> uuid::Uuid : converts u128 to UUID string

Summary

The [uuid.rs](/projects/287/67764) file encapsulates the representation of a Python UUID object within Rust and provides efficient serialization by:

This file is a critical component in any Rust-Python interop system that requires handling Python UUIDs in serialized Rust data structures.


**End of Documentation**