CosmosEntity

Trait CosmosEntity 

Source
pub trait CosmosEntity {
    type Entity: Serialize;

    // Required method
    fn partition_key(&self) -> Self::Entity;
}
Expand description

Re-export CosmosEntity which must be implemented by every model. CosmosDB partition key. Every CosmosDB entity must implement it.

If you want to treat a Rust type as a document to be added to a Cosmos collection, you just need to implement this trait for your type. This specifies what you use as a partitioning key. You can read more about how partitioning works in Cosmos here.

§Example

struct MySampleStruct {
    id: String,
    string: String,
    number: u64,
}

impl azure_data_cosmos::CosmosEntity for MySampleStruct {
    type Entity = u64;

    fn partition_key(&self) -> Self::Entity {
        self.number
    }
}

Required Associated Types§

Source

type Entity: Serialize

Returned type.

Required Methods§

Source

fn partition_key(&self) -> Self::Entity

Return partition key value as reference.

Implementations on Foreign Types§

Source§

impl CosmosEntity for Value

Source§

impl CosmosEntity for Box<ErasedCosmosEntityWrapper>

Implement CosmosEntity for a Boxed version.

Source§

fn partition_key(&self) -> Self::Entity

Return partition key value as reference.

Source§

type Entity = String

Implementors§