Skip to main content

TaskBuilder

Struct TaskBuilder 

Source
pub struct TaskBuilder { /* private fields */ }
Expand description

A task being built; TaskBuilder::build writes the fields in this order, which is the crate’s (a reader takes the fields as a map): task_id, model_type, model_id, task_name, model_name, source, v, reply_to when set, then the extra fields in the order they were added.

use legit_streams::Task;

let task = Task::builder("app", "post", "42")
    .task_id("app_01J0000000000000000000000A")
    .model_name("example-model")
    .field("embed_role", "query")
    .field("text_data", "Where is it?")
    .build()?;

let names: Vec<&str> = task.fields().iter().map(|(name, _)| name.as_str()).collect();
assert_eq!(
    names,
    ["task_id", "model_type", "model_id", "task_name", "model_name", "source", "v", "embed_role", "text_data"]
);

Implementations§

Source§

impl TaskBuilder

Source

pub fn task_id(self, task_id: impl Into<String>) -> Self

Use this task id rather than generating one. An empty id is ignored, and one is generated. An id set here is the caller’s to make unguessable: a fast-lane task’s id must carry at least 64 random bits, as the generated {app}_{ULID} does.

use legit_streams::Task;

let task = Task::builder("app", "post", "42").task_id("app_1").build()?;
assert_eq!(task.task_id(), "app_1");
Source

pub fn task_name(self, task_name: impl Into<String>) -> Self

Set the label for logs; default when unset.

use legit_streams::Task;

let task = Task::builder("app", "post", "42").task_name("embed").build()?;
assert_eq!(task.task_name(), "embed");
Source

pub fn model_name(self, model_name: impl Into<String>) -> Self

Ask for a model; empty, the default, means the worker’s default.

use legit_streams::Task;

let task = Task::builder("app", "post", "42").model_name("example-model").build()?;
assert_eq!(task.model_name(), "example-model");
Source

pub fn reply_to(self, reply_to: impl Into<String>) -> Self

Name the stream the result should go to, such as reply_to("app", "hash"). Without it the envelope has no reply_to field. An empty name is ignored.

use legit_streams::Task;

let task = Task::builder("app", "post", "42").reply_to("").build()?;
assert_eq!(task.reply_to(), None);
Source

pub fn field(self, name: impl Into<String>, value: impl Into<String>) -> Self

Add a field of the caller’s: the payload, such as text_data, or an optional setting, such as embed_role. Fields keep the order they’re added in.

use legit_streams::Task;

let task = Task::builder("app", "post", "42").field("embed_role", "query").build()?;
assert_eq!(task.get("embed_role"), Some("query"));
Source

pub fn build(self) -> Result<Task>

Build the task.

§Errors
use legit_streams::{Error, Task};

let built = Task::builder("app", "post", "42").field("task_id", "other").build();
assert_eq!(built, Err(Error::ReservedField("task_id".into())));
let built = Task::builder("app", "post", "42").field("_trace", "x").build();
assert_eq!(built, Err(Error::ReservedField("_trace".into())));
let built = Task::builder("App", "post", "42").build();
assert!(matches!(built, Err(Error::InvalidValue { .. })));

Trait Implementations§

Source§

impl Clone for TaskBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TaskBuilder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for TaskBuilder

§

impl Freeze for TaskBuilder

§

impl Move for TaskBuilder

§

impl RefUnwindSafe for TaskBuilder

§

impl Send for TaskBuilder
where RawVecInner: Send,

§

impl Sync for TaskBuilder
where RawVecInner: Sync,

§

impl Unpin for TaskBuilder
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for TaskBuilder

§

impl UnwindSafe for TaskBuilder
where RawVecInner: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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