Skip to content

Commit 5b8f6af

Browse files
committed
explain lifetime params of Deserialize{Value,Row}
1 parent 33924cc commit 5b8f6af

File tree

1 file changed

+42
-0
lines changed
  • scylla-cql/src/types/deserialize

1 file changed

+42
-0
lines changed

scylla-cql/src/types/deserialize/mod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,48 @@
1010
//! Those traits are quite similar to each other, both in the idea behind them
1111
//! and the interface that they expose.
1212
//!
13+
//! It's important to understand what is a _deserialized type_. It's not just
14+
//! an implementor of Deserialize{Value, Row}; there are some implementors of
15+
//! `Deserialize{Value, Row}` who are not yet final types, but **partially**
16+
//! deserialized types that support further deserialization - _type
17+
//! deserializers_, such as `ListlikeIterator`, `UdtIterator` or `ColumnIterator`.
18+
//!
19+
//! # Lifetime parameters
20+
//!
21+
//! - `'frame` is the lifetime of the frame. Any deserialized type that is going to borrow
22+
//! from the frame must have its lifetime bound by `'frame`.
23+
//! - `'metadata` is the lifetime of the result metadata. As result metadata is only needed
24+
//! for the very deserialization process and the **final** deserialized types (i.e. those
25+
//! that are not going to deserialize anything else, opposite of e.g. `MapIterator`) can
26+
//! later live independently of the metadata, this is different from `'frame`.
27+
//!
28+
//! _Type deserializers_, as they still need to deserialize some type, are naturally bound
29+
//! by 'metadata lifetime. However, final types are completely deserialized, so they should
30+
//! not be bound by 'metadata - only by 'frame.
31+
//!
32+
//! Rationale:
33+
//! `DeserializeValue` requires two types of data in order to perform
34+
//! deserialization:
35+
//! 1) a reference to the CQL frame (a FrameSlice),
36+
//! 2) the type of the column being deserialized, being part of the
37+
//! ResultMetadata.
38+
//!
39+
//! Similarly, `DeserializeRow` requires two types of data in order to
40+
//! perform deserialization:
41+
//! 1) a reference to the CQL frame (a FrameSlice),
42+
//! 2) a slice of specifications of all columns in the row, being part of
43+
//! the ResultMetadata.
44+
//!
45+
//! When deserializing owned types, both the frame and the metadata can have
46+
//! any lifetime and it's not important. When deserializing borrowed types,
47+
//! however, they borrow from the frame, so their lifetime must necessarily
48+
//! be bound by the lifetime of the frame. Metadata is only needed for the
49+
//! deserialization, so its lifetime does not abstractly bound the
50+
//! deserialized value. Not to unnecessarily shorten the deserialized
51+
//! values' lifetime to the metadata's lifetime (due to unification of
52+
//! metadata's and frame's lifetime in value deserializers), a separate
53+
//! lifetime parameter is introduced for result metadata: `'metadata`.
54+
//!
1355
//! # `type_check` and `deserialize`
1456
//!
1557
//! The deserialization process is divided into two parts: type checking and

0 commit comments

Comments
 (0)