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 description = "My little lovely test key".to_string();
let key = KeyBuilder::new()
    .with_description(&description)
    .execute(&client).await.unwrap();

assert_eq!(key.description, Some(description));

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 KeyBuilder

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 KeyBuilder

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 KeyBuilder

Set the expiration date of the Key.

§Example
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 KeyBuilder

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 KeyBuilder

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 KeyBuilder

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

assert_eq!(key.description, Some(description));
source

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

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

assert_eq!(key.name, Some(name));
source

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

Add a 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();

assert_eq!(key.uid, uid);
source

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

Create a Key from the builder.

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

assert_eq!(key.description, Some(description));

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 Clone for KeyBuilder

source§

fn clone(&self) -> KeyBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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 T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

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 T
where U: From<T>,

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
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