Implement Default Trait for RecordId
What component does this affect?
SurrealDB Rust SDK
Is this improvement related to a problem?
Currently you have to define the id field of a struct which represents a document table like so:
#[serde(skip_serializing)]
id: Option<RecordId>,So that you can use the same struct for Serialization and Deserialization by using None if you're creating a struct.
This results in any code which relies on the id field needing to except/unwrap/match the Option.
Suggest a solution
Instead I would like to suggest implementing the Default trait for the RecordId type. I'm sure there is code to check whether a id was specified or not - here we could add another if statement to check whether it's the default value and if yes, generate the ID like when the ID isn't provided.
Alternative methods
Adding one struct to create a record (without fields which have defaults / are generated by SurrealDB) and one which is used for records which has all fields.
SurrealDB version
surrealdb 2.3.8 crate
Contact Details
No response
Is there an existing issue for this?
- I have searched the existing issues
Code of Conduct
- I agree to follow this project's Code of Conduct
Source: surrealdb/surrealdb