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_URL, 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§

source§

impl KeyBuilder

source

pub fn new() -> KeyBuilder

Create a KeyBuilder.

Example
let builder = KeyBuilder::new();
source

pub fn with_actions(
&mut self,
actions: impl IntoIterator<Item = Action>
) -> &mut Self

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]);
source

pub fn with_action(&mut self, action: Action) -> &mut Self

Add one action the Key will be able to execute.

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

pub fn with_expires_at(&mut self, expires_at: OffsetDateTime) -> &mut Self

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);
source

pub fn with_indexes(
&mut self,
indexes: impl IntoIterator<Item = impl AsRef<str>>
) -> &mut Self

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);
source

pub fn with_index(&mut self, index: impl AsRef<str>) -> &mut Self

Add one index the Key can manage.

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

pub fn with_description(&mut self, desc: impl AsRef<str>) -> &mut Self

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();
source

pub fn with_name(&mut self, desc: impl AsRef<str>) -> &mut Self

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();
source

pub fn with_uid(&mut self, desc: impl AsRef<str>) -> &mut Self

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();
  
source

pub async fn execute(&self, client: &Client) -> Result<Key, Error>

Create a Key from the builder.

Example
let client = Client::new(MEILISEARCH_URL, 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§

source§

impl AsRef<KeyBuilder> for KeyBuilder

source§

fn as_ref(&self) -> &KeyBuilder

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

impl Debug for KeyBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for KeyBuilder

source§

fn default() -> KeyBuilder

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

impl Serialize for KeyBuilder

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where
__S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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