pub struct KeyBuilder {
    pub actions: Vec<Action>,
    pub description: Option<String>,
    pub name: Option<String>,
    pub uid: Option<String>,
    pub expires_at: Option<OffsetDateTime>,
    pub indexes: Vec<String>,
}
Expand description

The KeyBuilder is an analog to the Key type but without all the fields managed by Meilisearch. It’s used to create Key.

Example

let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
let description = "My little lovely test key".to_string();
let key = KeyBuilder::new()
  .with_description(&description)
  .execute(&client).await.unwrap();

Fields

actions: Vec<Action>description: Option<String>name: Option<String>uid: Option<String>expires_at: Option<OffsetDateTime>indexes: Vec<String>

Implementations

Create a KeyBuilder.

Example
let builder = KeyBuilder::new();

Declare a set of actions the Key will be able to execute.

Example
let mut builder = KeyBuilder::new();
builder.with_actions(vec![Action::Search, Action::DocumentsAdd]);

Add one action the Key will be able to execute.

Example
let mut builder = KeyBuilder::new();
builder.with_action(Action::DocumentsAdd);

Set the expiration date of the Key.

Example
use time::{OffsetDateTime, Duration};
let mut builder = KeyBuilder::new();
// create a key that expires in two weeks from now
builder.with_expires_at(OffsetDateTime::now_utc() + Duration::WEEK * 2);

Set the indexes the Key can manage.

Example
let mut key = KeyBuilder::new()
  .with_indexes(vec!["test", "movies"])
  .execute(&client)
  .await
  .unwrap();

assert_eq!(vec!["test", "movies"], key.indexes);

Add one index the Key can manage.

Example
let mut builder = KeyBuilder::new();
builder.with_index("test");

Add a description to the key.

Example
 let description = "My not so little lovely test key".to_string();

 let mut key = KeyBuilder::new()
  .with_description(&description)
  .execute(&client).await.unwrap();

Add a name to the key.

Example
 let name = "lovely key".to_string();

 let mut key = KeyBuilder::new()
  .with_name(&name)
  .execute(&client).await.unwrap();

Add an uid to the key.

Example
 let uid = "93bcd7fb-2196-4fd9-acb7-3fca8a96e78f".to_string();

 let mut key = KeyBuilder::new()
  .with_uid(&uid)
  .execute(&client).await.unwrap();
  

Create a Key from the builder.

Example
let client = Client::new(MEILISEARCH_HOST, MEILISEARCH_API_KEY);
let description = "My little lovely test key".to_string();
let key = KeyBuilder::new()
   .with_description(&description)
  .execute(&client).await.unwrap();

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more