You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new API is based on two new traits, DeserializeCql and DeserializeRow:
pubtraitDeserializeCql<'frame>whereSelf:Sized,{/// Checks whether this type can be deserialized from given CQL type.fntype_check(typ:&ColumnType) -> Result<(),ParseError>;/// Deserialize from given bytes./// The function may assume that `type_check` was called and it succeeded.fndeserialize(typ:&'frame ColumnType,v:Option<FrameSlice<'frame>>,) -> Result<Self,ParseError>;}
pubtraitDeserializeRow<'frame>whereSelf:Sized,{/// Checks whether this type can be deserialized from given row.fntype_check(specs:&[ColumnSpec]) -> Result<(),ParseError>;/// Deserialize from given bytes./// The function may assume that `type_check` was called and it succeeded.fndeserialize(row:ColumnIterator<'frame>) -> Result<Self,ParseError>;}
Instead of receiving pre-parsed data, both traits receive objects that borrow data from the serialized frame - hence the 'frame lifetime parameter. This allows the types being deserialized to allocate only when they need to (e.g. in case of String). However, the new API also allows types that borrow data from the serialized frame - for example &[u8] or &str. There is also a third option - the type being deserialized can also share ownership of the serialized frame - for example, you can deserialize blob to a bytes::Bytes, which will keep the original, serialized frame alive while it is alive. This is easier to use than slices or strs, but one needs to be careful as even a tiny blob will keep the memory for the whole serialized frame alive, which can lead to space leaks.
Another notable changes is the type_check method. In case of DeserializeRow it receives more comprehensive information than FromRow, which include column names, and now maching column names to fields is possible. The derive for DeserializeRow has that functionality. Moreover, because type checking is separate from deserialize, it can be done only once when a response is received - if the page with response has 1000 rows then we only need to call type_check once per page but deserialize once per row. deserialize can assume that type_check has been called and it can avoid some potentially expensive type checks.
The content you are editing has changed. Please copy your edits and refresh the page.
Sub-task of #462.
The new API
The new API is based on two new traits,
DeserializeCql
andDeserializeRow
:Instead of receiving pre-parsed data, both traits receive objects that borrow data from the serialized frame - hence the
'frame
lifetime parameter. This allows the types being deserialized to allocate only when they need to (e.g. in case ofString
). However, the new API also allows types that borrow data from the serialized frame - for example&[u8]
or&str
. There is also a third option - the type being deserialized can also share ownership of the serialized frame - for example, you can deserializeblob
to abytes::Bytes
, which will keep the original, serialized frame alive while it is alive. This is easier to use than slices orstr
s, but one needs to be careful as even a tiny blob will keep the memory for the whole serialized frame alive, which can lead to space leaks.Another notable changes is the
type_check
method. In case ofDeserializeRow
it receives more comprehensive information thanFromRow
, which include column names, and now maching column names to fields is possible. The derive forDeserializeRow
has that functionality. Moreover, because type checking is separate fromdeserialize
, it can be done only once when a response is received - if the page with response has 1000 rows then we only need to calltype_check
once per page butdeserialize
once per row.deserialize
can assume thattype_check
has been called and it can avoid some potentially expensive type checks.Tasks
DeserializeRow
andDeserializeCql
for current implementors ofFromRow
andFromCql
#963Deserialize{Row,Value}
in internal APIs #1025DeserializeRow
andDeserializeCql
in the public API #964The text was updated successfully, but these errors were encountered: